How can we add an Admin user in WordPress if we do not have access to Dashboard or SQL

There are situations in which we need to "take over" a blog / website on WordPress, but we do not have a lot of authentication data for it.
In the scenario where we do not have one User with admin rights To know his password, We do not have an email address On which we can recover a user admin and no access to the database (a cPanel account), it seems a little impossible to be able to log in to WordPress. There is, however, a "gate." FTP access To the site's files, can allow us to interact with its database and take control.

If we have FTP access to a WordPress blog, Recovering the password of a user with administrator rights or Adding a new user, Can be done in two ways.

1. Accessing the blog / website database through phpMyAdmin, using login data from the wp-config.php.

If we do not have access through a cPanel or other management system to phpMyAdmin, We can Download archive of here is Extract da archive and we're going to FTP, Next to WordPress files and folders.
Access phpMyAdmin from the browser: and connect with The database user and the password. We find them in wp-config.php.
Once you enter phpMyAdmin, the blog database, we go to the table "wp_users”Where we can easily change the email address (user_email). We put an email address that we have access to, then from WordPress we reset the password.

2. Adding a WordPress user with administrator privileges using the current.the topic's functions.php file.

A simpler and faster method than the first one, but besides the existing user / users who have administrative rights, one more will be added. Of course, once logged in with this user, You can change the data of others. Your email address and password.

To apply this method, first of all Identify what the current theme is On which the blog is running. On the first page, access the source (View Source) and search “/wp-content / themes/ ... ". The folder after “/ themes / ..” is the current theme folder.
Access the current theme FTP folder (/ wp-content / themes / username /) and edit the file functions.php Present here.

In functions.php, at the bottom we add the following code:
function wpb_admin_account(){
$user = 'Username';
$pass = 'Password';
$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' );
} }

Only the dates indicated in red will be changed. $ user, $ pass si $ email.

Save changes to the functions.php file, then:, Where you will be logged in with the data you entered above.

This way you can log in to WordPress with a new user with an administrator rank. After login, it is highly recommended to delete this code from functions.php.

How can we add an Admin user in WordPress if we do not have access to Dashboard or SQL

About the author


Passionate about everything gadget and IT, I write with pleasure on since 2006 and I like to discover with you new things about computers and operating systems macOS, Linux, Windows, iOS and Android.

Leave a Comment