As a developer, you will occasionally need to create a new admin user in the database to gain access to the site. Typically, this is necessary when you are provided with an export of a WordPress database, but you aren’t provided with the login credentials for the admin user.
You can gain access via the database. However, many developers aren’t very comfortable with MySQL and the process is pretty slow compared to what I’m about to show you. Here’s all you need to do:
- Create an
mu-plugins/
directory in your site’swp-content/
directory. - Create a new file in the
wp-content/mu-plugins/
directory you created and name it anything you want. Something likecreate-admin-user.php
would work nicely. - Copy this code snippet and paste it into the file you just created:
set_role( 'administrator' ); } } );
- Edit the username, password and email address.
- Login to the site using the information you just edited.
- Once you have logged in, delete the file.
So with these simple steps you can gain access to your wordpress admin by creating a new admin user.