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-friends/bp-friends-template.php

    r13493 r13503  
    222222
    223223        $friendship_status = bp_is_friend( $potential_friend_id );
    224         $friends_slug        = bp_get_friends_slug();
    225         $custom_friends_slug = bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug );
     224        $friends_slug      = bp_get_friends_slug();
    226225
    227226        if ( empty( $friendship_status ) ) {
     
    239238                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    240239                    'link_href'         => wp_nonce_url(
    241                         bp_loggedin_user_url(
    242                             array(
    243                                 'single_item_component'        => $custom_friends_slug,
    244                                 'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
    245                                 'single_item_action_variables' => array( bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests_cancel', 'cancel' ), $potential_friend_id ),
    246                             )
    247                         ),
     240                        bp_loggedin_user_url( bp_members_get_path_chunks( array( $friends_slug, 'requests', array( 'cancel', $potential_friend_id ) ) ) ),
    248241                        'friends_withdraw_friendship'
    249242                    ),
     
    264257                    'wrapper_class'     => 'friendship-button awaiting_response_friend',
    265258                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    266                     'link_href'         => bp_loggedin_user_url(
    267                         array(
    268                             'single_item_component' => $custom_friends_slug,
    269                             'single_item_action'    => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
    270                         )
    271                     ),
     259                    'link_href'         => bp_loggedin_user_url( bp_members_get_path_chunks( array( $friends_slug, 'requests' ) ) ),
    272260                    'link_text'         => __( 'Friendship Requested', 'buddypress' ),
    273261                    'link_title'        => __( 'Friendship Requested', 'buddypress' ),
     
    287275                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    288276                    'link_href'         => wp_nonce_url(
    289                         bp_loggedin_user_url(
    290                             array(
    291                                 'single_item_component'        => $custom_friends_slug,
    292                                 'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_remove_friend', 'remove-friend' ),
    293                                 'single_item_action_variables' => array( $potential_friend_id ),
    294                             )
    295                         ),
     277                        bp_loggedin_user_url( bp_members_get_path_chunks( array( $friends_slug, 'remove-friend', array( $potential_friend_id ) ) ) ),
    296278                        'friends_remove_friend'
    297279                    ),
     
    313295                    'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    314296                    'link_href'         => wp_nonce_url(
    315                         bp_loggedin_user_url(
    316                             array(
    317                                 'single_item_component'        => $custom_friends_slug,
    318                                 'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_add_friend', 'add-friend' ),
    319                                 'single_item_action_variables' => array( $potential_friend_id ),
    320                             )
    321                         ),
     297                        bp_loggedin_user_url( bp_members_get_path_chunks( array( $friends_slug, 'add-friend', array( $potential_friend_id ) ) ) ),
    322298                        'friends_add_friend'
    323299                    ),
     
    488464        }
    489465
    490         $friends_slug = bp_get_friends_slug();
    491         $url          = wp_nonce_url(
    492             bp_loggedin_user_url(
    493                 array(
    494                     'single_item_component'        => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug ),
    495                     'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
    496                     'single_item_action_variables' => array( bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests_accept', 'accept' ), $friendship_id ),
    497                 )
    498             ),
     466        $url = wp_nonce_url(
     467            bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_friends_slug(), 'requests', array( 'accept', $friendship_id ) ) ) ),
    499468            'friends_accept_friendship'
    500469        );
     
    537506        }
    538507
    539         $friends_slug = bp_get_friends_slug();
    540         $url          = wp_nonce_url(
    541             bp_loggedin_user_url(
    542                 array(
    543                     'single_item_component'        => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug ),
    544                     'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
    545                     'single_item_action_variables' => array( bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests_reject', 'reject' ), $friendship_id ),
    546                 )
    547             ),
     508        $url = wp_nonce_url(
     509            bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_friends_slug(), 'requests', array( 'reject', $friendship_id ) ) ) ),
    548510            'friends_reject_friendship'
    549511        );
Note: See TracChangeset for help on using the changeset viewer.