WP_REST_Request::get_parameter_order(): string[]
- Since
- 4.4.0
- Source
wp-includes/rest-api/class-wp-rest-request.php:361
Description
Used when checking parameters in WP_REST_Request::get_param().
Compatibility
- WordPress
- since 4.4.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.
Return value
string[]- Array of types to check, in order of priority.
Performance profile
How much work a call to WP_REST_Request::get_parameter_order() 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
- 28–35
- Plugin surface
- 1 hook
- Called by
- 7
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 35.
Third-party callbacks on 'rest_request_parameter_order' run inside this call, and their cost is not bounded by anything here.
7 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
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Request::get_parameter_order() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 28–33 | ->is_json_content_type(), ->parse_json_params(), ->get_body(), apply_filters() |
!empty($body) | 32–35 | ->is_json_content_type(), ->parse_json_params(), ->get_body(), ->parse_body_params(), apply_filters() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 35 instructions, 28–35 executed per call, 4 branches. The work does not change between versions.
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 · 1
One hook fires while WP_REST_Request::get_parameter_order() runs, in this order:
- apply_filters( rest_request_parameter_order )filterline 397 (+36 into the body)
Filters the parameter priority order for a REST API request.
Uses · 5
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_REST_Request::is_json_content_type()Checks if the request has specified a JSON Content-Type.
- WP_REST_Request::parse_json_params()Parses the JSON parameters.
- WP_REST_Request::get_body()Retrieves the request body content.
- WP_REST_Request::parse_body_params()Parses the request body parameters.
Used by · 7
- WP_REST_Request::get_param()Retrieves a parameter from the request.
- WP_REST_Request::get_params()Retrieves merged parameters from the request.
- WP_REST_Request::has_param()Checks if a parameter exists in the request.
- WP_REST_Request::offsetExists()Checks if a parameter is set.
- WP_REST_Request::offsetUnset()Removes a parameter from the request.
- WP_REST_Request::sanitize_params()Sanitizes (where possible) the params on the request.
- WP_REST_Request::set_param()Sets a parameter on the request.
Source code
protected function get_parameter_order() { $order = array(); if ( $this->is_json_content_type() ) { $order[] = 'JSON'; } $this->parse_json_params(); // Ensure we parse the body data. $body = $this->get_body(); if ( 'POST' !== $this->method && ! empty( $body ) ) { $this->parse_body_params(); } $accepts_body_data = array( 'POST', 'PUT', 'PATCH', 'DELETE' ); if ( in_array( $this->method, $accepts_body_data, true ) ) { $order[] = 'POST'; } $order[] = 'GET'; $order[] = 'URL'; $order[] = 'defaults'; /** * Filters the parameter priority order for a REST API request. * * The order affects which parameters are checked when using WP_REST_Request::get_param() * and family. This acts similarly to PHP's `request_order` setting. * * @since 4.4.0 * * @param string[] $order Array of types to check, in order of priority. * @param WP_REST_Request $request The request object. */ return apply_filters( 'rest_request_parameter_order', $order, $this ); }Changelog
Introduced in 4.4.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/class-wp-rest-request.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.