WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema( string $method = WP_REST_Server::CREATABLE ): array<string,
- Since
- 7.1.0
- Source
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:291
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 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$methodstringoptional- HTTP method of the request.
The arguments forCREATABLErequests are checked for required values and may fall-back to a given default.
Default WP_REST_Server::CREATABLE.Default:WP_REST_Server::CREATABLE
Return value
array<string,- array<string, mixed>> Endpoint arguments.
Performance profile
How much work a call to WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema() 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
- Moderate
- Scaling
- Constant
- Instructions
- 14–27
- Plugin surface
- None
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 66.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()one call below WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema() - optionoption read or write
get_option()one call below WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema()
Further down the call graph this can also reach 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 14 | rest_validate_request_arg(), is_wp_error() |
!is_wp_error() | 19 | rest_validate_request_arg(), is_wp_error(), wp_http_validate_url() |
!is_wp_error() | 27 | rest_validate_request_arg(), is_wp_error(), wp_http_validate_url(), __(), string() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 66 | 14–27 | 3 | |
| 8.5 | 66 | 14–27 | 3 | |
| 8.4 | 66 | 14–27 | 3 | |
| 8.3 | 66 | 14–27 | 3 | |
| 8.2 | 66 | 14–27 | 3 | |
| 8.1 | 66 | 14–27 | 3 | 29 more instructions than PHP 7.4 |
| 7.4 | 37 | 9–36 | 1 |
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 · 6
- __()Retrieves the translation of $text.
- rest_validate_request_arg()Validate a request argument based on details registered to the route.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_http_validate_url()Validates a URL as safe for use in the HTTP API.
- WP_REST_Posts_Controller::get_endpoint_args_for_item_schema()
- WP_Error::__construct()Initializes the error.
Used by · 1
- WP_REST_Attachments_Controller::get_edit_media_item_args()Gets the request args for the edit item route.
Source code
public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { $args = parent::get_endpoint_args_for_item_schema( $method ); if ( WP_REST_Server::CREATABLE !== $method ) { return $args; } $args['generate_sub_sizes'] = array( 'type' => 'boolean', 'default' => true, 'description' => __( 'Whether to generate image sub sizes.' ), ); $args['convert_format'] = array( 'type' => 'boolean', 'default' => true, 'description' => __( 'Whether to convert image formats.' ), ); $args['url'] = array( 'type' => 'string', 'format' => 'uri', 'description' => __( 'URL of an external image to sideload into the media library, instead of uploading a file.' ), 'sanitize_callback' => 'sanitize_url', 'validate_callback' => static function ( $url, $request, $param ) { /* * A custom validate_callback replaces the default * rest_validate_request_arg(), so re-apply it first to keep * the schema checks (string type, uri format) enforced. */ $valid = rest_validate_request_arg( $url, $request, $param ); if ( is_wp_error( $valid ) ) { return $valid; } /* * Reject URLs that are not safe to request server-side. wp_http_validate_url() * enforces an HTTP(S) scheme and blocks private, local, and otherwise * disallowed hosts, guarding the sideload against SSRF. */ if ( false === wp_http_validate_url( $url ) ) { return new WP_Error( 'rest_invalid_url', __( 'Invalid URL. Provide a valid, publicly reachable HTTP or HTTPS image URL.' ), array( 'status' => 400 ) ); } return true; }, ); return $args; }Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-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.