WP_REST_Menus_Controller::get_item_schema() WordPress Method
The WP_REST_Menus_Controller::get_item_schema() function is used to return the schema for a single menu item. This is useful for defining the properties that a menu item can have, and how those properties can be accessed and updated.
WP_REST_Menus_Controller::get_item_schema() #
Retrieves the term’s schema, conforming to JSON Schema.
Return
(array) Item schema data.
Source
File: wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php
public function get_item_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' => 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', ); return $schema; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |