WP_REST_Menus_Controller::get_item_schema(): array
- Since
- 5.9.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php:525
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
array- Item schema data.
Performance profile
How much work a call to WP_REST_Menus_Controller::get_item_schema() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 12–34
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 84.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Menus_Controller::get_item_schema() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$valid is null, false, long, double, string, array, object, resource | 12 | rest_validate_request_arg() |
$valid is not null, false, long, double, string, array, object, resource | 20–21 | rest_validate_request_arg(), rest_sanitize_request_arg() |
$valid is not null, false, long, double, string, array, object, resource && !$locations && !$location | 34 | rest_validate_request_arg(), rest_sanitize_request_arg(), get_registered_nav_menus(), __(), location() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 84 | 12–34 | 5 | |
| 8.5 | 84 | 12–34 | 5 | |
| 8.4 | 84 | 12–34 | 5 | |
| 8.3 | 84 | 12–34 | 5 | |
| 8.2 | 84 | 12–34 | 5 | |
| 8.1 | 84 | 12–34 | 5 | 37 more instructions than PHP 7.4 |
| 7.4 | 47 | 8–41 | 1 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 7
- __()Retrieves the translation of $text.
- rest_validate_request_arg()Validate a request argument based on details registered to the route.
- rest_sanitize_request_arg()Sanitize a request argument based on details registered to the route.
- get_registered_nav_menus()Retrieves all registered navigation menu locations in a theme.
- WP_REST_Menus_Controller::add_additional_fields_schema()
- WP_REST_Terms_Controller::get_item_schema()Retrieves the term's schema, conforming to JSON Schema.
- WP_Error::__construct()Initializes the error.
Used by · 3
- WP_REST_Menus_Controller::create_item()Creates a single term in a taxonomy.
- WP_REST_Menus_Controller::prepare_item_for_database()Prepares a single term for create or update.
- WP_REST_Menus_Controller::update_item()Updates a single term from a taxonomy.
Source code
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 ); }Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-menus-controller.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.