Create user from the WordPress backend.

, ,

In case of forgotten password this snippet can be used to create new user from WordPress backend. Insert code to functions.php of the used theme.

function custom_create_admin_user() {
    $username = 'user';
    $password = 'password';
    $email    = 'user@example.com';

    if ( ! username_exists( $username ) && ! email_exists( $email ) ) {
        $user_id = wp_create_user( $username, $password, $email );

        if ( ! is_wp_error( $user_id ) ) {
            $user = get_user_by( 'id', $user_id );
            $user->remove_role( 'subscriber' ); // New users default to 'subscriber'
            $user->add_role( 'administrator' ); // Set the new user role to 'administrator'
        }
    }
}
add_action( 'init', 'custom_create_admin_user' );

But be careful to choose strong password and correct email.

You are doing it on your own risk and responsibility.