Skip to content [Tab]
~/posts/software/create-user-from-the-wordpress-backend.md
$ stat -x create-user-from-the-wordpress-backend.md POSIX filesystem
Access Mode: -rw-r--r-- (0644)
Author: uid:1000(@f7234bv9s8)
File Size: 1.1 KB (116 words)
Modified:
Flags: --cat="software,web,wordpress"

Create user from the WordPress backend.

attachment://featured-image.webp

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.

@f7234bv9s8 maintainer

Software engineer and writer at notes:own:vision:com.