Create Admin User via FTP

When you are locked out of your WordPress site and have no access to PHPMyAdmin, add this to your functions.php file to create a new admin user account.

Remove it from the functions file after you’re successfully logged in. (The user will remain.)

function wpb_admin_account(){
   $user = 'Username';
   $pass = 'Password';
   $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' );
} }

Thanks for the snippet, WPBeginner!

Comments are closed.

Skip to toolbar