From baff296dfa8a97a701e4e77151770a9ba85752ad Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 8 Feb 2017 19:16:34 +0000 Subject: [PATCH] Media: in `wp.media.view.Toolbar.refresh()`, check for a selection before iterating over models. Props chandrapatel. Fixes #39511. git-svn-id: https://develop.svn.wordpress.org/trunk@40050 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-views.js | 8 +++++--- src/wp-includes/js/media/views/toolbar.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js index bb2c949c73..ae9ea8e1d0 100644 --- a/src/wp-includes/js/media-views.js +++ b/src/wp-includes/js/media-views.js @@ -7724,9 +7724,11 @@ Toolbar = View.extend({ disabled = false; // Prevent insertion of attachments if any of them are still uploading - disabled = _.some( selection.models, function( attachment ) { - return attachment.get('uploading') === true; - }); + if ( selection && selection.models ) { + disabled = _.some( selection.models, function( attachment ) { + return attachment.get('uploading') === true; + }); + } if ( requires.selection && selection && ! selection.length ) { disabled = true; diff --git a/src/wp-includes/js/media/views/toolbar.js b/src/wp-includes/js/media/views/toolbar.js index 7884a4b02d..e1884bf0a6 100644 --- a/src/wp-includes/js/media/views/toolbar.js +++ b/src/wp-includes/js/media/views/toolbar.js @@ -141,9 +141,11 @@ Toolbar = View.extend({ disabled = false; // Prevent insertion of attachments if any of them are still uploading - disabled = _.some( selection.models, function( attachment ) { - return attachment.get('uploading') === true; - }); + if ( selection && selection.models ) { + disabled = _.some( selection.models, function( attachment ) { + return attachment.get('uploading') === true; + }); + } if ( requires.selection && selection && ! selection.length ) { disabled = true;