Respect query vars for taxonomies passed as URL parameters when in grid mode of Media Library.

Fixes #30584.


git-svn-id: https://develop.svn.wordpress.org/trunk@31037 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-01-03 08:23:06 +00:00
parent fdef2cc755
commit 5df9963414
4 changed files with 51 additions and 20 deletions

View File

@@ -1021,32 +1021,34 @@ function get_available_post_mime_types($type = 'attachment') {
}
/**
* Executes a query for attachments. An array of WP_Query arguments
* can be passed in, which will override the arguments set by this function.
* Get the query vars for the current attachments request
*
* @since 2.5.0
* @since 4.2.0
*
* @param array|bool $q Array of query variables to use to build the query or false to use $_GET superglobal.
* @return array
* @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
*
* @return array The parsed query vars.
*/
function wp_edit_attachments_query( $q = false ) {
if ( false === $q )
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 ) )
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 )
if ( empty( $media_per_page ) || $media_per_page < 1 ) {
$media_per_page = 20;
}
/**
* Filter the number of items to list per page when listing media items.
@@ -1058,10 +1060,9 @@ function wp_edit_attachments_query( $q = false ) {
$q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page );
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types('attachment');
if ( isset($q['post_mime_type']) && !array_intersect( (array) $q['post_mime_type'], array_keys($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'] ) {
@@ -1074,9 +1075,25 @@ function wp_edit_attachments_query( $q = false ) {
$q['post_parent'] = 0;
}
wp( $q );
return $q;
}
return array($post_mime_types, $avail_post_mime_types);
/**
* Executes a query for attachments. An array of WP_Query arguments
* can be passed in, which will override the arguments set by this function.
*
* @since 2.5.0
*
* @param array|false $q Array of query variables to use to build the query or false to use $_GET superglobal.
* @return array
*/
function wp_edit_attachments_query( $q = false ) {
wp( wp_edit_attachments_query_vars( $q ) );
$post_mime_types = get_post_mime_types();
$avail_post_mime_types = get_available_post_mime_types( 'attachment' );
return array( $post_mime_types, $avail_post_mime_types );
}
/**