Creating a user via ftp is a very cool and helpful trick!

When might you need to add a user via ftp?

Sometimes you may forget your username or password, and/or you may not have access to the admin email on the account to reset a password. You will, however,  need to have ftp access for this to work.

Put the code below in the functions file of the active theme. Once you have saved the functions file, go to login to your site, and you will be able to login with the parameters you provided!

Once you have successfully established logged in to the dashboard, go to the users and create a user pofile for your self there. Then remember to go back to your functions.php file and delete the code you added. Deleting the code will not remove the user you added, and you can always add new users and authors to your WordPress site.

 

[code language="php"]
 function wpb_admin_account(){
 $user = 'your-chosen-username';
 $pass = 'your-chosen-password';
 $email = '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','wpb_admin_account');
 [/code]