How to create new WordPress admin user account via FTP or cPanel?

Today I’m going to show you how to create a new WordPress admin user account via FTP or cPanel. Now you would probalby want to ask “Why would I need to do that?”

Well, two possible reasons:

  1. You have forgotten either your username or password (or both)
  2. You have forgotten your username or password and password recovery is not working. The main reason for that is that your site is not using SMTP and therefore all recovery emails are also lost, and they are not delivered.

Hence, the solution to add a new admin account user via FTP or cPanel.

How to add a new WordPress admin account via FTP?

It is really easy and will take you probably a couple of minutes.

Option 1: add new user by creating a new file

  1. Log in to your FTP
  2. Create a new file in your computer (or server) and name it adduser.php
  3. Paste this code here below inside the file
  4. Change the username, password and email inside the file
  5. Save the file
  6. Go to your site and add /adduser-php to the URL. For example https://yoursite.com/adduser.php
  7. If everything is configured correctly then you’ll see the “Successfully created new admin user. Now delete this file” notification
  8. Now go back to the FTP and delete the adduser.php file
  9. Log in to your site by using these new credentials

Here is the code for the adduser.php file

<?php
// ADD NEW ADMIN USER TO WORDPRESS
// ----------------------------------
// Put this file in your WordPress root directory and run it from your browser.
// Delete it when you're done.

require_once('wp-blog-header.php');
require_once('wp-includes/registration.php');

// ----------------------------------------------------
// CONFIG VARIABLES
// Make sure that you set these before running the file.
$newusername = 'username'; // here goes your username
$newpassword = 'password'; // here goes your password
$newemail = 'email@email.com'; // here goes your email
// ----------------------------------------------------

// This is just a security precaution, to make sure the above "Config Variables"
// have been changed from their default values.
if ( $newpassword != 'YOURPASSWORD' &&
	 $newemail != 'YOUREMAIL@TEST.com' &&
	 $newusername !='YOURUSERNAME' )
{
	// Check that user doesn't already exist
	if ( !username_exists($newusername) && !email_exists($newemail) )
	{
		// Create user and set role to administrator
		$user_id = wp_create_user( $newusername, $newpassword, $newemail);
		if ( is_int($user_id) )
		{
			$wp_user_object = new WP_User($user_id);
			$wp_user_object->set_role('administrator');
			echo 'Successfully created new admin user. Now delete this file!';
		}
		else {
			echo 'Error with wp_insert_user. No users were created.';
		}
	}
	else {
		echo 'This user or email already exists. Nothing was done.';
	}
}
else {
	echo 'Whoops, looks like you did not set a password, username, or email';
	echo 'before running the script. Set these variables and try again.';
}

Option 2: add new user by modifying a functions.php file

  1. Log in to your FTP
  2. Go to the wp-content >> themes >> your theme and open functions.php.file
  3. Paste this code shown below inside the functions-php file
  4. Change the username, password and email inside the file
  5. Save the file
  6. Go to your site and log in with the new credentials
  7. Now go back to the FTP and delete the code inside the functions.php file
// Add admin user. Don’t forget to delete this file
function add_admin_account(){
$user = 'anotheruser'; // here goes your username
$pass = 'anotherpassword'; // here goes your password
$email = 'email1@email.com'; // here goes your 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' );
} }
add_action('init','add_admin_account');

How to add a new WordPress admin account via cPanel?

If you don’t know how to use the FTP but you have a cPanel based webhosting then:

  1. Log in to your cPanel and open up File manager
  2. Go to the public_html folder and decide whether you use the first or second option shown above

Option 1: add new user by creating a new file

  1. If you are going to use the first option and want to create a file then fint the File button on the toolbar, click on in and give the file a name (adduser.php for example).
  2. Next click on the Create new file button.
  3. Now select the newly created file and click find the Edit button on the toolbar. Click on it.
  4. Popup opens and now click once more on the Edit button
  5. Paste the code shown above inside this file
  6. Change username, password and email and save changes
  7. Go to your site and add /adduser-php to the URL. For example https://yoursite.com/adduser.php
  8. If everything is configured correctly then you’ll see the “Successfully created new admin user. Now delete this file” notification
  9. Now go back to the File manager and delete the adduser.php file
  10. Log in to your site by using these new credentials

Option 2: add new user by modifying a functions.php file

Everything works in a way like with the previous option. You just have to:

  1. Go to the wp-content >> themes >> your theme and open functions.php.file
  2. Paste this code shown above inside the functions-php file
  3. Change the username, password and email inside the file
  4. Save the file
  5. Go to your site and log in with the new credentials
  6. Now go back to the File manager and delete the code inside the functions.php file

Video: How to create new WordPress admin user account via FTP or cPanel?

Useful Wordpres tips and tricks

Here are some of my favorite WordPress tools

Thanks for reading this article! I hope it's been useful as you work on your own websites and e-commerce sites. I wanted to share some tools I use as a WordPress developer, and I think you'll find them helpful too.

Just so you know, these are affiliate links. If you decide to use any of them, I'll earn a commission. This helps me create tutorials and YouTube videos. But honestly, I genuinely use and recommend these tools to my friends and family as well. Your support keeps me creating content that benefits everyone.

Themes: Over the past few years, I've consistently relied on two primary themes for all sorts of projects: the Blocksy theme and the Kadence Theme. If you explore this website and my YouTube channel, you'll come across numerous tutorials that delve into these themes. If you're interested in obtaining a 10% discount for both of these themes, then:

Code Snippets Manager: WPCodeBox allows you to add code snippets to your site. Not only that, but it also provides you with the capability to construct and oversee your WordPress Code Snippets library right in the cloud. You can grab it with the 20% discount here (SAVE 20% Coupon: WPSH20).

Contact forms: There are hundreds of contact forms out there but Fluent Forms is the one I like the most. If you need a 20% discount then use this link (save 20% coupon is WPSH20).

Gutenberg add-ons: If I need a good Gutenberg blocks add-on then Kadence Blocks is the one I have used the most. You’ll get a 10% discount with the coupon SIMPLEHACKS here.

Website migration: While building a website you probably need a good plugin that can help you with the migration, backups, restoration, and staging sites. Well, WpVivid is the one I have used for the last couple of years. If you use this link along with the WPSH20 coupon you’ll get a 20% discount.

Woocommerce extensions: There are a bunch of Woocommerce extensions that I like but the one that stands out is Advanced Dynamic Pricing. Once again, you’ll get a 20% discount if you use this link here (save 20% coupon is WPSH20)

Web Hosting: If you would like to have a really fast and easy-to-use managed cloud hosting, then I recommend Verpex Hosting (see my review here). By the way, this site is hosted in Verpex.)

To see all my most up-to-date recommendations, check out this resource that I made for you!

Do you want to thank me and buy me a beer?

Every donation is entirely welcome but NEVER required. Enjoy my work for free but if you would like to thank me and buy me a beer or two then you can use this form here below.

Donation Form (#2)

Janek T.
Janek T.

Improve this text: {CLIPBOARD}

- I have been passionate about Wordpress since 2011, creating websites and sharing valuable tips on using Wordpress and Woocommerce on my site.
- Be the first to receive notifications about new tutorials by subscribing to my Youtube channel .
- Follow me on Twitter here

Articles: 116