WP_REST_Navigation_Fallback_Controller::prepare_item_for_response( WP_Post $item, WP_REST_Request $request ): WP_REST_Response
- Since
- 6.3.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php:152
Compatibility
- WordPress
- since 6.3.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.
Parameters
$itemWP_Post- The wp_navigation Post object whose response is being prepared.
$requestWP_REST_Request- Request object.
Return value
WP_REST_Response- $response The response data.
Performance profile
How much work a call to WP_REST_Navigation_Fallback_Controller::prepare_item_for_response() 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
- Trivial
- Scaling
- Constant
- Instructions
- 41–53
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 54.
Nothing here hands control to plugin code.
1 place 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_Navigation_Fallback_Controller::prepare_item_for_response() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!rest_is_field_included() | 41–46 | ->get_fields_for_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_is_field_included(), rest_is_field_included() |
rest_is_field_included() | 43–48 | ->get_fields_for_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_is_field_included(), ->prepare_links(), ->add_links() |
| always | 48–53 | ->get_fields_for_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_is_field_included(), rest_is_field_included(), ->prepare_links(), ->add_links() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 54 | 41–53 | 4 | |
| 8.5 | 54 | 41–53 | 4 | |
| 8.4 | 54 | 41–53 | 4 | |
| 8.3 | 54 | 41–53 | 4 | |
| 8.2 | 54 | 41–53 | 4 | |
| 8.1 | 54 | 41–53 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 55 | 41–54 | 4 |
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 · 6
- rest_is_field_included()Given an array of fields to include in a response, some of which may be `nested.fields`, determine whether the provided field should be included in the response body.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- WP_REST_Navigation_Fallback_Controller::get_fields_for_response()
- WP_REST_Navigation_Fallback_Controller::add_additional_fields_to_object()
- WP_REST_Navigation_Fallback_Controller::filter_response_by_context()
- WP_REST_Navigation_Fallback_Controller::prepare_links()Prepares the links for the request.
Used by · 1
- WP_REST_Navigation_Fallback_Controller::get_item()Gets the most appropriate fallback Navigation Menu.
Source code
public function prepare_item_for_response( $item, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); if ( rest_is_field_included( 'id', $fields ) ) { $data['id'] = (int) $item->ID; } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; $data = $this->add_additional_fields_to_object( $data, $request ); $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $links = $this->prepare_links( $item ); $response->add_links( $links ); } return $response; }Changelog
Introduced in 6.3.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 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-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.