Skip to:
Content
Pages
Categories
Search
Top
Bottom

Buddypress – when user activates account,user role changes to default


  • Pravin Makvana
    Participant

    @ashvin03

    I am working with buddypress, I have a two user roles, 1-student 2-faculty and i have set default user role as subscriber. when user registers and activates account by clicking on link sent through mail.User role changes to default(subscriber).

    Any idea what is the issue? Below is the code assigning role to user on sign up.

    add_action('bp_core_signup_user', 'ad_user_signup_usermeta', 10, 5);
    function ad_user_signup_usermeta($user_id, $user_login, $user_password, $user_email, $usermeta) {
    
            if(isset($_POST['signup_membership']) && !empty($_POST['signup_membership']))
            update_user_meta($user_id, 'membership', $_POST['signup_membership']);
    
            $userdata = array();
            $userdata['ID'] = $user_id;
            if(!empty($_POST['signup_usertype'])) {
                if($_POST['signup_usertype'] == 'student') {
                $userdata['role'] = 'student';  
                }
                if($_POST['signup_usertype'] == 'instructor') {
                $userdata['role'] = 'instructor';   
                }   
            }
    
            if ($userdata['role']){
                wp_update_user($userdata);
            }
    
    }
Viewing 4 replies - 1 through 4 (of 4 total)

  • Henry Wright
    Moderator

    @henrywright

    Hi @ashvin03

    Nowhere in your function do you tell BuddyPress to change the user’s role to subscriber, therefore the problem must be coming from elsewhere. Try disabling all plugins and activating the Twenty Fifteen theme to see if the issues resolves.


    Pravin Makvana
    Participant

    @ashvin03

    Hi,

    Thank’s for quick reply.this code add the user role but does not work as properly.When user register as fronted side and show the user list as back end side users => all user’s that time user add in particular roll but when active that user that time automatically role change and become as subscriber.

    Please help How can i resolved it?

    thanks.


    shanebp
    Moderator

    @shanebp

    Try storing the role selected when registering in user_meta.
    Then use that data to actually set the role via this hook bp_core_activated_user
    in this file: \buddypress\bp-members\bp-members-functions.php


    Pravin Makvana
    Participant

    @ashvin03

    Thanks @shanebp it’s work grate.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Buddypress – when user activates account,user role changes to default’ is closed to new replies.
Skip to toolbar