bp_core_get_username( int $user_id, string|bool $user_nicename = false, string|bool $user_login = false )
Return the username for a user based on their user id.
Description
This function is sensitive to the BP_ENABLE_USERNAME_COMPATIBILITY_MODE, so it will return the user_login or user_nicename as appropriate.
Parameters
- $user_id
-
(Required) User ID to check.
- $user_nicename
-
(Optional) user_nicename of user being checked.
Default value: false
- $user_login
-
(Optional) user_login of user being checked.
Default value: false
Return
(string) The username of the matched user or an empty string if no user is found.
Source
File: bp-members/bp-members-functions.php
function bp_core_get_username( $user_id = 0, $user_nicename = false, $user_login = false ) { if ( ! $user_nicename && ! $user_login ) { // Pull an audible and maybe use the login over the nicename. if ( bp_is_username_compatibility_mode() ) { $username = get_the_author_meta( 'login', $user_id ); } else { $username = get_the_author_meta( 'nicename', $user_id ); } } else { $username = bp_is_username_compatibility_mode() ? $user_login : $user_nicename; } /** * Filters the username based on originally provided user ID. * * @since BuddyPress 1.0.1 * * @param string $username Username determined by user ID. */ return apply_filters( 'bp_core_get_username', $username ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.