Merge pull request #9689 from woothemes/issue-9681/lingering-gallery-images

Fix lingering product gallery attachment ids when delete from media f…
This commit is contained in:
Claudio Sanches 2015-11-24 18:07:22 -02:00
commit 85ae4934de
1 changed files with 20 additions and 1 deletions

View File

@ -38,14 +38,33 @@ class WC_Meta_Box_Product_Images {
$attachments = array_filter( explode( ',', $product_image_gallery ) );
$update_meta = false;
if ( ! empty( $attachments ) ) {
foreach ( $attachments as $attachment_id ) {
$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
// if attachment is empty skip
if ( empty( $attachment ) ) {
$update_meta = true;
continue;
}
echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '
' . $attachment . '
<ul class="actions">
<li><a href="#" class="delete tips" data-tip="' . esc_attr__( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a></li>
</ul>
</li>';
// rebuild ids to be saved
$updated_gallery_ids[] = $attachment_id;
}
// need to update product meta to set new gallery ids
if ( $update_meta ) {
update_post_meta( $post->ID, '_product_image_gallery', implode( ',', $updated_gallery_ids ) );
}
}
?>