Changeset 13448
- Timestamp:
- 04/07/2023 07:47:34 AM (18 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template.php
r13443 r13448 2780 2780 */ 2781 2781 function bp_is_groups_directory() { 2782 if ( bp_is_groups_component() && ! bp_is_group() && ( ! bp_current_action() || ( bp_action_variable() && bp_is_current_action( bp_get_groups_group_type_base() ) ) ) ) { 2783 return true; 2784 } 2785 2786 return false; 2782 $return = false; 2783 2784 if ( bp_is_groups_component() && ! bp_is_group() ) { 2785 $return = ! bp_current_action() || ! empty( buddypress()->groups->current_directory_type ); 2786 } 2787 2788 return $return; 2787 2789 } 2788 2790 -
trunk/src/bp-groups/classes/class-bp-groups-component.php
r13441 r13448 322 322 } 323 323 324 // Set group type if available.325 if ( bp_is_groups_directory() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) {326 $matched_types = bp_groups_get_group_types( array(327 'has_directory' => true,328 'directory_slug' => bp_action_variable(),329 ) );330 331 // Set 404 if we do not have a valid group type.332 if ( empty( $matched_types ) ) {333 bp_do_404();334 return;335 }336 337 // Set our directory type marker.338 $this->current_directory_type = reset( $matched_types );339 }340 341 324 // Set up variables specific to the group creation process. 342 325 if ( bp_is_groups_component() && bp_is_current_action( 'create' ) && bp_user_can_create_groups() && isset( $_COOKIE['bp_new_group_id'] ) ) { 343 326 $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; 344 327 } 328 329 // The base slug to filter the groups directory according to a group type. 330 $group_type_base = bp_get_groups_group_type_base(); 345 331 346 332 /** … … 351 337 * @param array $value Array of illegal group names/slugs. 352 338 */ 353 $this->forbidden_names = apply_filters( 'groups_forbidden_names', array( 354 'my-groups', 355 'create', 356 'invites', 357 'send-invites', 358 'forum', 359 'delete', 360 'add', 361 'admin', 362 'request-membership', 363 'members', 364 'settings', 365 'avatar', 366 $this->slug, 367 $this->root_slug, 368 ) ); 339 $this->forbidden_names = apply_filters( 340 'groups_forbidden_names', 341 array( 342 'my-groups', 343 'create', 344 'invites', 345 'send-invites', 346 'forum', 347 'delete', 348 'add', 349 'admin', 350 'request-membership', 351 'members', 352 'settings', 353 'avatar', 354 $this->slug, 355 $this->root_slug, 356 $group_type_base, 357 ) 358 ); 369 359 370 360 // If the user was attempting to access a group, but no group by that name was found, 404. 371 if ( bp_is_groups_component() && empty( $this->current_group ) && empty( $this->current_directory_type ) && bp_current_action() && ! in_array( bp_current_action(), $this->forbidden_names ) ) { 372 bp_do_404(); 373 return; 361 if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() ) { 362 363 // Set group type if available. 364 if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { 365 $matched_type = ''; 366 $matched_types = bp_groups_get_group_types( 367 array( 368 'has_directory' => true, 369 'directory_slug' => bp_action_variable(), 370 ) 371 ); 372 373 // Set our directory type marker. 374 if ( ! empty( $matched_types ) ) { 375 $this->current_directory_type = reset( $matched_types ); 376 } 377 } 378 379 if ( ! $this->current_directory_type && ! in_array( bp_current_action(), $this->forbidden_names, true ) ) { 380 bp_do_404(); 381 return; 382 } 374 383 } 375 384 -
trunk/src/bp-groups/classes/class-bp-groups-theme-compat.php
r12647 r13448 37 37 38 38 // Bail if not looking at a group. 39 if ( ! bp_is_groups_component() ) 39 if ( ! bp_is_groups_component() ) { 40 40 return; 41 } 41 42 42 43 // Group Directory. -
trunk/tests/phpunit/testcases/routing/groups.php
r13433 r13448 75 75 public function test_group_directory_should_404_for_group_types_that_have_no_directory() { 76 76 $this->set_permalink_structure( '/%postname%/' ); 77 bp_ register_member_type( 'foo', array( 'has_directory' => false ) );78 $this->go_to( bp_get_ members_directory_permalink() . 'type/foo/' );79 $this->assert True( is_404() );77 bp_groups_register_group_type( 'taz', array( 'has_directory' => false ) ); 78 $this->go_to( bp_get_groups_directory_permalink() . 'type/taz/' ); 79 $this->assertEmpty( bp_get_current_group_directory_type() ); 80 80 } 81 81 … … 85 85 public function test_group_directory_should_404_for_invalid_group_types() { 86 86 $this->set_permalink_structure( '/%postname%/' ); 87 $this->go_to( bp_get_ members_directory_permalink() . 'type/foo/' );88 $this->assert True( is_404() );87 $this->go_to( bp_get_groups_directory_permalink() . 'type/zat/' ); 88 $this->assertEmpty( bp_get_current_group_directory_type() ); 89 89 } 90 90
Note: See TracChangeset
for help on using the changeset viewer.