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-messages/classes/class-bp-messages-component.php

    r13495 r13503  
    310310        // Menus for logged in user.
    311311        if ( is_user_logged_in() ) {
    312             $message_slug        = bp_get_messages_slug();
    313             $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     312            $message_slug = bp_get_messages_slug();
    314313
    315314            // Unread message count.
     
    336335                'id'     => 'my-account-' . $this->id,
    337336                'title'  => $title,
    338                 'href'   => bp_loggedin_user_url(
    339                     array(
    340                         'single_item_component' => $custom_message_slug,
    341                     )
    342                 ),
     337                'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug ) ) ),
    343338            );
    344339
     
    348343                'id'       => 'my-account-' . $this->id . '-inbox',
    349344                'title'    => $inbox,
    350                 'href'     => bp_loggedin_user_url(
    351                     array(
    352                         'single_item_component' => $custom_message_slug,
    353                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_inbox', 'inbox' ),
    354                     )
    355                 ),
     345                'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug, 'inbox' ) ) ),
    356346                'position' => 10,
    357347            );
     
    359349            // Starred.
    360350            if ( bp_is_active( $this->id, 'star' ) ) {
    361                 $star_slug      = bp_get_messages_starred_slug();
    362351                $wp_admin_nav[] = array(
    363352                    'parent'   => 'my-account-' . $this->id,
    364353                    'id'       => 'my-account-' . $this->id . '-starred',
    365354                    'title'    => __( 'Starred', 'buddypress' ),
    366                     'href'     => bp_loggedin_user_url(
    367                         array(
    368                             'single_item_component' => $custom_message_slug,
    369                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_' . $star_slug, $star_slug ),
    370                         )
    371                     ),
     355                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug, bp_get_messages_starred_slug() ) ) ),
    372356                    'position' => 11,
    373357                );
     
    379363                'id'       => 'my-account-' . $this->id . '-sentbox',
    380364                'title'    => __( 'Sent', 'buddypress' ),
    381                 'href'     => bp_loggedin_user_url(
    382                     array(
    383                         'single_item_component' => $custom_message_slug,
    384                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_sentbox', 'sentbox' ),
    385                     )
    386                 ),
     365                'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug, 'sentbox' ) ) ),
    387366                'position' => 20,
    388367            );
     
    393372                'id'       => 'my-account-' . $this->id . '-compose',
    394373                'title'    => __( 'Compose', 'buddypress' ),
    395                 'href'     => bp_loggedin_user_url(
    396                     array(
    397                         'single_item_component' => $custom_message_slug,
    398                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_compose', 'compose' ),
    399                     )
    400                 ),
     374                'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug, 'compose' ) ) ),
    401375                'position' => 30,
    402376            );
     
    408382                    'id'       => 'my-account-' . $this->id . '-notices',
    409383                    'title'    => __( 'Site Notices', 'buddypress' ),
    410                     'href'     => bp_loggedin_user_url(
    411                         array(
    412                             'single_item_component' => $custom_message_slug,
    413                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_notices', 'notices' ),
    414                         )
    415                     ),
     384                    'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $message_slug, 'notices' ) ) ),
    416385                    'position' => 90,
    417386                );
Note: See TracChangeset for help on using the changeset viewer.