ACF_Rest_Api::get_schema()privateACF 1.0

Dynamically generate the schema for the current request.

Метод класса: ACF_Rest_Api{}

Хуков нет.

Возвращает

Массив.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_schema();

Код ACF_Rest_Api::get_schema() ACF 6.0.4

private function get_schema() {
	$schema = array(
		'description' => 'ACF field data',
		'type'        => 'object',
		'properties'  => array(),
		'arg_options' => array(
			'validate_callback' => array( $this, 'validate_rest_arg' ),
		),
	);

	// If we don't have an object type, we can't determine the schema for the current request.
	$object_type = $this->request->object_type;
	if ( ! $object_type ) {
		return $schema;
	}

	$object_id       = $this->request->get_url_param( 'id' );
	$child_id        = $this->request->get_url_param( 'child_id' );
	$object_sub_type = $this->request->object_sub_type;

	if ( $child_id ) {
		$object_id = $child_id;
	}

	if ( ! $object_id ) {
		$field_groups = $this->get_field_groups_by_object_type( $object_type );
	} else {
		$field_groups = $this->get_field_groups_by_id( $object_id, $object_type, $object_sub_type );
	}

	if ( empty( $field_groups ) ) {
		return $schema;
	}

	foreach ( $field_groups as $field_group ) {
		foreach ( $this->get_fields( $field_group, $object_id ) as $field ) {
			$schema['properties'][ $field['name'] ] = acf_get_field_rest_schema( $field );
		}
	}

	return $schema;
}