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-templates/bp-legacy/buddypress-functions.php

    r13493 r13503  
    915915        }
    916916
    917         $activity_slug        = bp_get_activity_slug();
    918         $custom_activity_slug = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug );
    919 
    920917        // We need to calculate and return the feed URL for each scope.
    921918        switch ( $scope ) {
    922919                case 'friends':
    923                         $feed_url = bp_loggedin_user_url(
    924                                 array(
    925                                         'single_item_component'        => $custom_activity_slug,
    926                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_friends', 'friends' ),
    927                                         'single_item_action_variables' => array( 'feed' ),
    928                                 )
    929                         );
     920                        $feed_url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_activity_slug(), 'friends', array( 'feed' ) ) ) );
    930921                        break;
    931922                case 'groups':
    932                         $feed_url = bp_loggedin_user_url(
    933                                 array(
    934                                         'single_item_component'        => $custom_activity_slug,
    935                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_groups', 'groups' ),
    936                                         'single_item_action_variables' => array( 'feed' ),
    937                                 )
    938                         );
     923                        $feed_url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_activity_slug(), 'groups', array( 'feed' ) ) ) );
    939924                        break;
    940925                case 'favorites':
    941                         $feed_url = bp_loggedin_user_url(
    942                                 array(
    943                                         'single_item_component'        => $custom_activity_slug,
    944                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' ),
    945                                         'single_item_action_variables' => array( 'feed' ),
    946                                 )
    947                         );
     926                        $feed_url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_activity_slug(), 'favorites', array( 'feed' ) ) ) );
    948927                        break;
    949928                case 'mentions':
    950                         $feed_url = bp_loggedin_user_url(
    951                                 array(
    952                                         'single_item_component'        => $custom_activity_slug,
    953                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' ),
    954                                         'single_item_action_variables' => array( 'feed' ),
    955                                 )
    956                         );
     929                        $feed_url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_activity_slug(), 'mentions', array( 'feed' ) ) ) );
    957930
    958931                        if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) {
     
    14921465        }
    14931466
    1494         $friends_slug        = bp_get_friends_slug();
    1495         $custom_friends_slug = bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug );
    1496 
    14971467        // Trying to cancel friendship.
    14981468        if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
     
    15021472                        echo __( 'Friendship could not be canceled.', 'buddypress' );
    15031473                } else {
    1504                         $url = bp_loggedin_user_url(
    1505                                 array(
    1506                                         'single_item_component'        => $custom_friends_slug,
    1507                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_add_friend', 'add-friend' ),
    1508                                         'single_item_action_variables' => array( $friend_id ),
    1509                                 )
    1510                         );
     1474                        $url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_friends_slug(), 'add-friend', array( $friend_id ) ) ) );
    15111475                        echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( $url, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    15121476                }
     
    15191483                        echo __(' Friendship could not be requested.', 'buddypress' );
    15201484                } else {
    1521                         $url = bp_loggedin_user_url(
    1522                                 array(
    1523                                         'single_item_component'        => $custom_friends_slug,
    1524                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
    1525                                         'single_item_action_variables' => array(
    1526                                                 bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests_cancel', 'cancel' ),
    1527                                                 $friend_id,
    1528                                         ),
    1529                                 )
    1530                         );
     1485                        $url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_friends_slug(), 'requests', array( 'cancel', $friend_id ) ) ) );
    15311486                        echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="remove friendship-button pending_friend requested" rel="remove" href="' . wp_nonce_url( $url, 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
    15321487                }
     
    15371492
    15381493                if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
    1539                         $url = bp_loggedin_user_url(
    1540                                 array(
    1541                                         'single_item_component'        => $custom_friends_slug,
    1542                                         'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_add_friend', 'add-friend' ),
    1543                                         'single_item_action_variables' => array(
    1544                                                 $friend_id,
    1545                                         ),
    1546                                 )
    1547                         );
     1494                        $url = bp_loggedin_user_url( bp_members_get_path_chunks( array( bp_get_friends_slug(), 'add-friend', array( $friend_id ) ) ) );
    15481495                        echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( $url, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    15491496                } else {
Note: See TracChangeset for help on using the changeset viewer.