BP_XProfile_ProfileData::get_all_for_user( int $user_id )

Get all of the profile information for a specific user.


Parameters Parameters

$user_id

(int) (Required) ID of the user.


Top ↑

Return Return

(array)


Source Source

File: bp-xprofile/classes/class-bp-xprofile-profiledata.php

	public static function get_all_for_user( $user_id ) {

		$groups = bp_xprofile_get_groups( array(
			'user_id'                => $user_id,
			'hide_empty_groups'      => true,
			'hide_empty_fields'      => true,
			'fetch_fields'           => true,
			'fetch_field_data'       => true,
		) );

		$profile_data = array();

		if ( ! empty( $groups ) ) {
			$user = new WP_User( $user_id );

			$profile_data['user_login']    = $user->user_login;
			$profile_data['user_nicename'] = $user->user_nicename;
			$profile_data['user_email']    = $user->user_email;

			foreach ( (array) $groups as $group ) {
				if ( empty( $group->fields ) ) {
					continue;
				}

				foreach ( (array) $group->fields as $field ) {
					$profile_data[ $field->name ] = array(
						'field_group_id'   => $group->id,
						'field_group_name' => $group->name,
						'field_id'         => $field->id,
						'field_type'       => $field->type,
					);

					if ( is_null( $field->data ) ) {
						if ( 1 === $field->id ) {
							$profile_data[ $field->name ]['field_data'] = $user->display_name;
						} elseif ( isset( $field->type_obj ) && $field->type_obj instanceof BP_XProfile_Field_Type && isset( $field->type_obj->wp_user_key ) ) {
							$meta = $field->type_obj->get_field_value( $user->ID, $field->id );

							if ( isset( $meta['value'] ) ) {
								$profile_data[ $field->name ]['field_data'] = $meta['value'];
							}
						} else {
							$profile_data[ $field->name ]['field_data'] = false;
						}
					} else {
						$profile_data[ $field->name ]['field_data'] = $field->data->value;
					}
				}
			}
		}

		return $profile_data;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
8.0.0 Checks if a null field data is an xProfile WP Field.
1.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.