Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/23/2023 07:35:38 PM (18 months ago)
Author:
imath
Message:

Make BP_Core_Nav generate "BP Rewrites ready" navigation links

  • Remove all components $parent_url attributes when setting sub nav items.
  • Only use the bp_core_create_nav_link() $link attribute argument & the bp_core_create_subnav_link() $parent_url attribute argument if specified to preserve backward compatibility.
  • Migrates the Community search feature so that it uses BP Rewrites.
  • Perform some bp_loggedin_user_domain() in favor of bp_loggedin_user_url().
  • Update some PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/77
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r13432 r13441  
    162162    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    163163
    164         // Determine user to use.
    165         if ( bp_displayed_user_domain() ) {
    166             $user_domain = bp_displayed_user_domain();
    167         } elseif ( bp_loggedin_user_domain() ) {
    168             $user_domain = bp_loggedin_user_domain();
    169         } else {
     164        // Stop if there is no user displayed or logged in.
     165        if ( ! is_user_logged_in() && ! bp_displayed_user_id() ) {
    170166            return;
    171167        }
    172168
    173         $access       = bp_core_can_edit_settings();
    174         $slug         = bp_get_friends_slug();
    175         $friends_link = trailingslashit( $user_domain . $slug );
     169        $access = bp_core_can_edit_settings();
     170        $slug   = bp_get_friends_slug();
    176171
    177172        // Add 'Friends' to the main navigation.
     
    202197            'name'            => _x( 'Friendships', 'Friends screen sub nav', 'buddypress' ),
    203198            'slug'            => 'my-friends',
    204             'parent_url'      => $friends_link,
    205199            'parent_slug'     => $slug,
    206200            'screen_function' => 'friends_screen_my_friends',
     
    212206            'name'            => _x( 'Requests', 'Friends screen sub nav', 'buddypress' ),
    213207            'slug'            => 'requests',
    214             'parent_url'      => $friends_link,
    215208            'parent_slug'     => $slug,
    216209            'screen_function' => 'friends_screen_requests',
     
    238231
    239232            // Setup the logged in user variables.
    240             $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );
     233            $friends_slug        = bp_get_friends_slug();
     234            $custom_friends_slug = bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug );
    241235
    242236            // Pending friend requests.
     
    263257                'id'     => 'my-account-' . $this->id,
    264258                'title'  => $title,
    265                 'href'   => $friends_link,
     259                'href'   => bp_loggedin_user_url(
     260                    array(
     261                        'single_item_component' => $custom_friends_slug,
     262                    )
     263                ),
    266264            );
    267265
     
    271269                'id'       => 'my-account-' . $this->id . '-friendships',
    272270                'title'    => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ),
    273                 'href'     => trailingslashit( $friends_link . 'my-friends' ),
     271                'href'     => bp_loggedin_user_url(
     272                    array(
     273                        'single_item_component' => $custom_friends_slug,
     274                        'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_my_friends', 'my-friends' ),
     275                    )
     276                ),
    274277                'position' => 10,
    275278            );
     
    280283                'id'       => 'my-account-' . $this->id . '-requests',
    281284                'title'    => $pending,
    282                 'href'     => trailingslashit( $friends_link . 'requests' ),
     285                'href'     => bp_loggedin_user_url(
     286                    array(
     287                        'single_item_component' => $custom_friends_slug,
     288                        'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
     289                    )
     290                ),
    283291                'position' => 20,
    284292            );
Note: See TracChangeset for help on using the changeset viewer.