ACF\AI\Abilities

PostType::get_rest_item_output_schema │ private │ ACF 6.8.0

Gets the REST schema for item(s) in a CPT.

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

Хуков нет.

Возвращает

array|null. Schema array or null if not available.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_rest_item_output_schema( $acf_fields, $post_type, $type );
$acf_fields(массив) (обязательный)
An array of ACF fields present on the post type.
$post_type(строка) (обязательный)
The post type to get the schema for.
$type(строка)
Schema type: 'item' or 'collection'.
По умолчанию: 'item'

Список изменений

С версии 6.8.0 Введена.

Код PostType::get_rest_item_output_schema() ACF 6.8.11

private function get_rest_item_output_schema( array $acf_fields, string $post_type, string $type = 'item' ) {
	$post_type_object = get_post_type_object( $post_type );

	if ( ! $post_type_object ) {
		return null;
	}

	$controller = $post_type_object->get_rest_controller();
	if ( ! $controller || ! method_exists( $controller, 'get_public_item_schema' ) ) {
		return null;
	}

	$schema = $controller->get_public_item_schema();
	$schema = $this->add_acf_fields_to_schema( $schema, $acf_fields );

	if ( $type === 'collection' ) {
		return array(
			'type'  => 'array',
			'items' => $schema,
		);
	}

	return $schema;
}