Widgets: Fix Gallery Widget preview after an image is deleted.

The Gallery Widget incorrectly tried to include the deleted image in the preview.

Props westonruter, janak007, afercia, mrasharirfan.
Fixes #43139.



git-svn-id: https://develop.svn.wordpress.org/trunk@44661 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2019-01-21 04:12:10 +00:00
parent 3ea21b66d8
commit 02422aab1d

View File

@ -176,15 +176,15 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
?>
<script type="text/html" id="tmpl-wp-media-widget-gallery-preview">
<# var describedById = 'describedBy-' + String( Math.random() ); #>
<# if ( data.ids.length ) { #>
<#
var ids = _.filter( data.ids, function( id ) {
return ( id in data.attachments );
} );
#>
<# if ( ids.length ) { #>
<div class="gallery media-widget-gallery-preview">
<# _.each( data.ids, function( id, index ) { #>
<#
var attachment = data.attachments[ id ];
if ( ! attachment ) {
return;
}
#>
<# _.each( ids, function( id, index ) { #>
<# var attachment = data.attachments[ id ]; #>
<# if ( index < 6 ) { #>
<dl class="gallery-item">
<dt class="gallery-icon">
@ -193,9 +193,9 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
<# } else { #>
<img src="{{ attachment.url }}" alt="" />
<# } #>
<# if ( index === 5 && data.ids.length > 6 ) { #>
<# if ( index === 5 && ids.length > 6 ) { #>
<div class="gallery-icon-placeholder">
<p class="gallery-icon-placeholder-text">+{{ data.ids.length - 5 }}</p>
<p class="gallery-icon-placeholder-text">+{{ ids.length - 5 }}</p>
</div>
<# } #>
</dt>