Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/31/2023 05:26:39 PM (18 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-template.php

    r13442 r13443  
    18761876 *
    18771877 * @since 1.2.4
    1878  */
    1879 function bp_displayed_user_link() {
    1880     echo esc_url( bp_displayed_user_url() );
     1878 * @since 12.0.0 Introduced the `$chunk` argument.
     1879 *
     1880 * @param array $chunk A list of slugs to append to the URL.
     1881 */
     1882function bp_displayed_user_link( $chunks = array() ) {
     1883    $path_chunks = array();
     1884    $chunks      = (array) $chunks;
     1885
     1886    if ( $chunks ) {
     1887        $path_chunks = bp_members_get_path_chunks( $chunks );
     1888    }
     1889
     1890    echo esc_url( bp_displayed_user_url( $path_chunks ) );
    18811891}
    18821892
     
    19621972
    19631973    if ( $chunks ) {
    1964         $single_item_component = array_shift( $chunks );
    1965         if ( $single_item_component ) {
    1966             $path_chunks['single_item_component'] = bp_rewrites_get_slug( 'members', 'member_' . $single_item_component, $single_item_component );
    1967         }
    1968 
    1969         $single_item_action = array_shift( $chunks );
    1970         if ( $single_item_action ) {
    1971             $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $single_item_component . '_' . $single_item_action, $single_item_action );
    1972         }
    1973 
    1974         if ( $chunks ) {
    1975             foreach ( $chunks as $chunk ) {
    1976                 $path_chunks['single_item_action_variables'][] = bp_rewrites_get_slug( 'members', 'member_' . $single_item_component . '_' . $single_item_action . '_' . $chunk, $chunk );
    1977             }
    1978         }
     1974        $path_chunks = bp_members_get_path_chunks( $chunks );
    19791975    }
    19801976
     
    30983094        }
    30993095
     3096        $path_chunks = array(
     3097            'single_item_component' => $bp->{$component}->slug,
     3098        );
     3099
    31003100        // Append $action to $url if there is no $type.
    31013101        if ( ! empty( $action ) ) {
    3102             $url = bp_displayed_user_domain() . $bp->{$component}->slug . '/' . $action;
    3103         } else {
    3104             $url = bp_displayed_user_domain() . $bp->{$component}->slug;
     3102            $action_rewrite_id                 = 'member_' . str_replace( '-', '_', $action );
     3103            $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', $action_rewrite_id, $action );
    31053104        }
    31063105
    31073106        // Add a slash at the end of our user url.
    3108         $url = trailingslashit( $url );
     3107        $url = bp_displayed_user_url( $path_chunks );
    31093108
    31103109        // Add possible query arg.
     
    31453144     */
    31463145    function bp_get_avatar_delete_link() {
     3146        $profile_slug = bp_get_profile_slug();
     3147        $url          = wp_nonce_url(
     3148            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                )
     3154            ),
     3155            'bp_delete_avatar_link'
     3156        );
    31473157
    31483158        /**
     
    31513161         * @since 1.1.0
    31523162         *
    3153          * @param string $value Nonced URL used for deleting an avatar.
    3154          */
    3155         return apply_filters( 'bp_get_avatar_delete_link', wp_nonce_url( bp_displayed_user_domain() . bp_get_profile_slug() . '/change-avatar/delete-avatar/', 'bp_delete_avatar_link' ) );
     3163         * @param string $url Nonced URL used for deleting an avatar.
     3164         */
     3165        return apply_filters( 'bp_get_avatar_delete_link', $url );
    31563166    }
    31573167
Note: See TracChangeset for help on using the changeset viewer.