Ensure that thumbnails are removed when the media file is deleted. Fixes #8309 props jacobsantos.
git-svn-id: https://develop.svn.wordpress.org/trunk@9846 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4c1fe59e34
commit
9b46a07ac6
|
@ -21,8 +21,8 @@
|
|||
* @since 2.0.0
|
||||
* @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID.
|
||||
*
|
||||
* @param int $attachment_id Attachment ID
|
||||
* @param bool $unfiltered Whether to apply filters or not
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @param bool $unfiltered Whether to apply filters or not.
|
||||
* @return string The file path to the attached file.
|
||||
*/
|
||||
function get_attached_file( $attachment_id, $unfiltered = false ) {
|
||||
|
@ -2418,12 +2418,14 @@ function wp_delete_attachment($postid) {
|
|||
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
||||
|
||||
$uploadPath = wp_upload_dir();
|
||||
|
||||
if ( ! empty($meta['thumb']) ) {
|
||||
// Don't delete the thumb if another attachment uses it
|
||||
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)) ) {
|
||||
$thumbfile = str_replace(basename($file), $meta['thumb'], $file);
|
||||
$thumbfile = apply_filters('wp_delete_file', $thumbfile);
|
||||
@ unlink($thumbfile);
|
||||
@ unlink( path_join($uploadPath['basedir'], $thumbfile) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2432,7 +2434,7 @@ function wp_delete_attachment($postid) {
|
|||
foreach ( $sizes as $size ) {
|
||||
if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
|
||||
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
|
||||
@ unlink($intermediate_file);
|
||||
@ unlink( path_join($uploadPath['basedir'], $intermediate_file) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue