From ce4890cb3729aeb63b8840ff93bcc45781694521 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Fri, 17 Mar 2017 08:56:30 -0700 Subject: [PATCH] Display an error when attachment can't be loaded. Message needs more work. See https://github.com/xwp/wp-core-media-widgets/pull/27#discussion_r1065101 04 --- wp-admin/js/widgets/media-widgets.js | 10 +++++++--- wp-includes/widgets/class-wp-widget-image.php | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/wp-admin/js/widgets/media-widgets.js b/wp-admin/js/widgets/media-widgets.js index 7598901..4bbc405 100644 --- a/wp-admin/js/widgets/media-widgets.js +++ b/wp-admin/js/widgets/media-widgets.js @@ -152,9 +152,13 @@ wp.mediaWidgets = ( function( $ ) { attachment = new wp.media.model.Attachment( { id: control.model.get( 'attachment_id' ) } ); - attachment.fetch().done( function() { - control.selectedAttachment.set( attachment.attributes ); - } ); + attachment.fetch() + .done( function() { + control.selectedAttachment.set( attachment.attributes ); + } ) + .fail( function() { + control.selectedAttachment.set( { error: true } ); + } ); } }, diff --git a/wp-includes/widgets/class-wp-widget-image.php b/wp-includes/widgets/class-wp-widget-image.php index 9d58505..add05e9 100644 --- a/wp-includes/widgets/class-wp-widget-image.php +++ b/wp-includes/widgets/class-wp-widget-image.php @@ -33,6 +33,7 @@ public function __construct() { 'edit_media' => __( 'Edit Image' ), 'change_media' => __( 'Change Image' ), 'select_media' => __( 'Select Image' ), + 'error' => __( 'Image could not be loaded. Please verify it was not deleted.' ), ) ); } @@ -266,6 +267,10 @@ public function render_control_template_scripts() { <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #> + <# } else if ( data.attachment.error ) { #> +
+

l10n['error'] ); ?>

+
<# } #>