Create New User via php

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

When might you need to add a user via ftp?

While this is not the most common way to access a wordpress site, but the need arises.

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 need to have ftp access for this to work.

You will put this code in the functions file of the active theme.Once you have saved the functions file, go to login to your site, coool, you will be able to login with the parameters you provided.

Once you have successfully established contact, 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.

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' );
} }