Add Admin User in Functions

If you’ve forgotten what email and password you used to setup a website (or entered your email wrong, or your website isn’t sending reset password links to you!), you can setup an admin user via FTP using the following function.

Add to functions.php

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

Remember to update Username, Password and Emails from the defaults shown above!

Source. #22 in the list.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.