It is disappointing to have your WordPress admin locked up. That is why we have shown you how to add an admin user to WordPress through MySQL. Recently one of our readers asked if it is possible to add an admin user to WordPress using FTP. of course it is. In this article, we will show you how to add an admin user to WordPress using FTP

Why you might need to add an admin user to WordPress using FTP?
Sometimes you can forget your username or email address on a WordPress site and cannot enter the admin area.

One way to do this is to add an admin user to the WordPress database using MySQL. But you may be unable to connect to phpMyAdmin or do not want to run MySQL queries directly.
Some users may hack their site and delete the account. In that case, adding an admin user using FTP can quickly restore your access to the WordPress admin area. Having said this, let’s take a look at how you can easily add an admin user to WordPress using FTP.


Adding an admin user to WordPress using FTP

The first thing you need is an FTP client. If you are new to using FTP, see our guide on using FTP to upload files to WordPress. Once connected to your WordPress site, you need to find out the functions of your WordPress theme. File. It would be in a place like this:

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


Add the following code to your active theme function.php file

<?php
function dev_pt_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','dev_pt_admin_account');


Don’t forget to change the username, password and email@domain.com with their own values.

Next, save the file and then upload it back to your website using the FTP client.

You can now go to the login area of ​​your WordPress site and sign in with the user account you have added.

Once you are logged into your WordPress site, please edit the functions.php file and remove the code you have added. Deleting the code will not delete the user you added, and you can always add new users and authors to your WordPress site.

Categorized in: