diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
index e8337e1..0639849 100644
|
|
function groups_get_groups( $args = '' ) { |
713 | 713 | 'page' => 1, // The page to return if limiting per page. |
714 | 714 | 'populate_extras' => true, // Fetch meta such as is_banned and is_member. |
715 | 715 | 'update_meta_cache' => true, // Pre-fetch groupmeta for queried groups. |
| 716 | 'update_admin_cache' => true, |
716 | 717 | ); |
717 | 718 | |
718 | 719 | $r = wp_parse_args( $args, $defaults ); |
… |
… |
function groups_get_groups( $args = '' ) { |
732 | 733 | 'page' => $r['page'], |
733 | 734 | 'populate_extras' => $r['populate_extras'], |
734 | 735 | 'update_meta_cache' => $r['update_meta_cache'], |
| 736 | 'update_admin_cache' => $r['update_admin_cache'], |
735 | 737 | 'order' => $r['order'], |
736 | 738 | 'orderby' => $r['orderby'], |
737 | 739 | ) ); |
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
index 4fe3a61..e8745aa 100644
|
|
function bp_groups_directory_permalink() { |
138 | 138 | * @type array|string $exclude Array or comma-separated list of group IDs. Results will exclude |
139 | 139 | * the listed groups. Default: false. |
140 | 140 | * @type bool $update_meta_cache Whether to fetch groupmeta for queried groups. Default: true. |
| 141 | * @type bool $update_admin_cache Whether to pre-fetch group admins for queried groups. Default: true. |
141 | 142 | * } |
142 | 143 | * @return bool True if there are groups to display that match the params |
143 | 144 | */ |
… |
… |
function bp_has_groups( $args = '' ) { |
200 | 201 | 'exclude' => false, |
201 | 202 | 'populate_extras' => true, |
202 | 203 | 'update_meta_cache' => true, |
| 204 | 'update_admin_cache' => true, |
203 | 205 | ), 'has_groups' ); |
204 | 206 | |
205 | 207 | // Setup the Groups template global. |
… |
… |
function bp_has_groups( $args = '' ) { |
223 | 225 | 'exclude' => $r['exclude'], |
224 | 226 | 'populate_extras' => (bool) $r['populate_extras'], |
225 | 227 | 'update_meta_cache' => (bool) $r['update_meta_cache'], |
| 228 | 'update_admin_cache' => (bool) $r['update_admin_cache'], |
226 | 229 | ) ); |
227 | 230 | |
228 | 231 | /** |
diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php
index c763f6e..ed5b5bb 100644
|
|
class BP_Groups_Group { |
760 | 760 | * Results will exclude the listed groups. Default: false. |
761 | 761 | * @type bool $update_meta_cache Whether to pre-fetch groupmeta for the returned groups. |
762 | 762 | * Default: true. |
| 763 | * @type bool $update_admin_cache Whether to pre-fetch administrator IDs for the returned |
| 764 | * groups. Default: true. |
763 | 765 | * @type bool $show_hidden Whether to include hidden groups in results. Default: false. |
764 | 766 | * } |
765 | 767 | * @return array { |
… |
… |
class BP_Groups_Group { |
807 | 809 | 'include' => false, |
808 | 810 | 'populate_extras' => true, |
809 | 811 | 'update_meta_cache' => true, |
| 812 | 'update_admin_cache' => true, |
810 | 813 | 'exclude' => false, |
811 | 814 | 'show_hidden' => false, |
812 | 815 | ); |
… |
… |
class BP_Groups_Group { |
1023 | 1026 | bp_groups_update_meta_cache( $group_ids ); |
1024 | 1027 | } |
1025 | 1028 | |
| 1029 | // Grab all administrator IDs. |
| 1030 | if ( $r['update_admin_cache'] ) { |
| 1031 | BP_Groups_Member::prime_group_administrator_ids_cache( $group_ids ); |
| 1032 | } |
| 1033 | |
1026 | 1034 | // Set up integer properties needing casting. |
1027 | 1035 | $int_props = array( |
1028 | 1036 | 'id', 'creator_id', 'enable_forum' |
diff --git src/bp-groups/classes/class-bp-groups-member.php src/bp-groups/classes/class-bp-groups-member.php
index 0aae803..25a9b53 100644
|
|
class BP_Groups_Member { |
1043 | 1043 | $group_admins = wp_cache_get( $group_id, 'bp_group_admins' ); |
1044 | 1044 | |
1045 | 1045 | if ( false === $group_admins ) { |
1046 | | $bp = buddypress(); |
1047 | | $group_admins = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_admin = 1 AND is_banned = 0", $group_id ) ); |
1048 | | |
1049 | | wp_cache_set( $group_id, $group_admins, 'bp_group_admins' ); |
| 1046 | self::prime_group_administrator_ids_cache( array( $group_id ) ); |
| 1047 | $group_admins = wp_cache_get( $group_id, 'bp_group_admins' ); |
1050 | 1048 | } |
1051 | 1049 | |
1052 | 1050 | // Integer casting. |
… |
… |
class BP_Groups_Member { |
1058 | 1056 | } |
1059 | 1057 | |
1060 | 1058 | /** |
| 1059 | * Prime the bp_group_admins cache for one or more groups. |
| 1060 | * |
| 1061 | * @since 2.7.0 |
| 1062 | * |
| 1063 | * @param array $group_ids IDs of the groups. |
| 1064 | * @return bool True on success. |
| 1065 | */ |
| 1066 | public static function prime_group_administrator_ids_cache( $group_ids ) { |
| 1067 | global $wpdb; |
| 1068 | |
| 1069 | $uncached = bp_get_non_cached_ids( $group_ids, 'bp_group_admins' ); |
| 1070 | |
| 1071 | if ( $uncached ) { |
| 1072 | $bp = buddypress(); |
| 1073 | $uncached_sql = implode( ',', array_map( 'intval', $uncached ) ); |
| 1074 | $group_admins = $wpdb->get_results( "SELECT user_id, group_id, date_modified FROM {$bp->groups->table_name_members} WHERE group_id IN ({$uncached_sql}) AND is_admin = 1 AND is_banned = 0" ); |
| 1075 | |
| 1076 | $groups = array(); |
| 1077 | if ( $group_admins ) { |
| 1078 | foreach ( $group_admins as $group_admin ) { |
| 1079 | $admin_obj = new stdClass(); |
| 1080 | $admin_obj->user_id = $group_admin->user_id; |
| 1081 | $admin_obj->date_modified = $group_admin->date_modified; |
| 1082 | $groups[ $group_admin->group_id ][] = $admin_obj; |
| 1083 | } |
| 1084 | |
| 1085 | foreach ( $groups as $this_group_id => $this_group_admins ) { |
| 1086 | wp_cache_set( $this_group_id, $this_group_admins, 'bp_group_admins' ); |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | /** |
1061 | 1093 | * Get a list of all a given group's moderators. |
1062 | 1094 | * |
1063 | 1095 | * @since 1.6.0 |
diff --git src/bp-groups/classes/class-bp-groups-template.php src/bp-groups/classes/class-bp-groups-template.php
index 043d8f4..d3a776e 100644
|
|
class BP_Groups_Template { |
172 | 172 | 'meta_query' => false, |
173 | 173 | 'populate_extras' => true, |
174 | 174 | 'update_meta_cache' => true, |
| 175 | 'update_admin_cache' => true, |
175 | 176 | ); |
176 | 177 | |
177 | 178 | $r = wp_parse_args( $args, $defaults ); |
… |
… |
class BP_Groups_Template { |
228 | 229 | 'exclude' => $exclude, |
229 | 230 | 'populate_extras' => $populate_extras, |
230 | 231 | 'update_meta_cache' => $update_meta_cache, |
| 232 | 'update_admin_cache' => $update_admin_cache, |
231 | 233 | 'show_hidden' => $show_hidden, |
232 | 234 | ) ); |
233 | 235 | } |