Create new users automatically, Admin, Editor, Author, Contributor, Subscriber

Adding this snippet to the functions.php of your wordpress theme will automatically create a new user. Super Admin, Administrator, Editor, Author, Contributor, Subscriber

    function fb_wp_insert_user() {
    $user_data = array(
    'ID' => '',
    'user_pass' => wp_generate_password(),
    'user_login' => 'dummy',
    'user_nicename' => 'Dummy',
    'user_url' => '',
    'user_email' => 'dummy@example.com',
    'display_name' => 'Dummy',
    'nickname' => 'dummy',
    'first_name' => 'Dummy',
    'user_registered' => '2010-05-15 05:55:55',
    'role' => get_option('default_role') // Use default role or another role, e.g. 'editor'
    $user_id = wp_insert_user( $user_data );
    add_action( 'admin_init', 'fb_wp_insert_user' );

Comments  Leave a Reply

  1. Should it not look up to first find if username already exists?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!