How to change bb press forum roles programmatically?

708 views Asked by At

I have two user role

1)student

2)paid student

I have situation after the payment i am changing role student to paid student it work good but here i have also change the forum role programmatically to participant for paid student here . How do i change forum role programmatically using query, function anything.

Below code i have used to change user roles programmatically it works good but i am stuck d in changing forum role. i am looking something like this.

$user_id = get_current_user_id();
                        $oldrole=implode(', ', $user_id->roles);
                        if($oldrole=="student")
                        {
                        $u = new WP_User($user_id);

                      // Remove role
                       $u->remove_role('student');
                             $newrole="paid_student";
                       // Add role
                        $u->add_role( $newrole );
                        } 
1

There are 1 answers

12
Sanjay Nakate On BEST ANSWER

Finally i have got the answer. Bellow are the step.

1) Get user current user id.

<?php $user_id = get_current_user_id(); ?>

2)set new user forum role you wish to change

<?php $new_role_forum_role="bbp_participant"; ?>

3)fire function.

<?php bbp_set_user_role( $user_id, $new_role_forum_role );?>

now check your user in back end and see forum user role.

Full snippet code

<?php
$user_id = get_current_user_id();
                $new_role_forum_role="bbp_participant";
                  bbp_set_user_role( $user_id, $new_role_forum_role );
                 ?>