xprofile_get_field( int|object $field, int|null $user_id = null, bool $get_data = true )

Get a profile field object.

Description

Parameters

$field

(int|object) (Required) ID of the field or object representing field data.

$user_id

(int|null) (Optional) ID of the user associated with the field. Ignored if $get_data is false. If $get_data is true, but no $user_id is provided, defaults to logged-in user ID.

Default value: null

$get_data

(bool) (Optional) Whether to fetch data for the specified $user_id.

Default value: true

Return

(BP_XProfile_Field|null) Field object if found, otherwise null.

Source

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

function xprofile_get_field( $field, $user_id = null, $get_data = true ) {
	if ( $field instanceof BP_XProfile_Field ) {
		$_field = $field;
	} elseif ( is_object( $field ) ) {
		$_field = new BP_XProfile_Field();
		$_field->fill_data( $field );
	} else {
		$_field = BP_XProfile_Field::get_instance( $field, $user_id, $get_data );
	}

	if ( ! $_field ) {
		return null;
	}

	return $_field;
}

Changelog

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