PHP

How to recover WordPress admin access if you only have FTP access

There are well-documented solutions to recover the wordpress admin access if you have MySQL, phpMyAdmin or shell access.

This solution shows you how to create a new admin user if you don’t know the admin username or password and you don’t have any form of MySQL or shell access (only FTP access is required).

Step 1: Identify your currently active theme

This can be done by looking at the source code of your homepage (go to your domain, then Ctrl+U to show the source) and then Ctrl+F-search for wp-content/themes. It will show hits like https://mydomain.de/wp-content/themes/twentyfifteen/style.css. This means the currently active theme is twentyfifteen.

Step 2: Create a new admin user using functions.php

Now open your FTP software (I recommend FileZilla) and find your wp-content folder. Inside wp-content, go to themes and then open the folder of your currently active theme.

If the currently active theme is not listed in your wp-content/themes folder, you might have the wrong wp-content folder. Check if there are any other folders around.

When you have found your theme folder, edit functions.php and, just after the first <?php, add this block of code:

function wpb_admin_account(){
    $user = 'newadmin';
    $pass = 'saiquae9shahZus6eeri3feNae8gie';
    $email = '[email protected]';
    if ( !username_exists( $user )  && !email_exists( $email ) ) {
        $user_id = wp_create_user( $user, $pass, $email );
        $user = new WP_User( $user_id );
        $user->set_role( 'administrator' );
    }
}
add_action('init','wpb_admin_account');

Be sure to replace the username, password and email! I recommend to use a new random password and a non-generic username! The username you enter here must.

Save the file and upload it to the server.

After that, goto your homepage and reload once (this will create the new user).

Then, try to login using your newly created user (go to e.g. https://my-domain.com/wp-admin to do so!). If it doesn’t work, check if you edited the functions.php for the correct theme and try to use a different username!

Step 3: Delete the code we just created

If you just leave in the code, this will create a potential security risk. So I recommend deleting it right away!

Also, be sure to delete any admin users you don’t need afterwards.

 

Posted by Uli Köhler in PHP, Wordpress

Use PHP mail function instead of SMTP in Framadate

Problem:

You want to use framadate as a Doodle alternative, but you don’t have access to SMTP on your server

Solution:

This solution was tested with Framadate 1.0. It might not work with other versions. The best approach is to just try it out.

First, configure the mailer in app/inc/config.php just as you would with SMTP. Most importantly set

'use_smtp' => true

The settings in

'smtp_options' => [
    // [...]
],

do not matter, so you can leave them at their defaults.

Next, edit app/classes/Framadate/Services/MailService.php:

and find this line:

$mailer->isSMTP();

Comment it out:

//$mailer->isSMTP();

This tells PHPMailer, the underlying library, not to use SMTP but to use the PHP mail() function.

Now ensure that you have uploaded all the changed files to the server and test your modifications.

Posted by Uli Köhler in PHP

How to fix phpMyAdmin error #1231 – Variable ‘lc_messages’ can’t be set to the value of

Problem:

After logging in to your phpMyAdmin instance, you get an error message like this:

#1231 - Variable 'lc_messages' can't be set to the value of 'de_DE'

Solution:

This error message is caused by a bad language code – in the example listed above, MySQL does not understand the de_DE language code.

The easiest fix for this is to set phpMyAdmin to a fixed language. In order to do this, add this line to your config in config.inc.php on the server.

$cfg['Lang'] = 'en';

You can add this almost anywhere in the file, but I recommend adding it after the $cfg['blowfish_secret'] line.

In case the error message does not disappear after doing this, ensure there is no other $cfg['Lang'] line in config.inc.php.

Posted by Uli Köhler in PHP