Add a WordPress Admin User to the Database via PHP

As a developer, you will occasionally need to create a new administrative 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.

Sure, 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’s wp-content/ directory.
  • Create a new file in the wp-content/mu-plugins/ directory you created and name it anything you want. Something like create-admin-user.php would work nicely.
  • Copy this code snippet and paste it into the file you just created:
  • 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.