Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/18/2023 04:11:04 AM (18 months ago)
Author:
imath
Message:

BP Rewrites: optimize the code used to build URLs

The bp_members_get_path_chunks() & bp_groups_get_path_chunks() functions are making sure URL chunks are customized according to the slugs settings. Instead of redoing at many places all or some of the operations performed by these functions, update the code to build URLs so that it uses these functions.

See #4954
Fixes #8923
Closes https://github.com/buddypress/buddypress/pull/117

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-nouveau/includes/activity/functions.php

    r13461 r13503  
    220220            )
    221221        );
    222         $activity_slug = bp_nouveau_get_component_slug( 'activity' );
    223         $path_chunks   = array(
    224             'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
    225         );
     222        $activity_slug    = bp_nouveau_get_component_slug( 'activity' );
    226223
    227224        // If the user has favorite create a nav item
    228225        if ( bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ) ) {
    229             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' );
    230 
    231226            $nav_items['favorites'] = array(
    232227                'component' => 'activity',
    233228                'slug'      => 'favorites', // slug is used because BP_Core_Nav requires it, but it's the scope
    234229                'li_class'  => array(),
    235                 'link'      => bp_loggedin_user_url( $path_chunks ),
     230                'link'      => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, 'favorites' ) ) ),
    236231                'text'      => __( 'My Favorites', 'buddypress' ),
    237232                'count'     => false,
     
    242237        // The friends component is active and user has friends
    243238        if ( bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) {
    244             $friends_slug                      = bp_nouveau_get_component_slug( 'friends' );
    245             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $friends_slug, $friends_slug );
    246 
    247239            $nav_items['friends'] = array(
    248240                'component' => 'activity',
    249241                'slug'      => 'friends', // slug is used because BP_Core_Nav requires it, but it's the scope
    250242                'li_class'  => array( 'dynamic' ),
    251                 'link'      =>  bp_loggedin_user_url( $path_chunks ),
     243                'link'      =>  bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, bp_nouveau_get_component_slug( 'friends' ) ) ) ),
    252244                'text'      => __( 'My Friends', 'buddypress' ),
    253245                'count'     => '',
     
    258250        // The groups component is active and user has groups
    259251        if ( bp_is_active( 'groups' ) && bp_get_total_group_count_for_user( bp_loggedin_user_id() ) ) {
    260             $groups_slug                       = bp_nouveau_get_component_slug( 'groups' );
    261             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $groups_slug, $groups_slug );
    262 
    263252            $nav_items['groups'] = array(
    264253                'component' => 'activity',
    265254                'slug'      => 'groups', // slug is used because BP_Core_Nav requires it, but it's the scope
    266255                'li_class'  => array( 'dynamic' ),
    267                 'link'      => bp_loggedin_user_url( $path_chunks ),
     256                'link'      => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, bp_nouveau_get_component_slug( 'groups' ) ) ) ),
    268257                'text'      => __( 'My Groups', 'buddypress' ),
    269258                'count'     => '',
     
    274263        // Mentions are allowed
    275264        if ( bp_activity_do_mentions() ) {
    276             $deprecated_hooks[]                = array( 'bp_before_activity_type_tab_mentions', 'activity', 36 );
    277             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' );
    278 
    279             $count = '';
     265            $deprecated_hooks[] = array( 'bp_before_activity_type_tab_mentions', 'activity', 36 );
     266            $count              = '';
     267
    280268            if ( bp_get_total_mention_count_for_user( bp_loggedin_user_id() ) ) {
    281269                $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
     
    286274                'slug'      => 'mentions', // slug is used because BP_Core_Nav requires it, but it's the scope
    287275                'li_class'  => array( 'dynamic' ),
    288                 'link'      => bp_loggedin_user_url( $path_chunks ),
     276                'link'      => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, 'mentions' ) ) ),
    289277                'text'      => __( 'Mentions', 'buddypress' ),
    290278                'count'     => $count,
Note: See TracChangeset for help on using the changeset viewer.