Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Commit

Permalink
Display an error when attachment can't be loaded.
Browse files Browse the repository at this point in the history
Message needs more work.

See
#27 (comment)
04
  • Loading branch information
obenland committed Mar 17, 2017
1 parent 27d0d04 commit ce4890c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wp-admin/js/widgets/media-widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
} );
}
},

Expand Down
5 changes: 5 additions & 0 deletions wp-includes/widgets/class-wp-widget-image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.' ),
) );
}

Expand Down Expand Up @@ -266,6 +267,10 @@ public function render_control_template_scripts() {
<img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" alt="" />
<# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #>
<img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" alt="" />
<# } else if ( data.attachment.error ) { #>
<div class="notice notice-error notice-alt">
<p><?php echo esc_html( $this->l10n['error'] ); ?></p>
</div>
<# } #>
</script>
<?php
Expand Down

0 comments on commit ce4890c

Please sign in to comment.