Skip to:
Content

BuddyPress.org

Changeset 9701


Ignore:
Timestamp:
04/06/2015 03:19:56 PM (10 years ago)
Author:
boonebgorges
Message:

Don't trailingslash the href of subnav items if the 'link' was provided explicitly in bp_core_new_subnav_item().

trailingslashit() is not smart enough to detect links with query params, so
that links can be improperly trailingslashed in some cases. More generally,
it's not the case that all links should be trailingslashed (in particular,
those that do not lead to WP/BP pages), so plugin authors should be responsible
for trailingslashing on their own.

Props pareshradadiya.
See #6353.

Location:
trunk
Files:
2 edited

Legend:

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

    r9600 r9701  
    297297    // Link was not forced, so create one
    298298    if ( empty( $link ) ) {
    299         $link = $parent_url . $slug;
     299        $link = trailingslashit( $parent_url . $slug );
    300300
    301301        // If this sub item is the default for its parent, skip the slug
    302302        if ( ! empty( $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) && $slug == $bp->bp_nav[$parent_slug]['default_subnav_slug'] ) {
    303             $link = $parent_url;
     303            $link = trailingslashit( $parent_url );
    304304        }
    305305    }
     
    314314    $subnav_item = array(
    315315        'name'              => $name,
    316         'link'              => trailingslashit( $link ),
     316        'link'              => $link,
    317317        'slug'              => $slug,
    318318        'css_id'            => $item_css_id,
  • trunk/tests/phpunit/testcases/core/nav.php

    r9700 r9701  
    382382        $this->assertSame( $expected, buddypress()->bp_options_nav['foo-parent']['bar']['link'] );
    383383    }
     384
     385    /**
     386     * @group bp_core_new_subnav_item
     387     * @ticket BP6353
     388     */
     389    public function test_bp_core_new_subnav_item_link_should_not_trailingslash_link_explicit_link() {
     390        $link = 'http://example.com/foo/bar/blah/?action=edit&id=30';
     391
     392        bp_core_new_subnav_item( array(
     393            'name' => 'bar',
     394            'slug' => 'bar',
     395            'parent_slug' => 'foo',
     396            'parent_url' => 'http://example.com/foo/',
     397            'screen_function' => 'foo',
     398            'link' => $link,
     399        ) );
     400
     401        $this->assertSame( $link, buddypress()->bp_options_nav['foo']['bar']['link'] );
     402    }
    384403}
Note: See TracChangeset for help on using the changeset viewer.