Skip to:
Content

BuddyPress.org

Changeset 10212


Ignore:
Timestamp:
10/08/2015 04:52:31 AM (11 years ago)
Author:
r-a-y
Message:

URI: Allow root profiles to work when the 'Members' page is nested.

Previously, if the Members page was nested as a child of another page, the
root profiles feature - define( 'BP_ENABLE_ROOT_PROFILES', true ); - did
not work. This commit fixes this and includes a unit test.

Commit also adds a minor performance tweak when a root profile is detected.

Props r-a-y, boonebgorges.

Fixes #6477.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-catchuri.php

    r10110 r10212  
    241241        // Rejig the offset
    242242        if ( !empty( $slug ) && ( 1 < count( $slug ) ) ) {
    243                 array_pop( $slug );
    244                 $uri_offset = count( $slug );
     243                // Only offset if not on a root profile. Fixes issue when Members page is nested.
     244                if ( false === $root_profile ) {
     245                        array_pop( $slug );
     246                        $uri_offset = count( $slug );
     247                }
    245248        }
    246249
     
    265268                        // Are we viewing a specific user?
    266269                        if ( $after_member_slug ) {
     270                                // If root profile, we've already queried for the user
     271                                if ( $root_profile instanceof WP_User ) {
     272                                        $bp->displayed_user->id = $root_profile->ID;
     273
    267274                                // Switch the displayed_user based on compatibility mode
    268                                 if ( bp_is_username_compatibility_mode() ) {
     275                                } elseif ( bp_is_username_compatibility_mode() ) {
    269276                                        $bp->displayed_user->id = (int) bp_core_get_userid( urldecode( $after_member_slug ) );
     277
    270278                                } else {
    271279                                        $bp->displayed_user->id = (int) bp_core_get_userid_from_nicename( $after_member_slug );
  • trunk/tests/phpunit/testcases/routing/root-profiles.php

    r9819 r10212  
    4343        }
    4444
     45        /**
     46         * @ticket BP6475
     47         */
     48        public function test_member_permalink_when_members_page_is_nested_under_wp_page() {
     49                $p = $this->factory->post->create( array(
     50                        'post_type' => 'page',
     51                        'post_name' => 'foo',
     52                ) );
     53
     54                $members_page = get_page_by_path( 'members' );
     55                wp_update_post( array(
     56                        'ID' => $members_page->ID,
     57                        'post_parent' => $p,
     58                ) );
     59
     60                $domain = home_url( $this->u->user_nicename );
     61                $this->go_to( $domain );
     62
     63                $this->assertTrue( bp_is_user() );
     64                $this->assertTrue( bp_is_my_profile() );
     65                $this->assertEquals( $this->u->ID, bp_displayed_user_id() );
     66        }
     67
    4568        public function test_member_activity_page() {
    4669                $url = home_url( $this->u->user_nicename ) . '/' . bp_get_activity_slug();
Note: See TracChangeset for help on using the changeset viewer.