diff --git a/src/js/_enqueues/admin/site-icon.js b/src/js/_enqueues/admin/site-icon.js index a658f16e0b61a..49c6504156b59 100644 --- a/src/js/_enqueues/admin/site-icon.js +++ b/src/js/_enqueues/admin/site-icon.js @@ -117,6 +117,11 @@ // Grab the selected attachment. var attachment = frame.state().get( 'selection' ).first(); + if ( 'image' !== attachment.attributes.type ) { + window.alert( wp.i18n.__( 'The uploaded file is not a valid image. Please select a valid file format.' ) ); + return; + } + if ( attachment.attributes.height === $el.data( 'size' ) && $el.data( 'size' ) === attachment.attributes.width diff --git a/src/js/_enqueues/wp/customize/controls.js b/src/js/_enqueues/wp/customize/controls.js index 921983e6bf78d..f8ed7d6b666da 100644 --- a/src/js/_enqueues/wp/customize/controls.js +++ b/src/js/_enqueues/wp/customize/controls.js @@ -4571,6 +4571,11 @@ onSelect: function() { var attachment = this.frame.state().get( 'selection' ).first().toJSON(); + if ( 'image' !== attachment.type ) { + window.alert( wp.i18n.__( 'The uploaded file is not a valid image. Please select a valid file format.' ) ); + return; + } + if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) { this.setImageFromAttachment( attachment ); this.frame.close(); @@ -4791,6 +4796,11 @@ var attachment = this.frame.state().get( 'selection' ).first().toJSON(), controller = this; + if ( 'image' !== attachment.type ) { + window.alert( wp.i18n.__( 'The uploaded file is not a valid image. Please select a valid file format.' ) ); + return; + } + if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) { wp.ajax.post( 'crop-image', { nonce: attachment.nonces.edit, @@ -5060,6 +5070,13 @@ * switch to the cropper state. */ onSelect: function() { + var attachment = this.frame.state().get( 'selection' ).first().toJSON(); + + if ( 'image' !== attachment.type ) { + window.alert( wp.i18n.__( 'The uploaded file is not a valid image. Please select a valid file format.' ) ); + return; + } + this.frame.setState('cropper'); },