Skip to:
Content

BuddyPress.org


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

    r13495 r13503  
    240240                // Menus for logged in user.
    241241                if ( is_user_logged_in() ) {
    242                         $settings_slug        = bp_get_settings_slug();
    243                         $custom_settings_slug = bp_rewrites_get_slug( 'members', 'member_' . $settings_slug, $settings_slug );
     242                        $settings_slug = bp_get_settings_slug();
    244243
    245244                        // Add main Settings menu.
     
    248247                                'id'     => 'my-account-' . $this->id,
    249248                                'title'  => __( 'Settings', 'buddypress' ),
    250                                 'href'   => bp_loggedin_user_url(
    251                                         array(
    252                                                 'single_item_component' => $custom_settings_slug,
    253                                         )
    254                                 ),
     249                                'href'   => bp_loggedin_user_url( bp_members_get_path_chunks( array( $settings_slug ) ) ),
    255250                        );
    256251
     
    260255                                'id'       => 'my-account-' . $this->id . '-general',
    261256                                'title'    => __( 'General', 'buddypress' ),
    262                                 'href'     => bp_loggedin_user_url(
    263                                         array(
    264                                                 'single_item_component' => $custom_settings_slug,
    265                                                 'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $settings_slug . '_general', 'general' ),
    266                                         )
    267                                 ),
     257                                'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $settings_slug, 'general' ) ) ),
    268258                                'position' => 10,
    269259                        );
     
    275265                                        'id'       => 'my-account-' . $this->id . '-notifications',
    276266                                        'title'    => __( 'Email', 'buddypress' ),
    277                                         'href'     => bp_loggedin_user_url(
    278                                                 array(
    279                                                         'single_item_component' => $custom_settings_slug,
    280                                                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $settings_slug . '_notifications', 'notifications' ),
    281                                                 )
    282                                         ),
     267                                        'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $settings_slug, 'notifications' ) ) ),
    283268                                        'position' => 20,
    284269                                );
     
    294279                                        'id'       => 'my-account-' . $this->id . '-data',
    295280                                        'title'    => __( 'Export Data', 'buddypress' ),
    296                                         'href'     => bp_loggedin_user_url(
    297                                                 array(
    298                                                         'single_item_component' => $custom_settings_slug,
    299                                                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $settings_slug . '_data', 'data' ),
    300                                                 )
    301                                         ),
     281                                        'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $settings_slug, 'data' ) ) ),
    302282                                        'position' => 89,
    303283                                );
     
    305285
    306286                        // Delete Account
    307                         if ( !bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
     287                        if ( ! bp_current_user_can( 'bp_moderate' ) && ! bp_core_get_root_option( 'bp-disable-account-deletion' ) ) {
    308288                                $wp_admin_nav[] = array(
    309289                                        'parent'   => 'my-account-' . $this->id,
    310290                                        'id'       => 'my-account-' . $this->id . '-delete-account',
    311291                                        'title'    => __( 'Delete Account', 'buddypress' ),
    312                                         'href'     => bp_loggedin_user_url(
    313                                                 array(
    314                                                         'single_item_component' => $custom_settings_slug,
    315                                                         'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $settings_slug . '_delete_account', 'delete-account' ),
    316                                                 )
    317                                         ),
     292                                        'href'     => bp_loggedin_user_url( bp_members_get_path_chunks( array( $settings_slug, 'delete-account' ) ) ),
    318293                                        'position' => 90,
    319294                                );
Note: See TracChangeset for help on using the changeset viewer.