我想通过Buddypress自动将新注册的用户添加到相应的组中。
这是我放在主题函数中的代码。
function automatic_group_membership( $user_id ) {
if( !$user_id ) return false;
$join_group = xprofile_get_field_data(2, $user_id); // 2 is xprofile field_id
// conditional
if ($join_group == "Group1") // Group Name
$group_id = 3; // Group id
// action
groups_accept_invite( $user_id, $group_id );
}
add_action( 'bp_core_activated_user', 'automatic_group_membership' );
但它不起作用。
我怎样才能算出这个问题?
加入用户激活的特定组:
function auto_join_group( $user_id ) {
if( !$user_id ) return false;
$group_id = 7;
groups_join_group( $group_id, $user_id );
}
add_action( 'bp_core_activated_user', 'auto_join_group' );
至于什么是"逻辑";对应组";,我会让OP弄清楚的!