Wordpress - Change forum role from outside bbPress by checking user status

非 Y 不嫁゛ 提交于 2019-12-08 02:41:32

问题


I would like to check the user status and update their bbPress forum role accordingly. (Not the Wordpress role.)

The purpose is to add functionality to the BP-Registration-Options plugin that moderates user registration (In BuddyPress. Currently the plugin sets the user status to 69 while the user is unapproved, and blocks access to BuddyPress functionality. However, the user is still able to login.

When they log-in, bbPress automatically sets the user forum role according to your setting in the back end. In this case it is set to 'spectator'. When the user is approved by the admin their status changes and I want it to also update the bbPress role to 'participant'.

Here is my first attempt:

function bp_registration_options_additional() {
  if ( is_user_logged_in() ) {  
    $user_ID = get_current_user_id();
    $user = get_userdata( $user_ID );
      if (69 !== $user->user_status ) {

      // Here is where I need help. 

     //How to set the bbPress forum role to 'Participant'? 

    }
  }
}
add_action( 'wp_loaded', 'bp_registration_options_additional' );

Thanks!

WP: 3.8 bbPress: Version 2.5.2

EDIT: A bit of additional information. The meta_key for the forum roles is: wp_capabilities. The meta_value of a user with the forum role 'spectator; is: a:2:{s:10:"subscriber";b:1;s:13:"bbp_spectator";b:1;}


回答1:


Had the same requirement - to update the wp_capabilities field -

$wp_user_capabilities_arr = array( "subscriber" => true, "bbp_participant" => true ); update_user_meta($wp_user_id, "wp_capabilities", $wp_user_capabilities_arr);

And after update the data looks like:

a:2:{s:10:"subscriber";b:1;s:15:"bbp_participant";b:1;}



来源:https://stackoverflow.com/questions/21012652/wordpress-change-forum-role-from-outside-bbpress-by-checking-user-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!