wp_edit_attachments_query_vars( array|false $q = false ): array
- Since
- 4.2.0
- Source
wp-admin/includes/post.php:1329
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$_GETsuperglobal.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
- Scaling
- Scales with input
- Instructions
- 71–113
- Plugin surface
- 1 hook
- Called by
- 1
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 127.
Third-party callbacks on 'upload_per_page' run inside this call, and their cost is not bounded by anything here.
1 place 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
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.
| When | Instructions | Calls it makes |
|---|---|---|
$q !== false && !isset($q) && !current_user_can() | 71–95 | get_post_type_object(), current_user_can(), get_user_option(), apply_filters(), get_post_mime_types(), array_keys() |
$q !== false && !current_user_can() | 73–99 | get_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–99 | get_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–103 | get_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–105 | get_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–109 | get_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–109 | get_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–113 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 127 | 71–113 | 23 | |
| 8.5 | 127 | 71–113 | 23 | |
| 8.4 | 127 | 71–113 | 23 | |
| 8.3 | 127 | 71–113 | 23 | |
| 8.2 | 127 | 71–113 | 23 | |
| 8.1 | 127 | 71–113 | 23 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 129 | 71–113 | 23 |
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:
- 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
- get_post_type_object()Retrieves a post type object by name.
- current_user_can()Returns whether the current user has the specified capability.
- get_user_option()Retrieves user option that can be either per Site or per Network.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_post_mime_types()Gets default post mime types.
- get_current_user_id()Gets the current user's ID.
- add_filter()Adds a callback function to a filter hook.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.