简体   繁体   English

BuddyPress - 自动加入群组

[英]BuddyPress - Auto join group

I wanna automatically add new registered user to corresponding group by Buddypress.我想通过 Buddypress 自动将新注册的用户添加到相应的组中。

Here is my code put in the theme's functions.这是我放在主题函数中的代码。

    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

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

But it doesn't work.但它不起作用。

How can I figure out this problem?我怎样才能弄清楚这个问题?

Join a specific group on user activation:加入用户激活的特定组:

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

As for the logic of whatever is a "corresponding group", I'll let the OP figure that one out!至于什么是“对应组”的逻辑,我会让 OP 弄清楚!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM