bp_get_member_name()

Get the display name of the current member in the loop.

Description

Full name is, by default, pulled from xprofile’s Full Name field. When this field is empty, we try to get an alternative name from the WP users table, in the following order of preference: display_name, user_nicename, user_login.

Return

(string) The user's fullname for display.

Source

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

	function bp_get_member_name() {
		global $members_template;

		// Generally, this only fires when xprofile is disabled.
		if ( empty( $members_template->member->fullname ) ) {
			// Our order of preference for alternative fullnames.
			$name_stack = array(
				'display_name',
				'user_nicename',
				'user_login'
			);

			foreach ( $name_stack as $source ) {
				if ( !empty( $members_template->member->{$source} ) ) {
					// When a value is found, set it as fullname and be done with it.
					$members_template->member->fullname = $members_template->member->{$source};
					break;
				}
			}
		}

		$list_fields = bp_xprofile_get_hidden_fields_for_user(  $members_template->member->ID, bp_loggedin_user_id() );
		if ( empty( $list_fields ) ) {
			$full_name = $members_template->member->fullname;
		} else {
			$last_name_field_id = bp_xprofile_lastname_field_id();
			if ( in_array( $last_name_field_id, $list_fields ) ) {
				$last_name    = $members_template->member->fullname;
				$full_name = str_replace( ' ' . $last_name, '', $members_template->member->fullname );
			} else {
				$full_name = $members_template->member->fullname;
			}
		}

		/**
		 * Filters the display name of current member in the loop.
		 *
		 * @since BuddyPress 1.2.0
		 *
		 * @param string $fullname Display name for current member.
		 */
		return apply_filters( 'bp_get_member_name', trim( $full_name ) );
	}

Changelog

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