[Plugin: BP Group Hierarchy] group members automatically added to a subgroup
-
If someone is looking for adding group members from “parent” group to sub group automatically I did it by adding this code to /wp-content/plugins/bp-custom.php:
// 3 functions exending plugin BP-group-hierarchy include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if (is_plugin_active('bp-group-hierarchy/index.php')){ function gh_add_users_when_group_created() { global $wpdb, $bp; $cur_gr_id = $bp->groups->current_group->id; $cur_gr_par_id = $wpdb->get_var($wpdb->prepare("SELECT DISTINCT g.parent_id FROM {$bp->groups->table_name} g WHERE g.id=%d", $cur_gr_id)); if ($cur_gr_par_id) { $mysql = "SELECT DISTINCT user_id FROM wp_bp_groups_members WHERE group_id=$cur_gr_par_id"; $results = $wpdb->get_results($mysql); foreach ($results as $us) { groups_accept_invite($us->user_id, $cur_gr_id); } } } add_action( 'bp_after_group_creation_step_buttons', 'gh_add_users_when_group_created',80 ); function gh_add_user_when_user_is_added_to_parent_group($group_id, $user_id) { global $bp; $cur_gr_id = $bp->groups->current_group->id; $bphc = new BP_Groups_Hierarchy; $bphc->bp_groups_hierarchy($cur_gr_id); $chil = $bphc->has_children(); if (empty($chil)) return false; foreach ($chil as $child => $val) { groups_accept_invite($user_id, $val); } } add_action( 'groups_join_group', 'gh_add_user_when_user_is_added_to_parent_group', 10, 2); function gh_remove_user_when_is_deleted_in_parent_group($user_id, $group_id ) { global $bp; $cur_gr_id = $bp->groups->current_group->id; $bphc = new BP_Groups_Hierarchy; $bphc->bp_groups_hierarchy($cur_gr_id); $chil = $bphc->has_children(); if (empty($chil)) return false; foreach ($chil as $child => $val) { $member = new BP_Groups_Member($user_id, $val); $member->remove(); } } add_action('groups_leave_group', 'gh_remove_user_when_is_deleted_in_parent_group', 30, 2); add_action('groups_removed_member', 'gh_remove_user_when_is_deleted_in_parent_group', 30, 2); add_action('groups_remove_member', 'gh_remove_user_when_is_deleted_in_parent_group', 30, 2); }
It works for me: WP 3.4.2, BP 1.6.1, BP Group Hierarchy 1.3.4
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘[Plugin: BP Group Hierarchy] group members automatically added to a subgroup’ is closed to new replies.