WP_REST_Revisions_Controller::prepare_item_for_response( WP_Post $item, WP_REST_Request $request ): WP_REST_Response
- Since
- 4.7.0, 5.9.0, 7.1.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php:606
Compatibility
- WordPress
- since 7.1.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- Post revision object.
$requestWP_REST_Request- Request object.
Return value
WP_REST_Response- Response object.
Performance profile
How much work a call to WP_REST_Revisions_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
- Heavy
- Scaling
- Constant
- Instructions
- 141–205
- Plugin surface
- 3 hooks
- Called by
- 3
Reaches the database via get_post().
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 293.
Third-party callbacks on 'rest_prepare_revision', 'get_the_guid', 'the_content' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_post()one call below WP_REST_Revisions_Controller::prepare_item_for_response()
Further down the call graph this can also reach option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 32 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Revisions_Controller::prepare_item_for_response() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) && !->is_method() && !$fields && !rest_is_field_included() && empty($data) | 141–160 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 149–166 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 150–169 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 150–169 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 150–169 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !rest_is_field_included() && !empty($data) | 153–172 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 158–175 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 158–175 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 158–175 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 159–178 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 159–178 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 159–178 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
20 further outcomes, up to 205 instructions
!isset($value) && !->is_method() && !$fields && !empty($data) | 161–178 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 162–181 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 162–181 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 162–181 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 167–184 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 167–184 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 167–184 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 168–187 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 170–187 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 170–187 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 170–187 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 171–190 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 171–190 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 171–190 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && empty($data) | 176–193 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 179–196 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 179–196 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 179–196 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 180–199 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
!isset($value) && !->is_method() && !$fields && !empty($data) | 188–205 | setup_postdata(), ->is_method(), ->get_fields_for_response(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), get_the_title(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), apply_filters(), rest_is_field_included(), rest_is_field_included(), rest_is_field_included(), ->prepare_excerpt_response(), rest_is_field_included(), ->get_value(), ->add_additional_fields_to_object(), ->filter_response_by_context(), rest_ensure_response(), rest_get_route_for_post(), rest_url(), ->add_link(), apply_filters(), ->restore_post_data() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 293 | 141–205 | 26 | |
| 8.5 | 293 | 141–205 | 26 | |
| 8.4 | 293 | 141–205 | 26 | 24 fewer instructions than PHP 8.3 |
| 8.3 | 317 | 165–229 | 26 | |
| 8.2 | 317 | 165–229 | 26 | |
| 8.1 | 317 | 165–229 | 26 | 6 fewer instructions than PHP 7.4 |
| 7.4 | 323 | 167–232 | 26 |
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.
Hooks and filters fired · 4
4 hooks fire while WP_REST_Revisions_Controller::prepare_item_for_response() runs, in this order:
- apply_filters( rest_prepare_revision )filterline 631 (+25 into the body)
Filters a revision returned from the REST API.
- apply_filters( get_the_guid )filterline 678 (+72 into the body)
Filters the Global Unique Identifier (guid) of the post.
- apply_filters( rest_prepare_revision )filterline 739 (+133 into the body)
Filters a revision returned from the REST API.
Uses · 14
- setup_postdata()Set up global post data.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- 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.
- get_the_title()Retrieves the post title.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- rest_url()Retrieves the URL to a REST endpoint.
- rest_get_route_for_post()Gets the REST API route for a post.
- WP_REST_Response::__construct()
- WP_REST_Revisions_Controller::restore_post_data()Restores the global post to its previous value after preparing a revision.
- WP_REST_Revisions_Controller::get_fields_for_response()
- WP_REST_Revisions_Controller::prepare_date_response()Checks the post_date_gmt or modified_gmt and prepare any post or modified date for single post output.
- WP_REST_Revisions_Controller::prepare_excerpt_response()Checks the post excerpt and prepare it for single post output.
Show all 14
- WP_REST_Revisions_Controller::add_additional_fields_to_object()
- WP_REST_Revisions_Controller::filter_response_by_context()
Used by · 3
- WP_REST_Revisions_Controller::delete_item()Deletes a single revision.
- WP_REST_Revisions_Controller::get_item()Retrieves one revision from the collection.
- WP_REST_Revisions_Controller::get_items()Gets a collection of revisions.
Source code
public function prepare_item_for_response( $item, $request ) { /* * Save the previous global post so it can be restored before returning. * Preparing the revision sets up the global post and post data, which * must not leak into the rest of the request (e.g. the autosaves endpoint * is preloaded in the block editor, where a leaked global post can cause * the editor to be initialized with the wrong post). * * Note that $post is intentionally not declared as a global here. It must * remain local to this method so that a filter which reassigns the global * post while the response is being prepared (for example on 'the_content') * cannot change which post the remaining fields are read from. */ $previous_post = isset( $GLOBALS['post'] ) && $GLOBALS['post'] instanceof WP_Post ? $GLOBALS['post'] : null; // Restores the more descriptive, specific name for use within this method. $post = $item; $GLOBALS['post'] = $post; setup_postdata( $post ); // Don't prepare the response body for HEAD requests. if ( $request->is_method( 'HEAD' ) ) { /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php */ $response = apply_filters( 'rest_prepare_revision', new WP_REST_Response( array() ), $post, $request ); $this->restore_post_data( $previous_post ); return $response; } $fields = $this->get_fields_for_response( $request ); $data = array(); if ( in_array( 'author', $fields, true ) ) { $data['author'] = (int) $post->post_author; } if ( in_array( 'date', $fields, true ) ) { $data['date'] = $this->prepare_date_response( $post->post_date_gmt, $post->post_date ); } if ( in_array( 'date_gmt', $fields, true ) ) { $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt ); } if ( in_array( 'id', $fields, true ) ) { $data['id'] = $post->ID; } if ( in_array( 'modified', $fields, true ) ) { $data['modified'] = $this->prepare_date_response( $post->post_modified_gmt, $post->post_modified ); } if ( in_array( 'modified_gmt', $fields, true ) ) { $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt ); } if ( in_array( 'parent', $fields, true ) ) { $data['parent'] = (int) $post->post_parent; } if ( in_array( 'slug', $fields, true ) ) { $data['slug'] = $post->post_name; } if ( rest_is_field_included( 'guid', $fields ) ) { $data['guid'] = array(); } if ( rest_is_field_included( 'guid.rendered', $fields ) ) { /** This filter is documented in wp-includes/post-template.php */ $data['guid']['rendered'] = apply_filters( 'get_the_guid', $post->guid, $post->ID ); } if ( rest_is_field_included( 'guid.raw', $fields ) ) { $data['guid']['raw'] = $post->guid; } if ( rest_is_field_included( 'title', $fields ) ) { $data['title'] = array();Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$post to $item to match parent class for PHP 8 named parameter support.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-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.