Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/18/2023 04:11:04 AM (22 months ago)
Author:
imath
Message:

BP Rewrites: optimize the code used to build URLs

The bp_members_get_path_chunks() & bp_groups_get_path_chunks() functions are making sure URL chunks are customized according to the slugs settings. Instead of redoing at many places all or some of the operations performed by these functions, update the code to build URLs so that it uses these functions.

See #4954
Fixes #8923
Closes https://github.com/buddypress/buddypress/pull/117

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-star.php

    r13442 r13503  
    114114        );
    115115
    116         // Check user ID and determine base user slug.
    117         $user_slug = bp_members_get_user_slug( $r['user_id'] );
    118 
    119         // Bail if no user domain was calculated.
    120         if ( empty( $user_slug ) ) {
     116        // Check user ID.
     117        $user_id = (int) $r['user_id'];
     118        if ( empty( $user_id ) ) {
    121119            return '';
    122120        }
    123121
    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         );
     122        // Init path chunks.
     123        $path_chunks = array( bp_get_messages_slug() );
    131124
    132125        // Define local variables.
     
    175168
    176169            if ( true === $is_starred ) {
    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' ) );
     170                $action        = 'unstar';
     171                $bulk_attr     = ' data-star-bulk="1"';
     172                $path_chunks[] = $action;
     173                $path_chunks[] = array( $message_id, $nonce, 'all' );
    181174            } else {
    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 );
     175                $action        = 'star';
     176                $path_chunks[] = $action;
     177                $path_chunks[] = array( $message_id, $nonce );
    185178            }
    186179
     
    194187
    195188            if ( true === $is_starred ) {
    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 );
     189                $action = 'unstar';
    199190            } else {
    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 );
    203             }
    204 
    205             $title = $r["title_{$action}"];
    206         }
    207 
    208         $url = bp_rewrites_get_url( $path_chunks );
     191                $action = 'star';
     192            }
     193
     194            $path_chunks[] = $action;
     195            $path_chunks[] = array( $message_id, $nonce );
     196            $title         = $r["title_{$action}"];
     197        }
     198
     199        $url = bp_members_get_user_url( $user_id, bp_members_get_path_chunks( $path_chunks ) );
    209200
    210201        /**
Note: See TracChangeset for help on using the changeset viewer.