function call to as...
 
Notifications
Clear all

Limited Support

Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed. We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.

 

function call to assign wpForo user role?

2 Posts
1 Users
0 Reactions
2,061 Views
(@dlinstedt)
Member Customer
Joined: 7 years ago
Posts: 16
Topic starter  

Hi team,

As always, stellar product, fast, efficient and reliable!  Love it!

I am wondering if there is an acceptable function call in wpForo, to assign a user a new primary wpForo based role?

I am working with wpFusion, and when a tag changes I need to "change the wpForo role".

I don't want to sync with wordpress roles, for many reasons - so I am looking for an available function call in wpForo to get this done.  It would be nice if there were an API callback for this.  I am sure I am not the only one that could use this functionality (nearly everyone using wooCommerce would need this too I think).

Thank you kindly,

Dan


   
Quote
(@dlinstedt)
Member Customer
Joined: 7 years ago
Posts: 16
Topic starter  

Found the code in wpf-hooks.php line 2521  wpforo_update_usergroup_on_role_change

however, cannot call that function UNLESS the sync flag is turned on.

I guess, what I am looking for is an additional optional parameter on the end of the call:

$ignore_sync_flag = 0  (default)

pass in a zero, and it means "look at the sync flag feature setting"

pass in a one, and it means: "set the role regardless of the sync flag feature"

I think, that would make it much more usable, then I could turn off the forced sync feature, and call this function to change a users' wpForo user group.

Thoughts?  (i've pasted the updated code below that would make this work the way I describe)

function wpforo_update_usergroup_on_role_change( $userid, $new_role, $old_roles = array() ,$ignore_sync_flag=0){
if( wpforo_feature('role-synch') || $ignore_sync_flag==1 ) {
$user_ug_id = WPF()->member->get_usergroup( $userid );
$role_ug_ids = WPF()->usergroup->get_usergroups_by_role( $new_role );
if( !empty($role_ug_ids) && is_array($role_ug_ids) ){
if( count($role_ug_ids) > 1 ){
$prime_ugid = array_shift($role_ug_ids);
if( !in_array($user_ug_id, $role_ug_ids) ){
WPF()->member->set_usergroup( $userid, $prime_ugid );
WPF()->member->set_usergroups_secondary( $userid, $role_ug_ids );
}
}
else{
$groupid = current($role_ug_ids);
if( $groupid != $user_ug_id ){
WPF()->member->set_usergroup( $userid, $groupid );
}
}
}
}
}

   
ReplyQuote
Share:
Scroll to top