Technology WordPress

How to Add an Admin User in WordPress using FTP?

adminuserftp
Written by AskYouNow

Lock down of the WordPress admin is so Frustrating. So in this article, I’ll let you know how you can create admin user without cpanel and MYSQL Details

Why Did You May need to Add an Admin User in WordPress Using FTP?

Sometimes it happens when we forgot our admin username, password, and email and in that situation, we’re unable to login to the wordpress dashboard.

so there is one method by SQL query through which you can insert admin user but you wouldn’t want to run complicated SQL query.

Sometimes websites got hacked and admin users deleted by hackers and in this situation, you can add admin users quickly by FTP access to restore admin access.

So let me explain how you can do that with the help of your FTP.

First of all, you need FTP client through which you can connect to your server and once you got connected you need to go to your active theme’s function file whose path should look like this :
/yoursitedomain.com/wp-content/themes/your-active-theme/functions.php
ftp-img
You can download this file by right-clicking on it. Once you have downloaded this file just open it and put the below code in the end of the file
function wpb_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','wpb_admin_account');

After putting the code don’t forget to change the username, password, and email address.

After changing the values save it and upload it to FTP.

Now go back to your website’s admin URL and refresh it and put the username/email and password that you have just changed the file and login.

Once you have logged in then go to your function file and remove the added code from the file.

that’s it for now, Hope you guys like this. We will come up with another blog post soon.

if you have any queries or any questions about this code snippets. Contact us for more information.

About the author

AskYouNow

Leave a Comment

Retype the CAPTCHA code from the image
Change the CAPTCHA codeSpeak the CAPTCHA code