WP_REST_Menus_Controller::get_item_schema(): array

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


Return

array Item schema data.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php. View all references

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 );
}


Top ↑

Changelog

Changelog
Version Description
5.9.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.