Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/16/2023 03:43:26 PM (9 months ago)
Author:
imath
Message:

Make sure bp_core_new_nav_default() is ready for the BP Rewrites API

  • In case plain permalinks are used, use the $GLOBALS['wp']->query_string to set the buddypress()->unfiltered_uri global.
  • Do not edit sub nav links when calling bp_core_new_nav_default() if the URL parser is set to 'rewrites'.
  • Avoid a PHP notice if the new sub nav object misses the slug and/or the link properties.

Props corzel

See #4954
Fixes #8936
Closes https://github.com/buddypress/buddypress/pull/130

File:
1 edited

Legend:

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

    r13507 r13519  
    344344    );
    345345
    346     /**
    347      * Update secondary nav items:
    348      * - The previous default nav item needs to have its slug added to its link property.
    349      * - The new default nav item needs to have its slug removed from its link property.
    350      */
    351     $previous_default_subnav = $bp->members->nav->get( $parent_nav->slug . '/' . $parent_nav->default_subnav_slug );
    352 
    353     // Edit the link of the previous default nav item.
    354     $bp->members->nav->edit_nav(
    355         array(
    356             'link' => trailingslashit( $previous_default_subnav->link . $previous_default_subnav->slug ),
    357         ),
    358         $previous_default_subnav->slug,
    359         $parent_nav->slug
    360     );
    361 
    362     $new_default_subnav = $bp->members->nav->get( $parent_nav->slug . '/' . $r['subnav_slug'] );
    363 
    364     // Edit the link of the new default nav item.
    365     $bp->members->nav->edit_nav(
    366         array(
    367             'link' => rtrim( untrailingslashit( $new_default_subnav->link ), $new_default_subnav->slug ),
    368         ),
    369         $new_default_subnav->slug,
    370         $parent_nav->slug
    371     );
     346    // Only edit old & new default subnavs when using the Legacy URL parser.
     347    if ( 'rewrites' !== bp_core_get_query_parser() ) {
     348        /**
     349         * Update secondary nav items:
     350         * - The previous default nav item needs to have its slug added to its link property.
     351         * - The new default nav item needs to have its slug removed from its link property.
     352         */
     353        $previous_default_subnav = $bp->members->nav->get( $parent_nav->slug . '/' . $parent_nav->default_subnav_slug );
     354
     355        // Edit the link of the previous default nav item.
     356        $bp->members->nav->edit_nav(
     357            array(
     358                'link' => trailingslashit( $previous_default_subnav->link . $previous_default_subnav->slug ),
     359            ),
     360            $previous_default_subnav->slug,
     361            $parent_nav->slug
     362        );
     363
     364        $new_default_subnav = $bp->members->nav->get( $parent_nav->slug . '/' . $r['subnav_slug'] );
     365
     366        // Make sure the `$new_default_subnav` properties are set.
     367        if ( isset( $new_default_subnav->link, $new_default_subnav->slug ) ) {
     368            // Edit the link of the new default nav item.
     369            $bp->members->nav->edit_nav(
     370                array(
     371                    'link' => rtrim( untrailingslashit( $new_default_subnav->link ), $new_default_subnav->slug ),
     372                ),
     373                $new_default_subnav->slug,
     374                $parent_nav->slug
     375            );
     376        }
     377    }
    372378
    373379    if ( bp_is_current_component( $parent_nav->slug ) ) {
Note: See TracChangeset for help on using the changeset viewer.