Home > Back-end >  how to force all new users to only become a "customer" role in WordPress
how to force all new users to only become a "customer" role in WordPress

Time:04-04

(first of all excuse me for my bad English writing)

in last 2 days my WordPress website have a problem. when every one sign up on my website become an admin !!! I try all possible solutions but not work.

I need a hook to force all new registered users to only have a "customer" role. or immediately auto change there role to customer from admin after signup

I use DIGITS plugin for signup form (OTP plugin)

I use this code but not working:

function my_func1($user_id){
    $wp_user_object = new WP_User($current_user->ID);
    $wp_user_object->set_role('customer');
}
add_action('user_register','my_func1');

CodePudding user response:

go to Dashboard>setting>new user role> set it to customer or Subscriber. If this doesn't help then you can install Ultimate member plugin and force all users to customer roles

CodePudding user response:

add_action( 'user_register', 'myplugin_registration_save', 11, 1 );

function myplugin_registration_save( $user_id ) {
    $current_user = new WP_User($user_id);
    $current_user->remove_role('administrator');
    $current_user->add_role('customer');
}

This should solve your problem

  • Related