Home / admin / Create new users automatically, Admin, Editor, Author, Contributor, Subscriber
  • How to Create new users automatically, Admin, Editor, Author, Contributor, Subscriber

    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

    ( click code to copy )

    wordpress snippet : PHP

    <>
        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' );
    

    ( WordPress codex functions, hooks, in this snippet. )

    default_role, register, init, user_register, wp_insert_user, add_action, get_option, _n, _e, wp,
  • Nick

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