Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save greathmaster/e67f1ae0feb28c9ab3521b404c8e0544 to your computer and use it in GitHub Desktop.
Save greathmaster/e67f1ae0feb28c9ab3521b404c8e0544 to your computer and use it in GitHub Desktop.
Add to BuddyPress groups and bbPress forum subscription based on xProfile checkbox selection
/*
Add to BuddyPress groups and forums (including sub-forums) based on xProfile checkbox selection
*/
function my_bp_core_signup_user($user_id)
{
$groups = array(1 => "HIKING",
2 => "PADDLING",
3 => "CYCLING",
4=> "SKIING",);
$checkbox_xprofile_id = 149;
$selected_groups = xprofile_get_field_data($checkbox_xprofile_id, $user_id);
if(!empty($selected_groups))
{
foreach($groups as $group_id => $group_name)
{
if(in_array($group_name, $selected_groups))
{
groups_join_group($group_id, $user_id );
}
}
}
//example of adding automatically to a group
$overall_group_id = 5;
function my_bp_core_activated_user($user_id)
{
$groups = array(1 => "HIKING",
2 => "PADDLING",
3 => "CYCLING",
4=> "SKIING",);
$forums = array("HIKING" => 7142, "PADDLING" =>7145, "CYCLING" =>7147, "SKIING" => 7066);
$selected_groups = xprofile_get_field_data('149', $user_id);
if(!empty($selected_groups))
{
foreach($groups as $group_id => $group_name)
{
if(in_array($group_name, $selected_groups))
{
groups_join_group($group_id, $user_id );
//bbp_add_user_forum_subscription( $user_id, $forums[$group_name] );
subscribe_to_forums($user_id, $forums[$group_name]);
}
}
}
$overall_group_id = 5;
$overall_forum_id = 7133;
groups_join_group($overall_group_id, $user_id );
//bbp_add_user_forum_subscription( $user_id, $overall_forum_id);
subscribe_to_forums($user_id, $overall_forum_id);
}
//Subscribe a user to a forum and it's sub forums
function subscribe_to_forums($user_id, $forum_id)
{
//subscribe to the parent forum
bbp_add_user_forum_subscription( $user_id, $forum_id);
//subscribe to sub forums (if they exist)
if (bbp_get_forum_subforum_count( $forum_id ) > 0)
{
$sub_forums = bbp_forum_get_subforums($forum_id);
foreach($sub_forums as $sub_forum)
{
bbp_add_user_forum_subscription( $user_id, $sub_forum->ID);
}
}
}
function my_init()
{
add_action('bp_core_activated_user', 'my_bp_core_activated_user',15, 1);
}
add_action('init', 'my_init');
{
$groups = array(1 => "HIKING",
2 => "PADDLING",
3 => "CYCLING",
4=> "SKIING",);
$forums = array("HIKING" => 7142, "PADDLING" =>7145, "CYCLING" =>7147, "SKIING" => 7066);
$selected_groups = xprofile_get_field_data('149', $user_id);
if(!empty($selected_groups))
{
foreach($groups as $group_id => $group_name)
{
if(in_array($group_name, $selected_groups))
{
groups_join_group($group_id, $user_id );
bbp_add_user_forum_subscription( $user_id, $forums[$group_name] );
}
}
}
$overall_group_id = 5;
$overall_forum_id = 7133;
groups_join_group($overall_group_id, $user_id );
bbp_add_user_forum_subscription( $user_id, $overall_forum_id);
}
function my_init()
{
add_action('bp_core_activated_user', 'my_bp_core_activated_user',15, 1);
}
add_action('init', 'my_init');
}
function my_init()
{
add_action('bp_core_activated_user', 'my_bp_core_signup_user',15, 1);
}
add_action('init', 'my_init');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment