xprofile_filter_get_user_display_name( string $full_name, int $user_id )

Conditionally filters ‘bp_core_get_user_displayname’ to return user diaplay name from xprofile.

Description

Parameters

$full_name

(Required)

$user_id

(Required)

Return

(string)

Source

File: bp-xprofile/bp-xprofile-filters.php

function xprofile_filter_get_user_display_name( $full_name, $user_id ) {

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

	if ( !empty( $user_id ) ) {

		$display_name = bp_xprofile_get_member_display_name( $user_id );

		if ( !empty( $display_name ) ) {
			$full_name = $display_name;
		}

		$list_fields = bp_xprofile_get_hidden_fields_for_user( $user_id );

		if ( ! empty( $list_fields ) ) {
			$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, '', $full_name );
			}
		}
	}

	return $full_name;
}

Changelog

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