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 Description

This function is sensitive to the BP_ENABLE_USERNAME_COMPATIBILITY_MODE, so it will return the user_login or user_nicename as appropriate.


Top ↑

Parameters Parameters

$user_id

(int) (Required) User ID to check.

$user_nicename

(string|bool) (Optional) user_nicename of user being checked.

Default value: false

$user_login

(string|bool) (Optional) user_login of user being checked.

Default value: false


Top ↑

Return Return

(string) The username of the matched user or an empty string if no user is found.


Source 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 1.0.1
	 *
	 * @param string $username Username determined by user ID.
	 */
	return apply_filters( 'bp_core_get_username', $username );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.