diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 69b235a33b..665ee78ab2 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1802,7 +1802,7 @@ function wp_ajax_get_attachment() { */ function wp_ajax_query_attachments() { $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array(); - $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged' ) ) ); + $query = array_intersect_key( $query, array_flip( array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type' ) ) ); $query['post_type'] = 'attachment'; $query['post_status'] = 'inherit'; diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index 7cb9a4d227..1dc88392e5 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -224,6 +224,7 @@ if ( typeof wp === 'undefined' ) this.props.on( 'change:orderby', this._changeOrderby, this ); this.props.on( 'change:query', this._changeQuery, this ); this.props.on( 'change:search', this._changeSearch, this ); + this.props.on( 'change:type', this._changeType, this ); // Set the `props` model and fill the default property values. this.props.set( _.defaults( options.props || {}, { @@ -264,15 +265,15 @@ if ( typeof wp === 'undefined' ) } }, - _changeSearch: function( model, term ) { + _changeFilteredProp: function( prop, model, term ) { // Bail if we're currently searching for the same term. - if ( this.props.get('search') === term ) + if ( this.props.get( prop ) === term ) return; - if ( term && ! this.filters.search ) - this.filters.search = Attachments.filters.search; - else if ( ! term && this.filters.search === Attachments.filters.search ) - delete this.filters.search; + if ( term && ! this.filters[ prop ] ) + this.filters[ prop ] = Attachments.filters[ prop ]; + else if ( ! term && this.filters[ prop ] === Attachments.filters[ prop ] ) + delete this.filters[ prop ]; // If no `Attachments` model is provided to source the searches // from, then automatically generate a source from the existing @@ -283,6 +284,14 @@ if ( typeof wp === 'undefined' ) this.reset( this.props.get('source').filter( this.validator ) ); }, + _changeSearch: function( model, term ) { + return this._changeFilteredProp( 'search', model, term ); + }, + + _changeType: function( model, term ) { + return this._changeFilteredProp( 'type', model, term ); + }, + validator: function( attachment ) { return _.all( this.filters, function( filter, key ) { return !! filter.call( this, attachment ); @@ -380,6 +389,14 @@ if ( typeof wp === 'undefined' ) var value = attachment.get( key ); return value && -1 !== value.search( this.props.get('search') ); }, this ); + }, + + type: function( attachment ) { + var type = this.props.get('type'); + if ( ! type ) + return true; + + return -1 !== type.indexOf( attachment.get('type') ); } } }); @@ -497,7 +514,8 @@ if ( typeof wp === 'undefined' ) }, propmap: { - 'search': 's' + 'search': 's', + 'type': 'post_mime_type' }, // Caches query objects so queries can be easily reused.