WP_REST_Menus_Controller::get_item_schema()publicWP 5.9.0

Retrieves the term's schema, conforming to JSON Schema.

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

Хуков нет.

Возвращает

Массив. Item schema data.

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

$WP_REST_Menus_Controller = new WP_REST_Menus_Controller();
$WP_REST_Menus_Controller->get_item_schema();

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

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

Код WP_REST_Menus_Controller::get_item_schema() WP 6.5.2

public function get_item_schema() {
	if ( $this->schema ) {
		return $this->add_additional_fields_schema( $this->schema );
	}

	$schema = parent::get_item_schema();
	unset( $schema['properties']['count'], $schema['properties']['link'], $schema['properties']['taxonomy'] );

	$schema['properties']['locations'] = array(
		'description' => __( 'The locations assigned to the menu.' ),
		'type'        => 'array',
		'items'       => array(
			'type' => 'string',
		),
		'context'     => array( 'view', 'edit' ),
		'arg_options' => array(
			'validate_callback' => static function ( $locations, $request, $param ) {
				$valid = rest_validate_request_arg( $locations, $request, $param );

				if ( true !== $valid ) {
					return $valid;
				}

				$locations = rest_sanitize_request_arg( $locations, $request, $param );

				foreach ( $locations as $location ) {
					if ( ! array_key_exists( $location, get_registered_nav_menus() ) ) {
						return new WP_Error(
							'rest_invalid_menu_location',
							__( 'Invalid menu location.' ),
							array(
								'location' => $location,
							)
						);
					}
				}

				return true;
			},
		),
	);

	$schema['properties']['auto_add'] = array(
		'description' => __( 'Whether to automatically add top level pages to this menu.' ),
		'context'     => array( 'view', 'edit' ),
		'type'        => 'boolean',
	);

	$this->schema = $schema;

	return $this->add_additional_fields_schema( $this->schema );
}