wppaste
WordPress

wp_edit_attachments_query_vars( array|false $q = false ): array

Since
4.2.0
Source
wp-admin/includes/post.php:1329
Returns the query variables for the current attachments request.

Compatibility

WordPress
since 4.2.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

$qarray|falseoptional
Array of query variables to use to build the query.
Defaults to the $_GET superglobal.Default: false

Return value

array
The parsed query vars.

Performance profile

How much work a call to wp_edit_attachments_query_vars() 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
71–113

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

Plugin surface
1 hook

Third-party callbacks on 'upload_per_page' run inside this call, and their cost is not bounded by anything here.

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 callbacksapply_filters()called directly

Further down the call graph this can also reach query, option, cache, 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 · 8 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_edit_attachments_query_vars() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$q !== false && !isset($q) && !current_user_can()71–95get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys()
$q !== false && !current_user_can()73–99get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), get_current_user_id()
$q !== false && !current_user_can()75–99get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), add_filter()
$q !== false && !current_user_can()77–103get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), get_current_user_id(), add_filter()
$q !== false && !current_user_can()81–105get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), array_intersect(), array_keys()
$q !== false && !current_user_can()83–109get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), array_intersect(), array_keys(), get_current_user_id()
$q !== false && !current_user_can()85–109get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), array_intersect(), array_keys(), add_filter()
$q !== false && !current_user_can()87–113get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys(), array_intersect(), array_keys(), get_current_user_id(), add_filter()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev12771–11323
8.512771–11323
8.412771–11323
8.312771–11323
8.212771–11323
8.112771–113232 fewer instructions than PHP 7.4
7.412971–11323

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_edit_attachments_query_vars() runs, in this order:

  1. apply_filters( upload_per_page )filterline 1357 (+28 into the body)

    Filters the number of items to list per page when listing media items.

Uses · 7

Used by · 1

  • wp_edit_attachments_query()Executes a query for attachments. An array of WP_Query arguments can be passed in, which will override the arguments set by this function.

Source code

function wp_edit_attachments_query_vars( $q = false ) {	if ( false === $q ) {		$q = $_GET;	}	$q['m']         = isset( $q['m'] ) ? (int) $q['m'] : 0;	$q['cat']       = isset( $q['cat'] ) ? (int) $q['cat'] : 0;	$q['post_type'] = 'attachment';	$post_type      = get_post_type_object( 'attachment' );	$states         = 'inherit';	if ( current_user_can( $post_type->cap->read_private_posts ) ) {		$states .= ',private';	} 	$q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;	$q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states; 	$media_per_page = (int) get_user_option( 'upload_per_page' );	if ( empty( $media_per_page ) || $media_per_page < 1 ) {		$media_per_page = 20;	} 	/**	 * Filters the number of items to list per page when listing media items.	 *	 * @since 2.9.0	 *	 * @param int $media_per_page Number of media to list. Default 20.	 */	$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); 	$post_mime_types = get_post_mime_types();	if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) {		unset( $q['post_mime_type'] );	} 	foreach ( array_keys( $post_mime_types ) as $type ) {		if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {			$q['post_mime_type'] = $type;			break;		}	} 	if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {		$q['post_parent'] = 0;	} 	if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {		$q['author'] = get_current_user_id();	} 	// Filter query clauses to include filenames.	if ( isset( $q['s'] ) ) {		add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' );	} 	return $q;}

Changelog

Introduced in 4.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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-admin/includes/post.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.