Viewing 7 replies - 1 through 7 (of 7 total)
  • Hey Shubham,

    Did you find your answer?
    Please let me know the solution if you have.

    Ah! Found the solution!

    Action: wsl_hook_process_login_after_wp_insert_user
    Filter: wsl_hook_process_login_alter_redirect_to

    add_action('wsl_hook_process_login_after_wp_insert_user', 'wsl_hook_process_login_after_wp_insert_user_callback', 10, 3);
    function wsl_hook_process_login_after_wp_insert_user_callback($user_id, $provider, $hybridauth_user_profile) {
    	if(//logic) {
    		$u = new WP_User( $user_id );
    		// Remove role
    		$u->remove_role( 'subscriber' );
    		// Add role
    		$u->add_role( 'contributor' );
    	}
    }

    To redirect user to different pages use –

    add_filter( 'wsl_hook_process_login_alter_redirect_to', 'wsl_hook_process_login_alter_redirect_to_callback' );
    function wsl_hook_process_login_alter_redirect_to_callback($redirect_to) {
    	return $redirect_to;
    }

    Note – Filter is calling before changing role using above action

    Thread Starter shubham jain

    (@engshubham2013)

    Thanks Amit for your answer, but this is not my proper answer. Actually my problem was like this one – https://www.ads-software.com/support/topic/two-user-default-role and I have found the solution for that.

    Let me describe my problem, Here we have one option user can choose any one from followin user.

    As Normal – subscriber
    As Professional – Contributor
    After select any option then it will go to next section of form where he can fill the form manually or register by social network.

    Thanks,

    Great! Cheers!

    Thread Starter shubham jain

    (@engshubham2013)

    Please read once more my post, i just updated it. If you need solution please let me know.

    Hi,
    i’m modified this snippet to set a buddypress member type during the registration using wordpress social login and it works if i use a default string.
    But what i can’t do is to get a parameter from the url using php GET method, here is my code:

    add_action('wsl_hook_process_login_after_wp_insert_user', 'wsl_hook_process_login_after_wp_insert_user_callback', 10, 3);
    function wsl_hook_process_login_after_wp_insert_user_callback($user_id, $provider, $hybridauth_user_profile) {
    
        $u = new WP_User( $user_id );
    
        if (isset($_GET['mtype'])) {
          // this doesnt work for now, cant get the "GET" parameter
            $member_type =  $_GET['mtype'];
        }
        else {
          // this works for now
          $member_type =  'my-default-member-type'; // default value
        }
    
        bp_set_member_type( $user_id, $member_type );
    
    }

    any idea what i can do to catch the get parameter ? here is the corresponding url i was able to generate during the registration process, after the user has manage to connect is Facebook account and his account was successfully created:

    https://www.time2sail.com/wp-login.php?action=wordpress_social_authenticated&provider=Facebook&mode=login&mtype=my-selected-member-type

    Thanks for your help!

    Hi,

    I’m having the same issue with two default user roles. What is the solution you’ve found?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change user role at register time.’ is closed to new replies.