Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/27/2023 06:19:06 PM (13 months ago)
Author:
imath
Message:

Improve Components Member's single item navigation generation

  • Edit the BP_Component Class so that it globalize navigation items before registering it.
  • Introduce bp_get_component_navigations(), a new function that will be used to get Member's single navigation customizable slugs within the BuddyPress settings area.
  • Perform all remaining bp_loggedin_user_domain() replacements (55) in favor of the bp_loggedin_user_url() function which uses BP Rewrites to build URLs.
  • Improve bp_loggedin_user_link() by adding a new $chunks array of arguments to output escaped URL in templates.
  • Adapt some PHPUnit testcases.

Props r-a-y, johnjamesjacoby, boonebgorges

Closes https://github.com/buddypress/buddypress/pull/78
See #4954

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r13437 r13442  
    77 * @package BuddyPress
    88 * @subpackage BP_Theme_Compat
    9  * @version 10.0.0
     9 * @version 12.0.0
    1010 */
    1111
     
    908908
    909909    $scope = '';
    910     if ( ! empty( $_POST['scope'] ) )
     910    if ( ! empty( $_POST['scope'] ) ) {
    911911        $scope = $_POST['scope'];
     912    }
     913
     914    $activity_slug        = bp_get_activity_slug();
     915    $custom_activity_slug = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug );
    912916
    913917    // We need to calculate and return the feed URL for each scope.
    914918    switch ( $scope ) {
    915919        case 'friends':
    916             $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/friends/feed/';
     920            $feed_url = bp_loggedin_user_url(
     921                array(
     922                    'single_item_component'        => $custom_activity_slug,
     923                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_friends', 'friends' ),
     924                    'single_item_action_variables' => array( 'feed' ),
     925                )
     926            );
    917927            break;
    918928        case 'groups':
    919             $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/';
     929            $feed_url = bp_loggedin_user_url(
     930                array(
     931                    'single_item_component'        => $custom_activity_slug,
     932                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_groups', 'groups' ),
     933                    'single_item_action_variables' => array( 'feed' ),
     934                )
     935            );
    920936            break;
    921937        case 'favorites':
    922             $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
     938            $feed_url = bp_loggedin_user_url(
     939                array(
     940                    'single_item_component'        => $custom_activity_slug,
     941                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' ),
     942                    'single_item_action_variables' => array( 'feed' ),
     943                )
     944            );
    923945            break;
    924946        case 'mentions':
    925             $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
     947            $feed_url = bp_loggedin_user_url(
     948                array(
     949                    'single_item_component'        => $custom_activity_slug,
     950                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' ),
     951                    'single_item_action_variables' => array( 'feed' ),
     952                )
     953            );
    926954
    927955            if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) {
     
    14541482    }
    14551483
     1484    $friends_slug        = bp_get_friends_slug();
     1485    $custom_friends_slug = bp_rewrites_get_slug( 'members', 'member_' . $friends_slug, $friends_slug );
     1486
    14561487    // Trying to cancel friendship.
    14571488    if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
     
    14611492            echo __( 'Friendship could not be canceled.', 'buddypress' );
    14621493        } else {
    1463             echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
     1494            $url = bp_loggedin_user_url(
     1495                array(
     1496                    'single_item_component'        => $custom_friends_slug,
     1497                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_add_friend', 'add-friend' ),
     1498                    'single_item_action_variables' => array( $friend_id ),
     1499                )
     1500            );
     1501            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>';
    14641502        }
    14651503
     
    14711509            echo __(' Friendship could not be requested.', 'buddypress' );
    14721510        } else {
    1473             echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="remove friendship-button pending_friend requested" rel="remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $friend_id . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
     1511            $url = bp_loggedin_user_url(
     1512                array(
     1513                    'single_item_component'        => $custom_friends_slug,
     1514                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests', 'requests' ),
     1515                    'single_item_action_variables' => array(
     1516                        bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_requests_cancel', 'cancel' ),
     1517                        $friend_id,
     1518                    ),
     1519                )
     1520            );
     1521            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>';
    14741522        }
    14751523
     
    14791527
    14801528        if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
    1481             echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
     1529            $url = bp_loggedin_user_url(
     1530                array(
     1531                    'single_item_component'        => $custom_friends_slug,
     1532                    'single_item_action'           => bp_rewrites_get_slug( 'members', 'member_' . $friends_slug . '_add_friend', 'add-friend' ),
     1533                    'single_item_action_variables' => array(
     1534                        $friend_id,
     1535                    ),
     1536                )
     1537            );
     1538            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>';
    14821539        } else {
    14831540            echo __("Friendship request could not be cancelled.", 'buddypress');
Note: See TracChangeset for help on using the changeset viewer.