From 75b6e0755d004d72292c29a9703651229b39862d Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 23 Jun 2015 19:39:21 +0000 Subject: [PATCH] When filtering media by type in `wp.media.model.Attachments.filters.type()`, account for the library's `type` being an array of full mime-types. Fixes #32746. git-svn-id: https://develop.svn.wordpress.org/trunk@32915 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-models.js | 15 +++++++++++++-- src/wp-includes/js/media/models/attachments.js | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/js/media-models.js b/src/wp-includes/js/media-models.js index 4bc7f61c65..90a17e94d2 100644 --- a/src/wp-includes/js/media-models.js +++ b/src/wp-includes/js/media-models.js @@ -895,8 +895,19 @@ var Attachments = Backbone.Collection.extend({ * @returns {Boolean} */ type: function( attachment ) { - var type = this.props.get('type'); - return ! type || -1 !== type.indexOf( attachment.get('type') ); + var type = this.props.get('type'), atts = attachment.toJSON(), mime, found; + + mime = atts.mime || ( atts.file && atts.file.type ) || ''; + + if ( _.isArray( type ) ) { + found = _.find( type, function (t) { + return -1 !== mime.indexOf( t ); + } ); + } else { + found = ! type || -1 !== mime.indexOf( type ); + } + + return found; }, /** * @static diff --git a/src/wp-includes/js/media/models/attachments.js b/src/wp-includes/js/media/models/attachments.js index 5f0f26d618..9b6e86cd2f 100644 --- a/src/wp-includes/js/media/models/attachments.js +++ b/src/wp-includes/js/media/models/attachments.js @@ -491,8 +491,19 @@ var Attachments = Backbone.Collection.extend({ * @returns {Boolean} */ type: function( attachment ) { - var type = this.props.get('type'); - return ! type || -1 !== type.indexOf( attachment.get('type') ); + var type = this.props.get('type'), atts = attachment.toJSON(), mime, found; + + mime = atts.mime || ( atts.file && atts.file.type ) || ''; + + if ( _.isArray( type ) ) { + found = _.find( type, function (t) { + return -1 !== mime.indexOf( t ); + } ); + } else { + found = ! type || -1 !== mime.indexOf( type ); + } + + return found; }, /** * @static