How to create a new user account via FTP

Creating new user accounts in WordPress is very easy. As an admin, you need to navigate to Users admin page where you can create a new account for any user role. That can be done in a matter of seconds and a newly created user can immediately log in with given username and password.

But what happens if you lose access to your WordPress admin? Things might get a bit more complicated, but don’t worry – we have a function for you which can save your admin life.

Whether another admin deleted your account, whether you have deleted all users from the database by mistake, used a malfunctioning plugin or got hacked, you can still get back in control. Sometimes you might be able to get access only to your FTP server while the HTTP one will be out of your reach and you will need to create a new admin. While that might be a rare case, the following function will save you.

To create a new account outside WordPress admin environment, all you will need is an FTP access to your site. As an admin, you should have all the needed information to login to your server and you can quickly create a new account by creating a new function in your theme.

Create a new user account via FTP:

  1. Open FTP client and connect to your account
  2. Navigate to wp-content/themes
  3. Open the folder of the theme you are using
  4. Search for functions.php file and edit it
  5. Copy and paste the following function:
  6. function admin_account(){
    $user = 'Username';
    $pass = 'Password';
    $email = 'email@domain.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','admin_account');
    
  7. Change username, password and email to something unique
  8. Save changes

Make sure that username, password and email address which you set in the function are unique or otherwise the function won’t work properly. Once you have saved the changes, you’re done and you can navigate to your WP login panel. Use new information to log back in and once you have verified the account, you can delete the function from functions.php file.

The function shown above creates an admin account but you can easily modify it to create an account with any other user role. Simply change the role on the 8th row of the code to editor, author, contributor or subscriber or any other user role you have created.

Unfortunately, if you have lost your admin account, you have also lost all the posts written under that username. That’s why you should always keep a backup which you can easily retrieve. If you’re reading this while having your admin account, take this as a reminder to create a backup immediately and bookmark this article just in case you need to create an account outside WordPress in the future.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

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