True story: a client has sent me their FTP login information, but no WordPress login information. What do you do in this case, especially if it’s after hours, or the client has forgotten their WordPress login information and can’t access the email address associated with it? Simple: you create a new user via FTP!
To add a new user to a WordPress installation via FTP, add the following to the blog’s active theme’s functions.php file, save the file, refresh the blog, then go to the login page and login:
function admin_account(){
$user = ‘NEW_ADMIN_USERNAME_HERE’;
$pass = ‘NEW_ADMIN_PASSWORD_HERE’;
$email = ‘email@domain.com’;
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’,'admin_account’);
This handy snippet of code has saved my ass more than once.



