BP_REST_Members_Endpoint::xprofile_data( int $user_id )

Get XProfile info from the user.


Parameters Parameters

$user_id

(int) (Required) User ID.


Top ↑

Return Return

(array)


Source Source

File: bp-members/classes/class-bp-rest-members-endpoint.php

	protected function xprofile_data( $user_id ) {
		$data = array();

		// Get XProfile groups, only if the component is active.
		if ( bp_is_active( 'xprofile' ) ) {
			$fields_endpoint = new BP_REST_XProfile_Fields_Endpoint();

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

			foreach ( $groups as $group_order => $group ) {
				$data['groups'][ $group_order ] = array(
					'name' => $group->name,
					'id'   => $group->id,
				);

				foreach ( $group->fields as $item ) {
					$data['groups'][ $group_order ]['fields'][ $item->field_order ] = array(
						'name'  => $item->name,
						'id'    => $item->id,
						'value' => array(
							'raw'          => $item->data->value,
							'unserialized' => $fields_endpoint->get_profile_field_unserialized_value( $item->data->value ),
							'rendered'     => $fields_endpoint->get_profile_field_rendered_value( $item->data->value, $item ),
						),
					);
				}
			}
		} else {
			$data = array( __( 'No extended profile data available as the component is inactive', 'buddypress' ) );
		}

		return $data;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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