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-messages/bp-messages-star.php

    r13433 r13442  
    114114        );
    115115
    116         // Check user ID and determine base user URL.
    117         switch ( $r['user_id'] ) {
    118 
    119             // Current user.
    120             case bp_loggedin_user_id() :
    121                 $user_domain = bp_loggedin_user_domain();
    122                 break;
    123 
    124             // Displayed user.
    125             case bp_displayed_user_id() :
    126                 $user_domain = bp_displayed_user_domain();
    127                 break;
    128 
    129             // Empty or other.
    130             default :
    131                 $user_domain = bp_members_get_user_url( $r['user_id'] );
    132                 break;
    133         }
     116        // Check user ID and determine base user slug.
     117        $user_slug = bp_members_get_user_slug( $r['user_id'] );
    134118
    135119        // Bail if no user domain was calculated.
    136         if ( empty( $user_domain ) ) {
     120        if ( empty( $user_slug ) ) {
    137121            return '';
    138122        }
     123
     124        $message_slug        = bp_get_messages_slug();
     125        $custom_message_slug = bp_rewrites_get_slug( 'members', 'member_' . $message_slug, $message_slug );
     126        $path_chunks         = array(
     127            'component_id'          => 'members',
     128            'single_item'           => $user_slug,
     129            'single_item_component' => $custom_message_slug,
     130        );
    139131
    140132        // Define local variables.
     
    183175
    184176            if ( true === $is_starred ) {
    185                 $action    = 'unstar';
    186                 $bulk_attr = ' data-star-bulk="1"';
    187                 $retval    = $user_domain . bp_get_messages_slug() . '/unstar/' . $message_id . '/' . $nonce . '/all/';
     177                $action                                      = 'unstar';
     178                $bulk_attr                                   = ' data-star-bulk="1"';
     179                $path_chunks['single_item_action']           = bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_unstar', 'unstar' );
     180                $path_chunks['single_item_action_variables'] = array( $message_id, $nonce, bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_all', 'all' ) );
    188181            } else {
    189                 $action    = 'star';
    190                 $retval    = $user_domain . bp_get_messages_slug() . '/star/' . $message_id . '/' . $nonce . '/';
     182                $action                                      = 'star';
     183                $path_chunks['single_item_action']           = bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_star', 'star' );
     184                $path_chunks['single_item_action_variables'] = array( $message_id, $nonce );
    191185            }
    192186
     
    200194
    201195            if ( true === $is_starred ) {
    202                 $action = 'unstar';
    203                 $retval = $user_domain . bp_get_messages_slug() . '/unstar/' . $message_id . '/' . $nonce . '/';
     196                $action                                      = 'unstar';
     197                $path_chunks['single_item_action']           = bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_unstar', 'unstar' );
     198                $path_chunks['single_item_action_variables'] = array( $message_id, $nonce );
    204199            } else {
    205                 $action = 'star';
    206                 $retval = $user_domain . bp_get_messages_slug() . '/star/' . $message_id . '/' . $nonce . '/';
     200                $action                                      = 'star';
     201                $path_chunks['single_item_action']           = bp_rewrites_get_slug( 'members', 'member_' . $message_slug . '_star', 'star' );
     202                $path_chunks['single_item_action_variables'] = array( $message_id, $nonce );
    207203            }
    208204
    209205            $title = $r["title_{$action}"];
    210206        }
     207
     208        $url = bp_rewrites_get_url( $path_chunks );
    211209
    212210        /**
     
    215213         * @since 2.3.0
    216214         *
    217          * @param string $retval URL for starring / unstarring a message.
    218          * @param array  $r      Parsed link arguments. See $args in bp_get_the_message_star_action_link().
     215         * @param string $url URL for starring / unstarring a message.
     216         * @param array  $r   Parsed link arguments. See $args in bp_get_the_message_star_action_link().
    219217         */
    220         $retval = esc_url( apply_filters( 'bp_get_the_message_star_action_urlonly', $retval, $r ) );
     218        $retval = esc_url( apply_filters( 'bp_get_the_message_star_action_urlonly', $url, $r ) );
    221219        if ( true === (bool) $r['url_only'] ) {
    222220            return $retval;
Note: See TracChangeset for help on using the changeset viewer.