BP_REST_XProfile_Fields_Endpoint::assemble_response_data( BP_XProfile_Field $field, WP_REST_Request $request )

Assembles single XProfile field data to return as an object.


Parameters Parameters

$field

(BP_XProfile_Field) (Required) XProfile field object.

$request

(WP_REST_Request) (Required) Full data about the request.


Top ↑

Return Return

(array)


Source Source

File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php

	public function assemble_response_data( $field, $request ) {
		$data = array(
			'id'                => (int) $field->id,
			'group_id'          => (int) $field->group_id,
			'parent_id'         => (int) $field->parent_id,
			'type'              => $field->type,
			'name'              => $field->name,
			'description'       => array(
				'raw'      => $field->description,
				'rendered' => apply_filters( 'bp_get_the_profile_field_description', $field->description ),
			),
			'is_required'       => (bool) $field->is_required,
			'can_delete'        => (bool) $field->can_delete,
			'field_order'       => (int) $field->field_order,
			'option_order'      => (int) $field->option_order,
			'order_by'          => strtoupper( $field->order_by ),
			'is_default_option' => (bool) $field->is_default_option,
		);

		if ( ! empty( $request->get_param( 'fetch_visibility_level' ) ) ) {
			$data['visibility_level'] = $field->visibility_level;
		}

		if (
			0 === $data['parent_id']
			&& true === wp_validate_boolean( $request->get_param( 'fetch_field_data' ) )
			&& ! empty( $request->get_param( 'user_id' ) )
		) {
			if ( isset( $field->data->id ) ) {
				$data['data']['id'] = $field->data->id;
			}

			$data['data']['value'] = array(
				'raw'          => $field->data->value,
				'unserialized' => $this->get_profile_field_unserialized_value( $field->data->value ),
				'rendered'     => $this->get_profile_field_rendered_value( $field->data->value, $field ),
			);
		}

		// Adding the options.
		if ( method_exists( $field, 'get_children' ) ) {
			$data['options'] = array_map(
				function( $item ) use ( $request ) {
					return $this->assemble_response_data( $item, $request );
				},
				$field->get_children()
			);
		}

		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
		$data    = $this->add_additional_fields_to_object( $data, $request );
		$data    = $this->filter_response_by_context( $data, $context );

		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.