skip to Main Content

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

2

Answers


  1. 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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search