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-nouveau/includes/activity/functions.php

    r12908 r13442  
    44 *
    55 * @since 3.0.0
    6  * @version 8.0.0
     6 * @version 12.0.0
    77 */
    88
     
    8888            'avatar_width'  => $width,
    8989            'avatar_height' => $height,
    90             'user_domain'   => bp_loggedin_user_domain(),
     90            'user_domain'   => bp_loggedin_user_url(),
    9191            'avatar_alt'    => sprintf(
    9292                /* translators: %s: member name */
     
    220220            )
    221221        );
     222        $activity_slug = bp_nouveau_get_component_slug( 'activity' );
     223        $path_chunks   = array(
     224            'single_item_component' => bp_rewrites_get_slug( 'members', 'member_' . $activity_slug, $activity_slug ),
     225        );
    222226
    223227        // If the user has favorite create a nav item
    224228        if ( bp_get_total_favorite_count_for_user( bp_loggedin_user_id() ) ) {
     229            $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_favorites', 'favorites' );
     230
    225231            $nav_items['favorites'] = array(
    226232                'component' => 'activity',
    227233                'slug'      => 'favorites', // slug is used because BP_Core_Nav requires it, but it's the scope
    228234                'li_class'  => array(),
    229                 'link'      => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'activity' ) . '/favorites/',
     235                'link'      => bp_loggedin_user_url( $path_chunks ),
    230236                'text'      => __( 'My Favorites', 'buddypress' ),
    231237                'count'     => false,
     
    236242        // The friends component is active and user has friends
    237243        if ( bp_is_active( 'friends' ) && bp_get_total_friend_count( bp_loggedin_user_id() ) ) {
     244            $friends_slug                      = bp_nouveau_get_component_slug( 'friends' );
     245            $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $friends_slug, $friends_slug );
     246
    238247            $nav_items['friends'] = array(
    239248                'component' => 'activity',
    240249                'slug'      => 'friends', // slug is used because BP_Core_Nav requires it, but it's the scope
    241250                'li_class'  => array( 'dynamic' ),
    242                 'link'      => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'activity' ) . '/' . bp_nouveau_get_component_slug( 'friends' ) . '/',
     251                'link'      =>  bp_loggedin_user_url( $path_chunks ),
    243252                'text'      => __( 'My Friends', 'buddypress' ),
    244253                'count'     => '',
     
    249258        // The groups component is active and user has groups
    250259        if ( bp_is_active( 'groups' ) && bp_get_total_group_count_for_user( bp_loggedin_user_id() ) ) {
     260            $groups_slug                       = bp_nouveau_get_component_slug( 'groups' );
     261            $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_' . $groups_slug, $groups_slug );
     262
    251263            $nav_items['groups'] = array(
    252264                'component' => 'activity',
    253265                'slug'      => 'groups', // slug is used because BP_Core_Nav requires it, but it's the scope
    254266                'li_class'  => array( 'dynamic' ),
    255                 'link'      => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'activity' ) . '/' . bp_nouveau_get_component_slug( 'groups' ) . '/',
     267                'link'      => bp_loggedin_user_url( $path_chunks ),
    256268                'text'      => __( 'My Groups', 'buddypress' ),
    257269                'count'     => '',
     
    262274        // Mentions are allowed
    263275        if ( bp_activity_do_mentions() ) {
    264             $deprecated_hooks[] = array( 'bp_before_activity_type_tab_mentions', 'activity', 36 );
     276            $deprecated_hooks[]                = array( 'bp_before_activity_type_tab_mentions', 'activity', 36 );
     277            $path_chunks['single_item_action'] = bp_rewrites_get_slug( 'members', 'member_' . $activity_slug . '_mentions', 'mentions' );
    265278
    266279            $count = '';
     
    273286                'slug'      => 'mentions', // slug is used because BP_Core_Nav requires it, but it's the scope
    274287                'li_class'  => array( 'dynamic' ),
    275                 'link'      => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'activity' ) . '/mentions/',
     288                'link'      => bp_loggedin_user_url( $path_chunks ),
    276289                'text'      => __( 'Mentions', 'buddypress' ),
    277290                'count'     => $count,
Note: See TracChangeset for help on using the changeset viewer.