Creating administrator user in WordPress with only FTP details (Updated)

I seem to have recently gained a number of clients who were very keen for work to be completed due to bad communication with their previous developers. This usually meant that anything they’d ask for wouldn’t be received for some time. This raises a dilemma in that these clients almost always don’t have all the login info you need.

Today I wanted to grab a backup of a site and all I had was the sites FTP and the clients WP login with insufficient privileges to manage plugins. Easy enough to solve with the little snippet below.

<?php
    require('wp-load.php' );
 
    $username = "my_admin";
    $password = "StrangePassword123!";
    $email = "email@example.com";
 
 	// create user and return new user id
 	$id = wp_create_user($username, $password, $email);
 	// check create for WordPress error
    if(!is_wp_error($id)) {
    	// update users role to admin - this can't be done on the create
        wp_update_user( array ('ID' => $id, 'role' => 'administrator'));
        print 'User successfully created';
    }
    else {
    	// print WordPress error
    	print $id->get_error_message();
    }
?>

Just fill in your user, pass and email and you’ll be set. You’ll also have to changed the path to wp-load.php depending on where you place this script. Also as a good safety measure don’t forget to delete it when you’re done.

Created myself and user and backed up using BackupBuddy. Easy.

Updated: I updated the code to give more useful error messages.

-Morgan