Create New Admin Account in WordPress via FTP

Another handy little snippet for WordPress …

Have you ever had a client need help on their WordPress site, and have FTP access, but not actually give you a WordPress account to use? Just paste this snippet into their current theme’s functions.php file, or add it to a new file in their ~/wp-content/mu-plugins/ folder, and WordPress will automatically create an admin account for you to use!

Oh — and don’t forget to change the credentials that are included to your own. If there is already an account with the username or email address specified, it will fail and not do diddly squat.

function add_admin_acct(){
	$login = 'myacct1';
	$passw = 'mypass1';
	$email = '';

	if ( !username_exists( $login )  && !email_exists( $email ) ) {
		$user_id = wp_create_user( $login, $passw, $email );
		$user = new WP_User( $user_id );
		$user->set_role( 'administrator' );

Remember … with great power comes great responsibility. Don’t abuse it.

19 Replies to “Create New Admin Account in WordPress via FTP”

  1. Wow. I have needed this so many times.

    Thanks for passing it on.

    How about a post on the reverse. Seems I saw something once about if you have an admin WP account but no FTP, that there is a plugin to essentially fake FTP. That possible?

    1. Just change the values assigned to $login, $passw, and $email. And you should be able to paste it into the end of your functions.php file — or just into a new file and upload it to your wp-content/mu-plugins directory (create the directory if it doesn’t exist)

  2. So many thanks, you saved my life, my wife’s account was blocked as she forgot her password and the “forgot password” was not working. Thanks to you, I am now able to access the admin page, and realize she indicate in the recovery email address!

  3. I created /mu-plugins/ directory as it didn’t exist and then created functions.php file containing the code with changed $login, $passw & $email but account is not recognised and the contents of the functions.php file is displayed as text along the top of the site?

      1. I’m a complete noob so probably not! I managed to change passwords in Cpanel following this video tutorial in the end:

  4. Thanks, but unfortunately doesn’t work for me. I added the at the end. I called the file make.php and put it here: http://domain.tld/wp-content/mu-plugins/make.php. I surfed to it and it came back with Fatal error: Call to undefined function add_action() in ….domain.tld/wp-content/mu-plugins/make.php on line 13. that is the line with add_action(‘init’,’add_admin_acct’);.
    Could it be that in newer WP versions this doesn’t work any longer?
    Als tried the video that was posted by Iain, That does let me beond the loginpage, but the says I have insufficient rights to view the next page.

Comments are closed.