How to Add a User in WordPress Using FTP

Wordpress User Registration

Sometimes, there will be instances that get you locked out of your own WordPress admin area. This can be stressful and frustrating. There may be any number of reasons for this like the hack attacks, theme or plugin malfunctions, or even forgetting your username, email address or password for that matter.

Regardless, there are backdoor methods on how you can enter your site and create a new Admin User manually in the case of such emergency. One such method is connecting via the phpMyAdmin section and running MySQL queries to create the admin user. However, if you don’t want to meddle with the database or if you are unable to do so for some apparent reason, the other alternate method would be to add the new admin user via FTP.

Add Admin User in WordPress via FTP

Creating a new Admin user via FTP is really easy than you think. The first thing you need to do it to connect to your WordPress site via your FTP client.

Also read: how to update WordPress via FTP

After connecting to your FTP account, proceed to locate your WordPress theme’s “functions.php” file. The general location of the file would be /wp-content/themes/theme-name/functions.php.

Using the FTP client, download the functions.php onto your computer.

Theme functions file - Open WordPress theme functions file

Now open the file using a plain text editor, like the Notepad and add the following code snippet at the bottom of the file. Don’t forget to replace the Username, Password and name@example.com fields with the actual values. Also, the username and email address should be unique, i.e. there shouldn’t be a user already registered with the same username or email address.

//Add a new user using FTP
function bs_admin_account()
{
    $user = 'Username';
    $pass = 'Password';
    $email = 'name@example.com';
    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', 'bs_admin_account');

Now that you’ve done that, go back to your FTP client and upload the file to your website’s FTP account.

That’s all there is to do. You’ve created a new admin user using FTP. You can now log into your WordPress admin area using the credentials that you provided above.

Wordpress login page - Log into WordPress dashboard

Once logged in, make sure to remove the added code from the functions.php file. Don’t worry even when you remove the code, the user account will stay intact. You can always keep adding users and authors to your site as you need.

If you want to, you can force reset passwords of other accounts by simply navigating to “Users > All Users” and clicking on the “Edit” link under the user account. Once you are done resetting, you can remove the newly created account by clicking on the “Delete” link.

WordPress users - Edit WordPress Users

If you like this quick tip then you might also like to hide admin bar for all users except for administrators. Do check it out.

Hope that helps and do comment below sharing your thoughts and experiences about using FTP to create a new admin user in WordPress.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.