Insert “New User” and update/set meta data at once

The wordpress function wp_insert_user doesn’t seem to set (overwrite) the input I give. (documentation shows you can’t)
Trying to use: wp_insert_user using the returned userID also doesn’t work.

Of course I could just make my own query but maybe I’m forgetting an option to insert this data using a existing function.

$userdata = array(
    //user login
    'user_pass'  => esc_attr( $_POST['pass'] ),
    'user_login' => esc_attr( $_POST['user'] ),
    'user_email' => esc_attr( $_POST['email'] ),

    //user meta
    'rich_editing' => false,
    'comment_shortcuts' => false,
    'show_admin_bar_front' => false,        
    'wp_user_level' => 0, 
    'wp_capabilities' => 'a:1:{s:10:"subscriber";s:1:"1";}' 
);

     $new_user_user_id = wp_insert_user( $userdata );   

2 Answers
2

What you are best off doing is hooking into user_register and from there updating the user options you want them set to. Below is an example of disabling the admin bar for new users:

add_action("user_register", "sc_set_user_admin_bar_false_by_default", 10, 1);
function sc_set_user_admin_bar_false_by_default($user_id) {
    update_user_meta( $user_id, 'show_admin_bar_front', 'false' );
    update_user_meta( $user_id, 'show_admin_bar_admin', 'false' );
}

Leave a Comment