3

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

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

The codex page for wp_insert_user() lists all the values that it accepts. comment_shortcuts, and show_admin_bar_front will all need to be set with update_user_meta().

To handle wp_user_level and wp_capabilities you will need to use WP_User.

You can use $new_user_user_id (long var name lol) for both WP_User and update_user_meta()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.