WordPress.org

Make WordPress Core

Ticket #10492: wp_delete_attachment.diff

File wp_delete_attachment.diff, 1.2 KB (added by simonwheatley, 5 years ago)

Corrects indexes to access thumbnail metadata in wp_delete_attachment

  • Users/simon/Projects/StephenFry/site/wordpress/wp-includes/post.php

     
    26032603 
    26042604        $uploadPath = wp_upload_dir(); 
    26052605 
    2606         if ( ! empty($meta['thumb']) ) { 
     2606        if ( ! empty($meta['sizes']['thumbnail']) ) { 
    26072607                // Don't delete the thumb if another attachment uses it 
    2608                 if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%'.$meta['thumb'].'%', $postid)) ) { 
    2609                         $thumbfile = str_replace(basename($file), $meta['thumb'], $file); 
     2608                if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%'.$meta['sizes']['thumbnail']['file'].'%', $postid)) ) { 
     2609                        $thumbfile = str_replace(basename($file), $meta['sizes']['thumbnail']['file'], $file); 
    26102610                        $thumbfile = apply_filters('wp_delete_file', $thumbfile); 
    26112611                        @ unlink( path_join($uploadPath['basedir'], $thumbfile) ); 
    26122612                }