WP_REST_Autosaves_Controller::get_items( WP_REST_Request $request ): WP_REST_Response|WP_Error
- Since
- 5.0.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php:314
Description
Contains the user's autosave, for empty if it doesn't exist.
Compatibility
- WordPress
- since 5.0.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
$requestWP_REST_Request- Full details about the request.
Return value
WP_REST_Response|WP_Error- Response object on success, or WP_Error object on failure.
Performance profile
How much work a call to WP_REST_Autosaves_Controller::get_items() 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
- Scales with input
- Instructions
- 12–29
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 49.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()one call below WP_REST_Autosaves_Controller::get_items() - querycontent query
get_post()one call below WP_REST_Autosaves_Controller::get_items()
Further down the call graph this can also reach cache, option, 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Autosaves_Controller::get_items() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 12 | ->get_parent(), is_wp_error() |
!is_wp_error() && ->is_method() | 19 | ->get_parent(), is_wp_error(), ->is_method() |
!is_wp_error() && !->is_method() | 28–29 | ->get_parent(), is_wp_error(), ->is_method(), wp_get_post_revisions(), rest_ensure_response() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 49 | 12–29 | 5 | |
| 8.5 | 49 | 12–29 | 5 | |
| 8.4 | 49 | 12–29 | 5 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 52 | 12–29 | 5 | |
| 8.2 | 52 | 12–29 | 5 | |
| 8.1 | 52 | 12–29 | 5 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 53 | 12–29 | 5 |
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 · 8
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_get_post_revisions()Returns all revisions of specified post.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- WP_REST_Autosaves_Controller::get_parent()Get the parent post.
- WP_REST_Response::__construct()
- WP_REST_Autosaves_Controller::prepare_item_for_response()Prepares the revision for the REST response.
- WP_REST_Autosaves_Controller::prepare_response_for_collection()
Source code
public function get_items( $request ) { $parent = $this->get_parent( $request['id'] ); if ( is_wp_error( $parent ) ) { return $parent; } if ( $request->is_method( 'HEAD' ) ) { // Return early as this handler doesn't add any response headers. return new WP_REST_Response( array() ); } $response = array(); $parent_id = $parent->ID; $revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) ); foreach ( $revisions as $revision ) { if ( str_contains( $revision->post_name, "{$parent_id}-autosave" ) ) { $data = $this->prepare_item_for_response( $revision, $request ); $response[] = $this->prepare_response_for_collection( $data ); } } return rest_ensure_response( $response ); }Changelog
Introduced in 5.0.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.0.4 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-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.