create admin user using sftp
|

Create a WordPress Admin user using SFTP or FTP

Creating a new WordPress user from the admin dashboard is very easy, however sometimes in situations where we are locked out of WordPress we have to manually create a user for ourselves without having access to the Dashboard. One such situation can be that you forgot your password and are not able to receive the Email for Password Reset option.

There are two ways to do this.

  1. Creating use from MySQL Database
  2. Adding PHP function using FTP Access or CPanel File Manager

In this article, I will discuss the second method which is easier and anyone can do this by simply copying and pasting this snippet with a few small modifications.

After opening File manager or connecting to the server through an FTP client (for example FileZilla), you can follow the below steps.

  • Navigate to wp-content/themes/your-theme
  • Open functions.php file
  • Paste below code
/*Add new user */

function lawp_new_user(){
   $user = 'any-name';  //write user name here
   $pass = 'any-password';  //write password that you can remember here
   $email = 'youremail@domain.com';  //replace with your  email

   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','lawp_new_user');

/*code ends */

In the above code, add the username that you want to use, your password, and your email. I have added comments after lines of code so you can easily find which items you can replace.

After adding the above code and saving changes, the user will be created for you and you can login with the details (username/email and password) that you added in the code. Once you are able to login to the site and access the dashboard, you can remove the above code from functions.php. If you will not remove the code then deleting the above user from the user setting in the WordPress dashboard will not work.

I hope this article has helped you to learn how to create a WordPress admin user using SFTP or FTP. If you have any questions, feel free to ask in the comments.

Similar Posts

Leave a Reply

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