diff --git src/bp-core/admin/bp-core-admin-schema.php src/bp-core/admin/bp-core-admin-schema.php
index 6f9043a..44506bf 100644
|
|
function bp_core_install_groups() { |
202 | 202 | slug varchar(200) NOT NULL, |
203 | 203 | description longtext NOT NULL, |
204 | 204 | status varchar(10) NOT NULL DEFAULT 'public', |
| 205 | parent_id bigint(20) NOT NULL DEFAULT 0, |
205 | 206 | enable_forum tinyint(1) NOT NULL DEFAULT '1', |
206 | 207 | date_created datetime NOT NULL, |
207 | 208 | KEY creator_id (creator_id), |
208 | | KEY status (status) |
| 209 | KEY status (status), |
| 210 | KEY parent_id (parent_id) |
209 | 211 | ) {$charset_collate};"; |
210 | 212 | |
211 | 213 | $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members ( |
diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
index 16608a4..c16a324 100644
|
|
function bp_update_to_2_5() { |
508 | 508 | * 2.7.0 update routine. |
509 | 509 | * |
510 | 510 | * - Add email unsubscribe salt. |
| 511 | * - Add `parent_id` column to groups table. |
511 | 512 | * |
512 | 513 | * @since 2.7.0 |
513 | 514 | */ |
514 | 515 | function bp_update_to_2_7() { |
515 | 516 | bp_add_option( 'bp-emails-unsubscribe-salt', base64_encode( wp_generate_password( 64, true, true ) ) ); |
| 517 | |
| 518 | /* |
| 519 | * Also handled by `bp_core_install()`. |
| 520 | * Add `parent_id` column to groups table. |
| 521 | */ |
| 522 | if ( bp_is_active( 'groups' ) ) { |
| 523 | bp_core_install_groups(); |
| 524 | } |
516 | 525 | } |
517 | 526 | |
518 | 527 | /** |
diff --git src/bp-groups/bp-groups-actions.php src/bp-groups/bp-groups-actions.php
index 4a3c510..5280a76 100644
|
|
function groups_action_group_feed() { |
566 | 566 | ) ); |
567 | 567 | } |
568 | 568 | add_action( 'bp_actions', 'groups_action_group_feed' ); |
| 569 | |
| 570 | /** |
| 571 | * Update orphaned child groups when the parent is deleted. |
| 572 | * |
| 573 | * @since 2.7.0 |
| 574 | * |
| 575 | * @param BP_Groups_Group $group Instance of the group item being deleted. |
| 576 | */ |
| 577 | function bp_update_orphaned_groups_on_group_delete( $group ) { |
| 578 | // Get child groups and set the parent to the deleted parent's parent. |
| 579 | $grandparent_group_id = ! empty( $group->parent_id ) ? $group->parent_id : 0; |
| 580 | $child_args = array( |
| 581 | 'parent_id' => $group->id, |
| 582 | 'show_hidden' => true, |
| 583 | ); |
| 584 | $children = groups_get_groups( $child_args ); |
| 585 | $children = $children['groups']; |
| 586 | |
| 587 | foreach ( $children as $cgroup ) { |
| 588 | $child_group = groups_get_group( array( 'group_id' => $cgroup->id ) ); |
| 589 | $child_group->parent_id = $grandparent_group_id; |
| 590 | $child_group->save(); |
| 591 | } |
| 592 | } |
| 593 | add_action( 'bp_groups_delete_group', 'bp_update_orphaned_groups_on_group_delete', 10, 2 ); |
| 594 | No newline at end of file |
diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
index cb0753e..7ac4623 100644
|
|
function groups_get_group( $args = '' ) { |
87 | 87 | * @type string $slug The group slug. |
88 | 88 | * @type string $status The group's status. Accepts 'public', 'private' or |
89 | 89 | * 'hidden'. Defaults to 'public'. |
| 90 | * @type int $parent_id The ID of the parent group. Default: 0. |
90 | 91 | * @type int $enable_forum Optional. Whether the group has a forum enabled. |
91 | 92 | * If the legacy forums are enabled for this group |
92 | 93 | * or if a bbPress forum is enabled for the group, |
… |
… |
function groups_create_group( $args = '' ) { |
105 | 106 | 'description' => '', |
106 | 107 | 'slug' => '', |
107 | 108 | 'status' => 'public', |
| 109 | 'parent_id' => 0, |
108 | 110 | 'enable_forum' => 0, |
109 | 111 | 'date_created' => bp_core_current_time() |
110 | 112 | ); |
… |
… |
function groups_create_group( $args = '' ) { |
151 | 153 | $group->description = $description; |
152 | 154 | $group->slug = $slug; |
153 | 155 | $group->status = $status; |
| 156 | $group->parent_id = $parent_id; |
154 | 157 | $group->enable_forum = (int) $enable_forum; |
155 | 158 | $group->date_created = $date_created; |
156 | 159 | |
… |
… |
function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $n |
270 | 273 | * to the group. 'members', 'mods', or 'admins'. |
271 | 274 | * @return bool True on success, false on failure. |
272 | 275 | */ |
273 | | function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false ) { |
| 276 | function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status = false, $parent_id = false ) { |
274 | 277 | |
275 | 278 | $group = groups_get_group( array( 'group_id' => $group_id ) ); |
276 | 279 | $group->enable_forum = $enable_forum; |
… |
… |
function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_ |
285 | 288 | // Now update the status. |
286 | 289 | $group->status = $status; |
287 | 290 | |
| 291 | // Update the parent ID if necessary. |
| 292 | if ( false !== $parent_id ) { |
| 293 | $group->parent_id = $parent_id; |
| 294 | } |
| 295 | |
288 | 296 | if ( !$group->save() ) |
289 | 297 | return false; |
290 | 298 | |
… |
… |
function groups_get_groups( $args = '' ) { |
703 | 711 | 'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of. |
704 | 712 | 'include' => false, // Only include these specific groups (group_ids). |
705 | 713 | 'exclude' => false, // Do not include these specific groups (group_ids). |
| 714 | 'parent_id' => false, // Get groups that are children of the specified group(s). |
706 | 715 | 'search_terms' => false, // Limit to groups that match these search terms. |
707 | 716 | 'group_type' => '', |
708 | 717 | 'group_type__in' => '', |
… |
… |
function groups_get_groups( $args = '' ) { |
722 | 731 | 'user_id' => $r['user_id'], |
723 | 732 | 'include' => $r['include'], |
724 | 733 | 'exclude' => $r['exclude'], |
| 734 | 'parent_id' => $r['parent_id'], |
725 | 735 | 'search_terms' => $r['search_terms'], |
726 | 736 | 'group_type' => $r['group_type'], |
727 | 737 | 'group_type__in' => $r['group_type__in'], |
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
index f08fea5..fa1403e 100644
|
|
function bp_groups_directory_permalink() { |
137 | 137 | * about groups. Default: true. |
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 | * @type array|string $parent_id Array or comma-separated list of group IDs. Results will include only |
| 141 | * child groups of the listed groups. Default: false. |
140 | 142 | * @type bool $update_meta_cache Whether to fetch groupmeta for queried groups. Default: true. |
141 | 143 | * } |
142 | 144 | * @return bool True if there are groups to display that match the params |
… |
… |
function bp_has_groups( $args = '' ) { |
150 | 152 | $slug = false; |
151 | 153 | $type = ''; |
152 | 154 | $search_terms = false; |
| 155 | $parent_id = false; |
153 | 156 | |
154 | 157 | // When looking your own groups, check for two action variables. |
155 | 158 | if ( bp_is_current_action( 'my-groups' ) ) { |
… |
… |
function bp_has_groups( $args = '' ) { |
198 | 201 | 'meta_query' => false, |
199 | 202 | 'include' => false, |
200 | 203 | 'exclude' => false, |
| 204 | 'parent_id' => $parent_id, |
201 | 205 | 'populate_extras' => true, |
202 | 206 | 'update_meta_cache' => true, |
203 | 207 | ), 'has_groups' ); |
… |
… |
function bp_has_groups( $args = '' ) { |
221 | 225 | 'meta_query' => $r['meta_query'], |
222 | 226 | 'include' => $r['include'], |
223 | 227 | 'exclude' => $r['exclude'], |
| 228 | 'parent_id' => $r['parent_id'], |
224 | 229 | 'populate_extras' => (bool) $r['populate_extras'], |
225 | 230 | 'update_meta_cache' => (bool) $r['update_meta_cache'], |
226 | 231 | ) ); |
diff --git src/bp-groups/classes/class-bp-groups-group.php src/bp-groups/classes/class-bp-groups-group.php
index bde4f1e..f16b8c3 100644
|
|
class BP_Groups_Group { |
68 | 68 | public $status; |
69 | 69 | |
70 | 70 | /** |
| 71 | * Parent ID. |
| 72 | * |
| 73 | * ID of parent group, if applicable. |
| 74 | * |
| 75 | * @since 2.7.0 |
| 76 | * @var int |
| 77 | */ |
| 78 | public $parent_id; |
| 79 | |
| 80 | /** |
71 | 81 | * Should (legacy) bbPress forums be enabled for this group? |
72 | 82 | * |
73 | 83 | * @since 1.6.0 |
… |
… |
class BP_Groups_Group { |
214 | 224 | $this->slug = $group->slug; |
215 | 225 | $this->description = stripslashes( $group->description ); |
216 | 226 | $this->status = $group->status; |
| 227 | $this->parent_id = $group->parent_id; |
217 | 228 | $this->enable_forum = $group->enable_forum; |
218 | 229 | $this->date_created = $group->date_created; |
219 | 230 | |
… |
… |
class BP_Groups_Group { |
282 | 293 | $this->slug = apply_filters( 'groups_group_slug_before_save', $this->slug, $this->id ); |
283 | 294 | $this->description = apply_filters( 'groups_group_description_before_save', $this->description, $this->id ); |
284 | 295 | $this->status = apply_filters( 'groups_group_status_before_save', $this->status, $this->id ); |
| 296 | $this->parent_id = apply_filters( 'groups_group_parent_id_before_save', $this->parent_id, $this->id ); |
285 | 297 | $this->enable_forum = apply_filters( 'groups_group_enable_forum_before_save', $this->enable_forum, $this->id ); |
286 | 298 | $this->date_created = apply_filters( 'groups_group_date_created_before_save', $this->date_created, $this->id ); |
287 | 299 | |
… |
… |
class BP_Groups_Group { |
324 | 336 | slug = %s, |
325 | 337 | description = %s, |
326 | 338 | status = %s, |
| 339 | parent_id = %d, |
327 | 340 | enable_forum = %d, |
328 | 341 | date_created = %s |
329 | 342 | WHERE |
… |
… |
class BP_Groups_Group { |
334 | 347 | $this->slug, |
335 | 348 | $this->description, |
336 | 349 | $this->status, |
| 350 | $this->parent_id, |
337 | 351 | $this->enable_forum, |
338 | 352 | $this->date_created, |
339 | 353 | $this->id |
… |
… |
class BP_Groups_Group { |
346 | 360 | slug, |
347 | 361 | description, |
348 | 362 | status, |
| 363 | parent_id, |
349 | 364 | enable_forum, |
350 | 365 | date_created |
351 | 366 | ) VALUES ( |
352 | | %d, %s, %s, %s, %s, %d, %s |
| 367 | %d, %s, %s, %s, %s, %d, %d, %s |
353 | 368 | )", |
354 | 369 | $this->creator_id, |
355 | 370 | $this->name, |
356 | 371 | $this->slug, |
357 | 372 | $this->description, |
358 | 373 | $this->status, |
| 374 | $this->parent_id, |
359 | 375 | $this->enable_forum, |
360 | 376 | $this->date_created |
361 | 377 | ); |
… |
… |
class BP_Groups_Group { |
710 | 726 | * See {@link WP_Meta_Query::queries} for description. |
711 | 727 | * @type array|string $value Optional. Array or comma-separated list of group IDs. Results |
712 | 728 | * will be limited to groups within the list. Default: false. |
| 729 | * @type array|string $parent_id Optional. Array or comma-separated list of group IDs. Results |
| 730 | * will be limited to children of the specified groups. Default: false. |
713 | 731 | * @type bool $populate_extras Whether to fetch additional information |
714 | 732 | * (such as member count) about groups. Default: true. |
715 | 733 | * @type array|string $exclude Optional. Array or comma-separated list of group IDs. |
… |
… |
class BP_Groups_Group { |
761 | 779 | 'group_type__not_in' => '', |
762 | 780 | 'meta_query' => false, |
763 | 781 | 'include' => false, |
| 782 | 'parent_id' => false, |
764 | 783 | 'populate_extras' => true, |
765 | 784 | 'update_meta_cache' => true, |
766 | 785 | 'exclude' => false, |
… |
… |
class BP_Groups_Group { |
835 | 854 | $sql['include'] = " AND g.id IN ({$include})"; |
836 | 855 | } |
837 | 856 | |
| 857 | if ( ! empty( $r['parent_id'] ) ) { |
| 858 | $parent_id = implode( ',', wp_parse_id_list( $r['parent_id'] ) ); |
| 859 | $sql['parent_id'] = " AND g.parent_id IN ({$parent_id})"; |
| 860 | } |
| 861 | |
838 | 862 | if ( ! empty( $r['exclude'] ) ) { |
839 | 863 | $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) ); |
840 | 864 | $sql['exclude'] = " AND g.id NOT IN ({$exclude})"; |
… |
… |
class BP_Groups_Group { |
948 | 972 | } |
949 | 973 | |
950 | 974 | // Already escaped in the paginated results block. |
| 975 | if ( ! empty( $parent_id ) ) { |
| 976 | $total_sql['where'][] = "g.parent_id IN ({$parent_id})"; |
| 977 | } |
| 978 | |
| 979 | // Already escaped in the paginated results block. |
951 | 980 | if ( ! empty( $exclude ) ) { |
952 | 981 | $total_sql['where'][] = "g.id NOT IN ({$exclude})"; |
953 | 982 | } |
diff --git src/bp-groups/classes/class-bp-groups-template.php src/bp-groups/classes/class-bp-groups-template.php
index 043d8f4..49e5eb6 100644
|
|
class BP_Groups_Template { |
165 | 165 | 'slug' => false, |
166 | 166 | 'include' => false, |
167 | 167 | 'exclude' => false, |
| 168 | 'parent_id' => false, |
168 | 169 | 'search_terms' => '', |
169 | 170 | 'group_type' => '', |
170 | 171 | 'group_type__in' => '', |
… |
… |
class BP_Groups_Template { |
226 | 227 | 'group_type__not_in' => $group_type__not_in, |
227 | 228 | 'include' => $include, |
228 | 229 | 'exclude' => $exclude, |
| 230 | 'parent_id' => $parent_id, |
229 | 231 | 'populate_extras' => $populate_extras, |
230 | 232 | 'update_meta_cache' => $update_meta_cache, |
231 | 233 | 'show_hidden' => $show_hidden, |