'how to force all new users to only become a "customer" role in WordPress

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


Solution 1:[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

Solution 2:[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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yash
Solution 2 Waqas Rahman