Add Admin Account in WordPress Only From FTP


Yesterday, I found myself in a critical situation. One of my client’s WordPress blog was hacked its admin password was changed. He wants to reset it. When I tried to use password reset function, I found that there is no user with username admin and email id was also wrong. Hacker changed the email id and username of the WordPress blog. This was also not a big problem for me. I asked for the cPanel login credentials and thought I will do it direct from PHPMyAdmin. But Client refused to give cpanel details because he was afraid of data leakage.

WordPress password change

In this case, I have only option to use FTP and nothing else. To reset the password, we will use same approach which we used in last post explaining reset WordPress password with FTP.

Navigate to the directory wp-content and then in themes. We will edit functions.php. Open it and put following code at the beginning. Change $user, $pass and $email values according to your account details which you want to add

function admin_account(){
$user = ‘AccountID’;
$pass = ‘AccountPassword’;
$email = ’[email protected]’;
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’ );
} }

Now refresh the blog. It will load functions.php and this code will add the user with specified details and default role will be admin.

Now remove the line and then try login with this new account added.

In case of any difficulties in implementation, you can comment below or contact me.


Tags: |

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.

Similar Articles


Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

2020 UseThisTip | Part of Techlomedia Internet Pvt Ltd Developed By Deepanker