Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (4 years ago)
Author:
imath
Message:

BP Rewrites: Introduce the bp_members_get_user_url() function

As many member URLs are built concatenating bp_core_get_user_domain()
with URL chunks, the safer way to make sure developers update the way they
build their member URLs in favor of using BP Rewrites is:

  1. to deprecate this function
  2. create a new function bp_members_get_user_url() which is a wrapper of

bp_rewrites_get_url()

  1. replace all bp_core_get_user_domain() occurrences by

bp_members_get_user_url()

This commit also deprecates bp_core_get_username() in favor of the new
bp_members_get_user_slug() function and updates PHPUnit tests.

Props r-a-y, johnjamesjacoby, boonebgorges

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-filters.php

    r13395 r13433  
    292292
    293293        foreach( (array) $comments as $comment ) {
    294                 if ( $comment->user_id )
     294                if ( $comment->user_id ) {
    295295                        $user_ids[] = $comment->user_id;
    296         }
    297 
    298         if ( empty( $user_ids ) )
     296                }
     297        }
     298
     299        if ( empty( $user_ids ) ) {
    299300                return $comments;
     301        }
    300302
    301303        $user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
    302304
    303         if ( !$userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) )
     305        if ( ! $userdata = $wpdb->get_results( "SELECT ID as user_id, user_login, user_nicename FROM {$wpdb->users} WHERE ID IN ({$user_ids})" ) ) {
    304306                return $comments;
    305 
    306         foreach( (array) $userdata as $user )
    307                 $users[$user->user_id] = bp_core_get_user_domain( $user->user_id, $user->user_nicename, $user->user_login );
     307        }
     308
     309        foreach( (array) $userdata as $user ) {
     310                $users[$user->user_id] = bp_members_get_user_url( $user->user_id );
     311        }
    308312
    309313        foreach( (array) $comments as $i => $comment ) {
    310                 if ( !empty( $comment->user_id ) ) {
    311                         if ( !empty( $users[$comment->user_id] ) )
     314                if ( ! empty( $comment->user_id ) ) {
     315                        if ( ! empty( $users[$comment->user_id] ) ) {
    312316                                $comments[$i]->comment_author_url = $users[$comment->user_id];
     317                        }
    313318                }
    314319        }
    … …  
    12331238                                $tokens['unsubscribe'] = esc_url( sprintf(
    12341239                                        '%s%s/notifications/',
    1235                                         bp_core_get_user_domain( $user_obj->ID ),
     1240                                        bp_members_get_user_url( $user_obj->ID ),
    12361241                                        bp_get_settings_slug()
    12371242                                ) );
Note: See TracChangeset for help on using the changeset viewer.