ACF\AI\Abilities

Taxonomy::get_rest_item_input_schemaprivateACF 6.8.0

Get REST input schema for taxonomy terms.

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

Хуков нет.

Возвращает

array.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_rest_item_input_schema( $acf_fields, $taxonomy_label, $hierarchical, $action ): array;
$acf_fields(массив) (обязательный)
ACF fields for this taxonomy.
$taxonomy_label(строка) (обязательный)
Taxonomy label for descriptions.
$hierarchical(true|false)
Whether taxonomy is hierarchical.
По умолчанию: false
$action(строка)
Action type ('create' or 'update').
По умолчанию: 'create'

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

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

Код Taxonomy::get_rest_item_input_schema() ACF 6.8.8

private function get_rest_item_input_schema( array $acf_fields, string $taxonomy_label, bool $hierarchical = false, string $action = 'create' ): array {
	$schema = array(
		'type'       => 'object',
		'properties' => array(),
	);

	if ( 'update' === $action ) {
		$schema['properties']['id'] = array(
			'type'        => 'integer',
			'description' => sprintf( 'The ID of the %s term to update.', strtolower( $taxonomy_label ) ),
			'required'    => true,
		);
	}

	$schema['properties']['name'] = array(
		'type'        => 'string',
		'description' => sprintf( 'The name of the %s term.', strtolower( $taxonomy_label ) ),
		'required'    => 'update' !== $action,
	);

	$schema['properties']['description'] = array(
		'type'        => 'string',
		'description' => sprintf( 'The description of the %s term.', strtolower( $taxonomy_label ) ),
		'required'    => false,
	);

	$schema['properties']['slug'] = array(
		'type'        => 'string',
		'description' => sprintf( 'The slug of the %s term (auto-generated from name if not provided).', strtolower( $taxonomy_label ) ),
		'required'    => false,
	);

	if ( $hierarchical ) {
		$schema['properties']['parent'] = array(
			'type'        => 'integer',
			'description' => 'Parent term ID for hierarchical taxonomies. Use 0 or omit for top-level terms. For child terms, provide the ID of the parent term.',
			'required'    => false,
			'default'     => 0,
		);
	}

	return $this->add_acf_fields_to_schema( $schema, $acf_fields );
}