Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/24/2018 02:52:25 AM (6 years ago)
Author:
r-a-y
Message:

Navigation: Ensure subnav menus can be registered before the parent nav is registered.

In #7659, a bug was fixed where restricted subnav menus should be
redirected instead of throwing a 404. The side-effect of the fix is this
broke how plugins can register subnav menus before the parent nav is
created.

This commit rectifies the problem by not bailing out if the parent nav
cannot be found during subnav menu registration. Includes a unit-test.

Props dontdream, boonebgorges, r-a-y.

See #7931 (trunk).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/core/nav/bpCoreNewSubnavItem.php

    r11737 r12195  
    336336        $this->assertSame( 'bar', buddypress()->bp_options_nav['parent']['foo']['css_id'] );
    337337    }
     338
     339    /**
     340     * @ticket BP7931
     341     */
     342    public function test_subnav_should_not_404_on_early_bp_setup_nav_priority() {
     343        $u = self::factory()->user->create();
     344        $old_current_user = get_current_user_id();
     345        $this->set_current_user( $u );
     346
     347        $user_domain = bp_core_get_user_domain( $u );
     348
     349        // Register a subnav on 'bp_setup_nav' hook early (at priority zero).
     350        add_action( 'bp_setup_nav', function() use ( $user_domain ) {
     351            /*
     352             * Emulate a subnav screen.
     353             *
     354             * The bp_core_load_template() call is imperative for our 404 check to work!
     355             */
     356            $screen = function() {
     357                bp_core_load_template ('members/single/plugins');
     358            };
     359
     360            // Register the subnav.
     361            bp_core_new_subnav_item( array (
     362                'name'            => 'Testing',
     363                'slug'            => 'testing',
     364                'parent_url'      => $user_domain . bp_get_profile_slug (). '/',
     365                'parent_slug'     => bp_get_profile_slug (),
     366                'screen_function' => $screen,
     367                'position'        => 20
     368            ) );
     369        }, 0 );
     370
     371        // Emulate visit to our new subnav page.
     372        $this->go_to( $user_domain . bp_get_profile_slug () . '/testing/' );
     373
     374        // Assert that subnav page does not 404.
     375        $this->assertFalse( is_404() );
     376
     377        $this->set_current_user( $old_current_user );
     378    }
    338379}
Note: See TracChangeset for help on using the changeset viewer.