Skip to main content
< All Topics

Adding a WordPress User via PHP

When inheriting a WordPress site where you have file system access but no WordPress credentials, you can use PHP to create a new administrator account directly. This is typically done via FTP, SFTP, or a file manager in your hosting control panel.

Before you begin

  • You will need access to the site’s file system via FTP, SFTP, or a hosting control panel file manager
  • Identify the active theme — you will be editing its functions.php file
  • Have the site URL handy so you can load it after making the edit

Steps

  1. Open the functions.php file of the active theme
  2. Add the following code, updating the username, password, and email address before saving

  1. Load the site in a browser. The code will execute in the background and create the new account.
  2. Log in to WordPress using the credentials you specified
  3. Open functions.php again and remove the code you added. This is important — leaving it in place means it will attempt to run on every page load.

A few things to note

  • Use a username that is not on the list of usernames to avoid — even for a temporary account
  • Use a strong password. Once you are in WordPress you can reset it or delete the account entirely.
  • If Wordfence or another security plugin is installed, you may receive a notification that a user was created outside of the normal WordPress process. This is expected and can be dismissed.
  • Once you have access, create a proper administrator account through the WordPress dashboard and delete this temporary one.

Related articles

Need help taking over or maintaining an existing WordPress site? Glimmernet offers WordPress maintenance and managed hosting services.

Submit a Comment

Your email address will not be published. Required fields are marked *