WP_REST_Abilities_V1_List_Controller::get_items( WP_REST_Request $request ): WP_REST_Response
- Since
- 6.9.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php:88
Compatibility
- WordPress
- since 6.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 3 of the 5 tracked releases, added in 6.9.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- Response object on success.
Performance profile
How much work a call to WP_REST_Abilities_V1_List_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
- Light
- Scaling
- Scales with input
- Instructions
- 65–109
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
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 125.
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
apply_filters()one call below WP_REST_Abilities_V1_List_Controller::get_items()
Further down the call graph this can also reach option, cache, serialize, query 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 · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Abilities_V1_List_Controller::get_items() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($request) && !$page | 65–71 | wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg() |
!empty($request) && !$page | 72–78 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg() |
empty($request) && !$page | 73–80 | wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg() |
empty($request) | 76–82 | wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header() |
!empty($request) && !$page | 80–87 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg() |
!empty($request) | 83–89 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header() |
empty($request) | 84–91 | wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header() |
empty($request) && $page | 87–93 | wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!empty($request) | 91–98 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header() |
!empty($request) && $page | 94–100 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
empty($request) && $page | 95–102 | wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
!empty($request) && $page | 102–109 | array_merge(), wp_get_abilities(), ceil(), ->get_method(), array_slice(), rest_ensure_response(), ->header(), ->header(), ->get_query_params(), urlencode_deep(), rest_url(), add_query_arg(), add_query_arg(), ->link_header(), add_query_arg(), ->link_header() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 125 | 65–109 | 8 | |
| 8.5 | 125 | 65–109 | 8 | |
| 8.4 | 125 | 65–109 | 8 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 127 | 67–111 | 8 | |
| 8.2 | 127 | 67–111 | 8 | |
| 8.1 | 127 | 67–111 | 8 | |
| 7.4 | 127 | 67–111 | 8 |
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
- wp_get_abilities()Retrieves registered abilities, optionally filtered by the given arguments.
- rest_ensure_response()Ensures a REST response is a response object (for consistency).
- add_query_arg()Retrieves a modified URL query string.
- urlencode_deep()Navigates through an array, object, or scalar, and encodes the values to be used in a URL.
- rest_url()Retrieves the URL to a REST endpoint.
- WP_REST_Response::__construct()
- WP_REST_Abilities_V1_List_Controller::prepare_item_for_response()Prepares an ability for response.
- WP_REST_Abilities_V1_List_Controller::prepare_response_for_collection()
Source code
public function get_items( $request ) { $query_args = array( 'meta' => array( 'show_in_rest' => true ), ); if ( ! empty( $request['category'] ) ) { $query_args['category'] = $request['category']; } if ( ! empty( $request['namespace'] ) ) { $query_args['namespace'] = $request['namespace']; } if ( ! empty( $request['meta'] ) ) { // Merge caller meta first so the forced show_in_rest filter wins. This keeps a caller from using meta to reveal abilities hidden from REST. $query_args['meta'] = array_merge( $request['meta'], $query_args['meta'] ); } $abilities = wp_get_abilities( $query_args ); $page = $request['page']; $per_page = $request['per_page']; $offset = ( $page - 1 ) * $per_page; $total_abilities = count( $abilities ); $max_pages = (int) ceil( $total_abilities / $per_page ); if ( $request->get_method() === 'HEAD' ) { $response = new WP_REST_Response( array() ); } else { $abilities = array_slice( $abilities, $offset, $per_page ); $data = array(); foreach ( $abilities as $ability ) { $item = $this->prepare_item_for_response( $ability, $request ); $data[] = $this->prepare_response_for_collection( $item ); } $response = rest_ensure_response( $data ); } $response->header( 'X-WP-Total', (string) $total_abilities ); $response->header( 'X-WP-TotalPages', (string) $max_pages ); $query_params = $request->get_query_params(); $base = add_query_arg( urlencode_deep( $query_params ), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) ); if ( $page > 1 ) { $prev_page = $page - 1; $prev_link = add_query_arg( 'page', $prev_page, $base ); $response->link_header( 'prev', $prev_link ); } if ( $page < $max_pages ) { $next_page = $page + 1; $next_link = add_query_arg( 'page', $next_page, $base ); $response->link_header( 'next', $next_link ); } return $response; }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 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-abilities-v1-list-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.