Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/07/2023 04:28:08 AM (14 months 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/deprecated/12.0.php

    r13432 r13433  
    158158    _deprecated_function( __FUNCTION__, '12.0.0' );
    159159}
     160
     161/**
     162 * Return the username for a user based on their user id.
     163 *
     164 * This function is sensitive to the BP_ENABLE_USERNAME_COMPATIBILITY_MODE,
     165 * so it will return the user_login or user_nicename as appropriate.
     166 *
     167 * @since 1.0.0
     168 * @deprecated 12.0.0
     169 *
     170 * @param int         $user_id       User ID to check.
     171 * @param string|bool $user_nicename Optional. user_nicename of user being checked.
     172 * @param string|bool $user_login    Optional. user_login of user being checked.
     173 * @return string The username of the matched user or an empty string if no user is found.
     174 */
     175function bp_core_get_username( $user_id = 0, $user_nicename = false, $user_login = false ) {
     176    _deprecated_function( __FUNCTION__, '12.0.0', 'bp_members_get_user_slug()' );
     177
     178    if ( ! $user_id ) {
     179        $value = $user_nicename;
     180        $field = 'slug';
     181
     182        if ( ! $user_nicename ) {
     183            $value = $user_login;
     184            $field = 'login';
     185        }
     186
     187        $user = get_user_by( $field, $value );
     188
     189        if ( $user instanceof WP_User ) {
     190            $user_id = (int) $user->ID;
     191        }
     192    }
     193
     194    $username = bp_members_get_user_slug( $user_id );
     195
     196    /**
     197     * Filters the username based on originally provided user ID.
     198     *
     199     * @since 1.0.1
     200     * @deprecated 12.0.0
     201     *
     202     * @param string $username Username determined by user ID.
     203     */
     204    return apply_filters_deprecated( 'bp_core_get_username', array( $username ), '12.0.0', 'bp_members_get_user_slug' );
     205}
     206
     207/**
     208 * Return the domain for the passed user: e.g. http://example.com/members/andy/.
     209 *
     210 * @since 1.0.0
     211 * @deprecated 12.0.0
     212 *
     213 * @param int         $user_id       The ID of the user.
     214 * @param string|bool $user_nicename Optional. user_nicename of the user.
     215 * @param string|bool $user_login    Optional. user_login of the user.
     216 * @return string
     217 */
     218function bp_core_get_user_domain( $user_id = 0, $user_nicename = false, $user_login = false ) {
     219    _deprecated_function( __FUNCTION__, '12.0.0', 'bp_members_get_user_url()' );
     220
     221    if ( empty( $user_id ) ) {
     222        return;
     223    }
     224
     225    $domain = bp_members_get_user_url( $user_id );
     226
     227    // Don't use this filter.  Subject to removal in a future release.
     228    // Use the 'bp_core_get_user_domain' filter instead.
     229    $domain = apply_filters_deprecated( 'bp_core_get_user_domain_pre_cache', array( $domain, $user_id, $user_nicename, $user_login), '12.0.0' );
     230
     231    /**
     232     * Filters the domain for the passed user.
     233     *
     234     * @since 1.0.1
     235     * @deprecated 12.0.0
     236     *
     237     * @param string $domain        Domain for the passed user.
     238     * @param int    $user_id       ID of the passed user.
     239     * @param string $user_nicename User nicename of the passed user.
     240     * @param string $user_login    User login of the passed user.
     241     */
     242    return apply_filters_deprecated( 'bp_core_get_user_domain', array( $domain, $user_id, $user_nicename, $user_login), '12.0.0', 'bp_members_get_user_url' );
     243}
Note: See TracChangeset for help on using the changeset viewer.