wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php:606Prepares the revision for the REST response.
$itemWP_Post$requestWP_REST_RequestWP_REST_Response4 hooks fire while WP_REST_Revisions_Controller::prepare_item_for_response() runs, in this order:
Filters a revision returned from the REST API.
Filters the Global Unique Identifier (guid) of the post.
Filters a revision returned from the REST API.
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();Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
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.