Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/31/2023 05:26:39 PM (20 months ago)
Author:
imath
Message:

Make sure all displayed user URLs are built using the BP Rewrites API

Replace all remaining bp_displayed_user_domain() usage in favor of
bp_displayed_user_url().
Introduce the bp_members_get_path_chunks() function to quickly build BP
Rewrites argument for member's URL using an array of slugs.
Deprecate bp_activities_member_rss_link(), bp_blogs_blog_tabs() &
bp_groups_header_tabs().
Improve bp_displayed_user_link() so that it's possible to pass an array
of slugs to output an escaped BP Rewrites ready URL.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r13436 r13443  
    137137     */
    138138    return apply_filters( 'bp_core_get_users', $retval, $r );
     139}
     140
     141/**
     142 * Get members path chunks using an array of URL slugs.
     143 *
     144 * @since 12.0.0
     145 *
     146 * @param array $chunks An array of URL slugs.
     147 * @return array An array of BP Rewrites URL arguments.
     148 */
     149function bp_members_get_path_chunks( $chunks = array() ) {
     150    $path_chunks = array();
     151
     152    $single_item_component            = array_shift( $chunks );
     153    $item_component_rewrite_id_suffix = '';
     154    if ( $single_item_component ) {
     155        $item_component_rewrite_id_suffix     = str_replace( '-', '_', $single_item_component );
     156        $path_chunks['single_item_component'] = bp_rewrites_get_slug( 'members', 'member_' . $item_component_rewrite_id_suffix, $single_item_component );
     157    }
     158
     159    $single_item_action            = array_shift( $chunks );
     160    $item_action_rewrite_id_suffix = '';
     161    if ( $single_item_action ) {
     162        $item_action_rewrite_id_suffix     = str_replace( '-', '_', $single_item_action );
     163        $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $item_component_rewrite_id_suffix . '_' . $item_action_rewrite_id_suffix, $single_item_action );
     164    }
     165
     166    if ( $chunks && $item_component_rewrite_id_suffix && $item_component_rewrite_id_suffix ) {
     167        foreach ( $chunks as $chunk ) {
     168            $item_action_variable_rewrite_id_suffix        =  str_replace( '-', '_', $chunk );
     169            $path_chunks['single_item_action_variables'][] = bp_rewrites_get_slug( 'members', 'member_' . $item_component_rewrite_id_suffix . '_' . $item_action_rewrite_id_suffix . '_' . $item_action_variable_rewrite_id_suffix, $chunk );
     170        }
     171    }
     172
     173    return $path_chunks;
    139174}
    140175
Note: See TracChangeset for help on using the changeset viewer.