Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/18/2023 04:11:04 AM (23 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-members/bp-members-template.php

    r13443 r13503  
    30943094        }
    30953095
    3096         $path_chunks = array(
    3097             'single_item_component' => $bp->{$component}->slug,
    3098         );
    3099 
    3100         // Append $action to $url if there is no $type.
     3096        $path_chunks = array( $bp->{$component}->slug );
     3097
     3098        // Append $action to $url if needed.
    31013099        if ( ! empty( $action ) ) {
    3102             $action_rewrite_id                 = 'member_' . str_replace( '-', '_', $action );
    3103             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', $action_rewrite_id, $action );
    3104         }
    3105 
    3106         // Add a slash at the end of our user url.
     3100            $path_chunks[] = $action;
     3101        }
     3102
     3103        // Check for slugs customization.
     3104        $path_chunks = bp_members_get_path_chunks( $path_chunks );
     3105
     3106        // Generate user url.
    31073107        $url = bp_displayed_user_url( $path_chunks );
    31083108
     
    31473147        $url          = wp_nonce_url(
    31483148            bp_displayed_user_url(
    3149                 array(
    3150                     'single_item_component'        => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug, $profile_slug ),
    3151                     'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $profile_slug . '_change_avatar', 'change-avatar' ),
    3152                     'single_item_action_variables' => array( bp_rewrites_get_slug( 'members', 'member_' . $profile_slug . '_delete_avatar', 'delete-avatar' ) ),
    3153                 )
     3149                bp_members_get_path_chunks( array( $profile_slug, 'change-avatar', array( 'delete-avatar' ) ) )
    31543150            ),
    31553151            'bp_delete_avatar_link'
     
    36793675        $retval = bp_members_get_user_url(
    36803676            (int) $user_id,
    3681             array(
    3682                 'single_item_component' => bp_rewrites_get_slug( 'members', 'member_invitations', bp_get_members_invitations_slug() ),
    3683                 'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_invitations_list_invites', 'list-invites' ),
    3684             )
     3677            bp_members_get_path_chunks( array( bp_get_members_invitations_slug(), 'list-invites' ) )
    36853678        );
    36863679
     
    37213714        $retval = bp_members_get_user_url(
    37223715            (int) $user_id,
    3723             array(
    3724                 'single_item_component' => bp_rewrites_get_slug( 'members', 'member_invitations', bp_get_members_invitations_slug() ),
    3725                 'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_invitations_send_invites', 'send-invites' ),
    3726             )
     3716            bp_members_get_path_chunks( array( bp_get_members_invitations_slug(), 'send-invites' ) )
    37273717        );
    37283718
Note: See TracChangeset for help on using the changeset viewer.