wppaste
WordPress

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
Retrieves the query params for the attachments collection.

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 for CREATABLE requests 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

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
14–27

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 66.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()one call below WP_REST_Attachments_Controller::get_endpoint_args_for_item_schema()
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
is_wp_error()14rest_validate_request_arg(), is_wp_error()
!is_wp_error()19rest_validate_request_arg(), is_wp_error(), wp_http_validate_url()
!is_wp_error()27rest_validate_request_arg(), is_wp_error(), wp_http_validate_url(), __(), string()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6614–273
8.56614–273
8.46614–273
8.36614–273
8.26614–273
8.16614–27329 more instructions than PHP 7.4
7.4379–361

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

Used by · 1

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.