bp_core_get_user_displayname( int|string|bool $user_id_or_username )

Fetch the display name for a user.

Description

Parameters

$user_id_or_username

(int|string|bool) (Required) User ID or username.

Return

(string|bool) The display name for the user in question, or false if user not found.

Source

File: bp-members/bp-members-functions.php

function bp_core_get_user_displayname( $user_id_or_username ) {
	if ( empty( $user_id_or_username ) ) {
		return false;
	}

	if ( ! is_numeric( $user_id_or_username ) ) {
		$user_id = bp_core_get_userid( $user_id_or_username );
	} else {
		$user_id = $user_id_or_username;
	}

	if ( empty( $user_id ) ) {
		return false;
	}


	$list_fields = bp_xprofile_get_hidden_fields_for_user( $user_id, bp_loggedin_user_id());
	if ( empty( $list_fields ) ) {
		$full_name = get_the_author_meta( 'display_name', $user_id );
		if ( empty( $full_name ) ) {
		    $full_name = get_the_author_meta( 'nickname', $user_id );
        }
	} else {
		$last_name_field_id = bp_xprofile_lastname_field_id();
		if ( in_array( $last_name_field_id, $list_fields ) ) {
			$last_name    = xprofile_get_field_data( $last_name_field_id, $user_id );
			$full_name = str_replace( ' ' . $last_name, '', get_the_author_meta( 'display_name', $user_id ) );
		} else {
			$full_name = get_the_author_meta( 'display_name', $user_id );
		}
	}

	if ( empty( $full_name ) && empty( get_userdata( $user_id ) ) ) {
		$full_name = __( 'Deleted User', 'buddyboss' );
    }

	/**
	 * Filters the display name for the passed in user.
	 *
	 * @since BuddyPress 1.0.1
	 *
	 * @param string $fullname Display name for the user.
	 * @param int    $user_id  ID of the user to check.
	 */
	return apply_filters( 'bp_core_get_user_displayname', trim( $full_name ), $user_id );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.1 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.