Wordpress - 通过检查用户状态从 bbPress 外部更改论坛角色 [英] Wordpress - Change forum role from outside bbPress by checking user status

查看:67
本文介绍了Wordpress - 通过检查用户状态从 bbPress 外部更改论坛角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查用户状态并相应地更新他们的 bbPress 论坛角色.(不是 Wordpress 角色.)

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

目的是向 BP-Registration-Options 插件添加功能,以调节用户注册(在 BuddyPress 中.目前,该插件在用户未获批准时将用户状态设置为 69,并阻止对 BuddyPress 功能的访问.然而,用户仍然可以登录.

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.

当他们登录时,bbPress 会根据您在后端的设置自动设置用户论坛角色.在这种情况下,它被设置为旁观者".当用户被管理员批准时,他们的状态会发生变化,我希望它也将 bbPress 角色更新为参与者".

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'.

这是我的第一次尝试:

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' );

谢谢!

WP:3.8bbPress:版本 2.5.2

WP: 3.8 bbPress: Version 2.5.2

一些附加信息.论坛角色的元键是:wp_capabilities.论坛角色为观众"的用户的元值;是:a:2:{s:10:"subscriber";b:1;s:13:"bbp_spectator";b:1;}

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;}

推荐答案

有相同的要求 - 更新 wp_capabilities 字段 -

Had the same requirement - to update the wp_capabilities field -

$wp_user_capabilities_arr = 数组(订阅者" =>真的,bbp_participant"=>真的);update_user_meta($wp_user_id, "wp_capabilities", $wp_user_capabilities_arr);

更新后的数据如下:

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

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

这篇关于Wordpress - 通过检查用户状态从 bbPress 外部更改论坛角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆