mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-02 05:31:25 +01:00
Ensure that thumbnails are removed when the media file is deleted. Fixes #8309 props jacobsantos.
git-svn-id: http://svn.automattic.com/wordpress/trunk@9846 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
9f3add6a4a
commit
f92c019881
@ -21,8 +21,8 @@
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
* @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID.
|
* @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID.
|
||||||
*
|
*
|
||||||
* @param int $attachment_id Attachment ID
|
* @param int $attachment_id Attachment ID.
|
||||||
* @param bool $unfiltered Whether to apply filters or not
|
* @param bool $unfiltered Whether to apply filters or not.
|
||||||
* @return string The file path to the attached file.
|
* @return string The file path to the attached file.
|
||||||
*/
|
*/
|
||||||
function get_attached_file( $attachment_id, $unfiltered = false ) {
|
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 ));
|
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
|
||||||
|
|
||||||
|
$uploadPath = wp_upload_dir();
|
||||||
|
|
||||||
if ( ! empty($meta['thumb']) ) {
|
if ( ! empty($meta['thumb']) ) {
|
||||||
// Don't delete the thumb if another attachment uses it
|
// 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)) ) {
|
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 = str_replace(basename($file), $meta['thumb'], $file);
|
||||||
$thumbfile = apply_filters('wp_delete_file', $thumbfile);
|
$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 ) {
|
foreach ( $sizes as $size ) {
|
||||||
if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
|
if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
|
||||||
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
|
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
|
||||||
@ unlink($intermediate_file);
|
@ unlink( path_join($uploadPath['basedir'], $intermediate_file) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user