Being locked of your WordPress admin is frustrating. That’s why we have shown you how to add an admin user in WordPress via MySQL. In this article, we will show you how to add a WordPress Admin User using 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 of WordPress Admin User for any user role. It can be done in a matter of seconds and a newly created user can immediately log in with given username and password.

Why You May Need to Add a WordPress Admin User Using FTP?

Sometimes you may forget your username or email address on a WordPress site and cannot login to the admin area.

One way to do this is by adding an admin user to the WordPress database using MySQL. But you may be unable to connect to phpMyAdmin or don’t want to run MySQL queries directly.

Some users may get their site hacked and admin account deleted. In that case, adding an admin user using FTP can quickly restore your access to the WordPress admin area.

Adding a WordPress Admin User Using FTP

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

Here is a little snippet which can create a WordPress backend account with ease using the FTP.

Once connected to your WordPress site, you need to locate your WordPress theme’s functions.php file. It would be at a location like this:

/example.com/wp-content/themes/your-current-theme/functions.php

Right click on

functions.php

file and then select download. Your FTP client will download the

functions.php

file to your computer.

WordPress Admin User

Open the file you just downloaded on your computer using a plain text editor like Notepad. Now you need to add this code at the bottom of the file. Also, make sure the username and the email are unique else the function will fail.

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

Don’t forget to replace Username, Password, and email@domain.com with your own values.

Leave a Reply

Or

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


CAPTCHA Image
Reload Image

Find us on Facebook

Subscribe to our Newsletter