Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/18/2023 04:11:04 AM (2 years 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-activity/classes/class-bp-activity-component.php

    r13495 r13503  
    336336
    337337            // Setup the logged in user variables.
    338             $activity_slug        = bp_get_activity_slug();
    339             $custom_activity_slug = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug );
     338            $activity_slug = bp_get_activity_slug();
    340339
    341340            // Unread message count.
    342341            if ( bp_activity_do_mentions() ) {
    343342                $count = bp_get_total_mention_count_for_user( bp_loggedin_user_id() );
    344                 if ( !empty( $count ) ) {
     343                if ( ! empty( $count ) ) {
    345344                    $title = sprintf(
    346345                        /* translators: %s: Unread mention count for the current user */
     
    358357                'id'     => 'my-account-' . $this->id,
    359358                'title'  => _x( 'Activity', 'My Account Activity sub nav', 'buddypress' ),
    360                 'href'   => bp_loggedin_user_url(
    361                     array(
    362                         'single_item_component' => $custom_activity_slug,
    363                     )
    364                 ),
     359                'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug ) ) ),
    365360            );
    366361
     
    370365                'id'       => 'my-account-' . $this->id . '-personal',
    371366                'title'    => _x( 'Personal', 'My Account Activity sub nav', 'buddypress' ),
    372                 'href'     => bp_loggedin_user_url(
    373                     array(
    374                         'single_item_component' => $custom_activity_slug,
    375                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_just_me', 'just-me' ),
    376                     )
    377                 ),
     367                'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, 'just-me' ) ) ),
    378368                'position' => 10,
    379369            );
     
    385375                    'id'       => 'my-account-' . $this->id . '-mentions',
    386376                    'title'    => $title,
    387                     'href'     => bp_loggedin_user_url(
    388                         array(
    389                             'single_item_component' => $custom_activity_slug,
    390                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' ),
    391                         )
    392                     ),
     377                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, 'mentions' ) ) ),
    393378                    'position' => 20,
    394379                );
     
    401386                    'id'       => 'my-account-' . $this->id . '-favorites',
    402387                    'title'    => _x( 'Favorites', 'My Account Activity sub nav', 'buddypress' ),
    403                     'href'     => bp_loggedin_user_url(
    404                         array(
    405                             'single_item_component' => $custom_activity_slug,
    406                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' ),
    407                         )
    408                     ),
     388                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, 'favorites' ) ) ),
    409389                    'position' => 30,
    410390                );
     
    413393            // Friends?
    414394            if ( bp_is_active( 'friends' ) ) {
    415                 $friends_slug   = bp_get_friends_slug();
    416395                $wp_admin_nav[] = array(
    417396                    'parent'   => 'my-account-' . $this->id,
    418397                    'id'       => 'my-account-' . $this->id . '-friends',
    419398                    'title'    => _x( 'Friends', 'My Account Activity sub nav', 'buddypress' ),
    420                     'href'     => bp_loggedin_user_url(
    421                         array(
    422                             'single_item_component' => $custom_activity_slug,
    423                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $friends_slug, $friends_slug ),
    424                         )
    425                     ),
     399                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, bp_get_friends_slug() ) ) ),
    426400                    'position' => 40,
    427401                );
     
    430404            // Groups?
    431405            if ( bp_is_active( 'groups' ) ) {
    432                 $groups_slug    = bp_get_groups_slug();
    433406                $wp_admin_nav[] = array(
    434407                    'parent'   => 'my-account-' . $this->id,
    435408                    'id'       => 'my-account-' . $this->id . '-groups',
    436409                    'title'    => _x( 'Groups', 'My Account Activity sub nav', 'buddypress' ),
    437                     'href'     => bp_loggedin_user_url(
    438                         array(
    439                             'single_item_component' => $custom_activity_slug,
    440                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $groups_slug, $groups_slug ),
    441                         )
    442                     ),
     410                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $activity_slug, bp_get_groups_slug() ) ) ),
    443411                    'position' => 50
    444412                );
Note: See TracChangeset for help on using the changeset viewer.