Skip to:
Content

BuddyPress.org

Changeset 11405


Ignore:
Timestamp:
01/31/2017 08:31:10 PM (3 years ago)
Author:
r-a-y
Message:

Groups: Fix AJAX pagination when on a group type directory page.

This commit moves group type directory detection from the
'template_redirect' hook to our groups component class to ensure
detection is available for AJAX purposes.

Commit also changes invalid group type directory requests to 404 instead
of redirecting back to the main Groups directory.

Props r-a-y, dcavins.

Fixes #7423.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-screens.php

    r11360 r11405  
    2222function groups_directory_groups_setup() {
    2323    if ( bp_is_groups_directory() ) {
    24         // Set group type if available.
    25         if ( bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) {
    26             $matched_types = bp_groups_get_group_types( array(
    27                 'has_directory'  => true,
    28                 'directory_slug' => bp_action_variable(),
    29             ) );
    30 
    31             // Redirect back to group directory if no match.
    32             if ( empty( $matched_types ) ) {
    33                 bp_core_redirect( bp_get_groups_directory_permalink() );
    34             }
    35 
    36             // Set our global variable.
    37             buddypress()->groups->current_directory_type = reset( $matched_types );
    38         }
    39 
    4024        bp_update_is_directory( true, 'groups' );
    4125
  • trunk/src/bp-groups/classes/class-bp-groups-component.php

    r11360 r11405  
    266266        } else {
    267267            $this->current_group = 0;
     268        }
     269
     270        // Set group type if available.
     271        if ( bp_is_groups_directory() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) {
     272            $matched_types = bp_groups_get_group_types( array(
     273                'has_directory'  => true,
     274                'directory_slug' => bp_action_variable(),
     275            ) );
     276
     277            // Set 404 if we do not have a valid group type.
     278            if ( empty( $matched_types ) ) {
     279                bp_do_404();
     280                return;
     281            }
     282
     283            // Set our directory type marker.
     284            $this->current_directory_type = reset( $matched_types );
    268285        }
    269286
     
    298315
    299316        // If the user was attempting to access a group, but no group by that name was found, 404.
    300         if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() && !in_array( bp_current_action(), $this->forbidden_names ) ) {
     317        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 ) ) {
    301318            bp_do_404();
    302319            return;
  • trunk/tests/phpunit/testcases/routing/groups.php

    r9819 r11405  
    2828        $this->assertTrue( bp_is_user_groups() && bp_is_current_action( 'invites' ) );
    2929    }
     30
     31    /**
     32     * @group group_types
     33     */
     34    public function test_group_directory_with_type() {
     35        bp_groups_register_group_type( 'foo' );
     36        $this->go_to( bp_get_groups_directory_permalink() . 'type/foo/' );
     37        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foo', 0 ) );
     38    }
     39
     40    /**
     41     * @group group_types
     42     */
     43    public function test_group_directory_with_type_that_has_custom_directory_slug() {
     44        bp_groups_register_group_type( 'foo', array( 'has_directory' => 'foos' ) );
     45        $this->go_to( bp_get_groups_directory_permalink() . 'type/foos/' );
     46        $this->assertTrue( bp_is_groups_component() && ! bp_is_group() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_is_action_variable( 'foos', 0 ) );
     47    }
     48
     49    /**
     50     * @group group_types
     51     */
     52    public function test_group_directory_should_404_for_group_types_that_have_no_directory() {
     53        bp_register_member_type( 'foo', array( 'has_directory' => false ) );
     54        $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
     55        $this->assertTrue( is_404() );
     56    }
     57
     58    /**
     59     * @group group_types
     60     */
     61    public function test_group_directory_should_404_for_invalid_group_types() {
     62        $this->go_to( bp_get_members_directory_permalink() . 'type/foo/' );
     63        $this->assertTrue( is_404() );
     64    }
    3065}
Note: See TracChangeset for help on using the changeset viewer.