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:
parent
fdef2cc755
commit
5df9963414
@ -2159,11 +2159,17 @@ function wp_ajax_query_attachments() {
|
||||
wp_send_json_error();
|
||||
|
||||
$query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array();
|
||||
$query = array_intersect_key( $query, array_flip( array(
|
||||
$keys = array(
|
||||
's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type',
|
||||
'post_parent', 'post__in', 'post__not_in', 'year', 'monthnum'
|
||||
) ) );
|
||||
);
|
||||
foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) {
|
||||
if ( $t->query_var && isset( $query[ $t->query_var ] ) ) {
|
||||
$keys[] = $t->query_var;
|
||||
}
|
||||
}
|
||||
|
||||
$query = array_intersect_key( $query, array_flip( $keys ) );
|
||||
$query['post_type'] = 'attachment';
|
||||
if ( MEDIA_TRASH
|
||||
&& ! empty( $_REQUEST['query']['post_status'] )
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* global ajaxurl, attachMediaBoxL10n */
|
||||
/* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings */
|
||||
|
||||
var findPosts;
|
||||
( function( $ ){
|
||||
@ -72,13 +72,16 @@ var findPosts;
|
||||
};
|
||||
|
||||
$( document ).ready( function() {
|
||||
var $mediaGridWrap = $( '#wp-media-grid' );
|
||||
var settings, $mediaGridWrap = $( '#wp-media-grid' );
|
||||
|
||||
// Open up a manage media frame into the grid.
|
||||
if ( $mediaGridWrap.length && window.wp && window.wp.media ) {
|
||||
settings = _wpMediaGridSettings;
|
||||
|
||||
window.wp.media({
|
||||
frame: 'manage',
|
||||
container: $mediaGridWrap
|
||||
container: $mediaGridWrap,
|
||||
library: settings.queryVars
|
||||
}).open();
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,13 @@ if ( 'grid' === $mode ) {
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script( 'media-grid' );
|
||||
wp_enqueue_script( 'media' );
|
||||
|
||||
$vars = wp_edit_attachments_query_vars();
|
||||
unset( $vars['mode'], $vars['post_type'], $vars['post_status'], $vars['posts_per_page'] );
|
||||
|
||||
wp_localize_script( 'media-grid', '_wpMediaGridSettings', array(
|
||||
'adminUrl' => parse_url( self_admin_url(), PHP_URL_PATH ),
|
||||
'queryVars' => $vars
|
||||
) );
|
||||
|
||||
get_current_screen()->add_help_tab( array(
|
||||
|
Loading…
Reference in New Issue
Block a user