/** * Handle the display of a group's Members page. */ function groups_screen_group_members() { if (!bp_is_single_item()) { return false; } $bp = buddypress(); // Refresh the group member count meta. groups_update_groupmeta($bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count($bp->groups->current_group->id)); /** * Fires before the loading of a group's Members page. * * @since 1.0.0 * * @param int $id ID of the group whose members are being displayed. */ do_action('groups_screen_group_members', $bp->groups->current_group->id); /** * Filters the template to load for a group's Members page. * * @since 1.0.0 * * @param string $value Path to a group's Members template. */ bp_core_load_template(apply_filters('groups_template_group_members', 'groups/single/home')); }
/** * Delete all group membership information for the specified user * * @global object $bp BuddyPress global settings * @global wpdb $wpdb WordPress database object * @param int $user_id * @since 1.0 * @uses BP_Groups_Member */ function delete_all_for_user($user_id) { global $bp, $wpdb; // Get all the group ids for the current user's groups and update counts $group_ids = BP_Groups_Member::get_group_ids($user_id); foreach ($group_ids['groups'] as $group_id) { groups_update_groupmeta($group_id, 'total_member_count', groups_get_total_member_count($group_id) - 1); // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync if (groups_is_user_admin($user_id, $group_id) && count(groups_get_group_admins($group_id)) < 2 && groups_is_user_creator($user_id, $group_id)) { groups_delete_group($group_id); } } return $wpdb->query($wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id)); }
/** * Handle the display of a group's Members page. */ function groups_screen_group_members() { if (!bp_is_single_item()) { return false; } $bp = buddypress(); // Refresh the group member count meta groups_update_groupmeta($bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count($bp->groups->current_group->id)); do_action('groups_screen_group_members', $bp->groups->current_group->id); bp_core_load_template(apply_filters('groups_template_group_members', 'groups/single/home')); }
/** * Create the hub overview CSV when requested. * * @since 1.0.0 */ public function run_stat_hub_csv() { global $wpdb; $bp = buddypress(); // Output headers so that the file is downloaded rather than displayed. header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=cc-hubs-overview.csv'); // Create a file pointer connected to the output stream. $output = fopen('php://output', 'w'); // Write a header row. $row = array('Hub ID', 'Name', 'Slug', 'Status', 'Date Created', 'Last Activity', 'Parent Hub ID', 'Total Members', 'Creator ID', 'Creator Email', 'Forum', 'BP Docs', 'CC Hub Home Page', 'CC Hub Pages', 'CC Hub Narratives', 'Custom Plugins'); fputcsv($output, $row); // Groups Loop if (bp_has_groups(array('order' => 'ASC', 'orderby' => 'date_created', 'page' => null, 'per_page' => null, 'max' => false, 'show_hidden' => true, 'user_id' => null, 'meta_query' => false, 'include' => false, 'exclude' => false, 'populate_extras' => false, 'update_meta_cache' => false))) { while (bp_groups()) { bp_the_group(); $group_id = bp_get_group_id(); $group_object = groups_get_group(array('group_id' => (int) $group_id, 'populate_extras' => true)); // Hub ID $row = array($group_id); // Name $row[] = bp_get_group_name(); // Slug $row[] = bp_get_group_slug(); // Status $row[] = bp_get_group_status(); // Date Created $row[] = $group_object->date_created; // Date of last activity $row[] = $group_object->last_activity; // Parent Hub ID $row[] = $wpdb->get_var($wpdb->prepare("SELECT g.parent_id FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id)); // Total Members $row[] = groups_get_total_member_count($group_id); // Creator ID $creator_id = $group_object->creator_id; $row[] = $creator_id; // Creator Email $creator = get_user_by('id', $creator_id); $row[] = $creator->user_email; // Forum $row[] = $group_object->enable_forum; // BP Docs if (function_exists('bp_docs_is_docs_enabled_for_group')) { $row[] = bp_docs_is_docs_enabled_for_group($group_id); } else { $row[] = ''; } // CC Hub Home Page if (function_exists('cc_get_group_home_page_post') && cc_get_group_home_page_post($group_id)->have_posts()) { $row[] = 1; } else { $row[] = 0; } // CC Hub Pages $row[] = (bool) groups_get_groupmeta($group_id, "ccgp_is_enabled"); // CC Hub Narratives $row[] = (bool) groups_get_groupmeta($group_id, "ccgn_is_enabled"); // Custom Plugins // To make your group-specific plugin be counted, so something like this: /* add_filter( 'cc_stats_custom_plugins', 'prefix_report_custom_plugin', 10, 2 ); * function prefix_report_custom_plugin( $custom_plugins, $group_id ) { * if ( $group_id == sa_get_group_id() ) { * $custom_plugins[] = "CC Salud America"; * } * return $custom_plugins; * } */ $custom_plugins = apply_filters('cc_stats_custom_plugins', array(), $group_id); $custom_plugins = implode(' ', $custom_plugins); $row[] = $custom_plugins; // Write the row. fputcsv($output, $row); } } fclose($output); exit; }
function groups_screen_group_members() { global $bp; if ($bp->is_single_item) { // Refresh the group member count meta groups_update_groupmeta($bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count($bp->groups->current_group->id)); do_action('groups_screen_group_members', $bp->groups->current_group->id); bp_core_load_template(apply_filters('groups_template_group_members', 'groups/single/home')); } }
/** * @group groups_leave_group * @group group_membership */ public function test_groups_leave_group_multiple_admins_allow_leave() { $old_current_user = get_current_user_id(); $u1 = $this->factory->user->create(); $g = $this->factory->group->create(array('creator_id' => $u1)); $u2 = $this->factory->user->create(); $this->add_user_to_group($u2, $g); $m2 = new BP_Groups_Member($u2, $g); $m2->promote('admin'); $before = groups_get_total_member_count($g); $this->set_current_user($u1); groups_leave_group($g, $u1); $after = groups_get_total_member_count($g); $this->assertEquals($before - 1, $after); $this->set_current_user($old_current_user); }
function wangguard_spam_all_data($user_id) { global $wpdb, $bp; $wpdb->query($wpdb->prepare("DELETE FROM {$bp->blogs->table_name} WHERE user_id = %d", $user_id)); friends_remove_data($user_id); $group_ids = BP_Groups_Member::get_group_ids($user_id); foreach ($group_ids['groups'] as $group_id) { groups_update_groupmeta($group_id, 'total_member_count', groups_get_total_member_count($group_id) - 1); // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync if (groups_is_user_admin($user_id, $group_id) && count(groups_get_group_admins($group_id)) < 2 && groups_is_user_creator($user_id, $group_id)) { groups_delete_group($group_id); } } return $wpdb->query($wpdb->prepare("DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id)); BP_Groups_Member::delete_all_for_user($user_id); }