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 don't have much credentials with 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 bit impossible to log in WordPress. There is, however, a "door." FTP access To the site's files, can allow us to interact with its database and take control.

If we have FTP access to the files of a blog on WordPress, recovering the password of a user with access rights administrator 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: Extract da archive and we're going to FTP, next to files and folders WordPress.
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 user WordPress with rights administrator, using the functions.php file of the current theme.

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 = '';
 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 WordPress with a new user with the rank of administrator. After authentication it is very advisable to delete this code from functions.php.

Passionate about technology, I enjoy writing on since 2006. I have a rich experience in operating systems: macOS, Windows, and Linux, as well as in programming languages and blogging platforms (WordPress) and for online stores (WooCommerce, Magento, PrestaShop).

How to » Linux » MySQL » How can we add an Admin user in WordPress if we do not have access to Dashboard or SQL
Leave a Comment