bp_custom_display_name_format( string $display_name, int $user_id = null )

Get the display_name for member based on user_id

Description

Parameters

$display_name

(Required)

$user_id

(Optional)

Default value: null

Return

(string)

Source

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

function bp_custom_display_name_format( $display_name, $user_id = null ) {
	// some cases it calls the filter directly, therefore no user id is passed
	if ( ! $user_id ) {
		return $display_name;
	}

	$format = bp_get_option( 'bp-display-name-format' );

	switch ( $format ) {
		case 'first_name':
			$display_name = get_user_meta( $user_id, 'first_name', true );
			break;
		case 'first_last_name':
			$display_name = implode( ' ', array_filter( [
				get_user_meta( $user_id, 'first_name',true ),
				get_user_meta( $user_id, 'last_name', true )
			] ) );
			break;
		case 'nickname':
			$display_name = get_user_meta( $user_id, 'nickname', true );
			break;
	}

	return trim( $display_name );
}

Changelog

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