Create a new admin account in WordPress via FTP

If your WordPress admin account get locked then you can try to restore admin account access by using the “Lost your password?” link on the admin login page or you can try to reset your password by directly updating it in database.

There is one more way if you have FTP access to your WordPress installation folder. Guess How? By creating a new admin account.

To create a new admin account, place the following lines in your current theme’s functions.php file or create a single file plugin with the following code:


function create_admin_account(){
$login = 'myusername';
$passwd = 'mypassword';
$email = 'myemail @ mydomain.com';

if ( !username_exists( $login ) && !email_exists( $email ) ) {
$userId = wp_create_user( $login, $passwd, $email );
$user = new WP_User( $userId );
$user->set_role( 'administrator' );
}
}

add_action('init','create_admin_account');

After adding the above code browse any page on your WordPress website, it will create the admin account with the provided login credentials.

NOTE: Delete the above code from you theme’s functions.php file or plugin as it imposes a security risk once you can access administrator account.

Leave a Comment

Back to top