WordPress.org

Make WordPress Core

Ticket #17864: 17864.diff

File 17864.diff, 3.3 KB (added by scribu, 10 years ago)

first pass, covering wp_delete_attachment()

  • wp-includes/post.php

     
    37353735
    37363736        $meta = wp_get_attachment_metadata( $post_id );
    37373737        $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
    3738         $file = get_attached_file( $post_id );
     3738        $file = $meta['file'];
    37393739
    37403740        if ( is_multisite() )
    37413741                delete_transient( 'dirsize_cache' );
     
    37673767        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
    37683768        do_action( 'deleted_post', $post_id );
    37693769
    3770         $uploadpath = wp_upload_dir();
    3771 
    37723770        if ( ! empty($meta['thumb']) ) {
    37733771                // Don't delete the thumb if another attachment uses it
    37743772                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'] . '%', $post_id)) ) {
    37753773                        $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
    3776                         $thumbfile = apply_filters('wp_delete_file', $thumbfile);
    3777                         @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
     3774                        wp_delete_file( $thumbfile );
    37783775                }
    37793776        }
    37803777
    37813778        // remove intermediate and backup images if there are any
    37823779        foreach ( get_intermediate_image_sizes() as $size ) {
    37833780                if ( $intermediate = image_get_intermediate_size($post_id, $size) ) {
    3784                         $intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
    3785                         @ unlink( path_join($uploadpath['basedir'], $intermediate_file) );
     3781                        wp_delete_file( $intermediate['path'] );
    37863782                }
    37873783        }
    37883784
    3789         if ( is_array($backup_sizes) ) {
     3785        if ( is_array( $backup_sizes ) ) {
    37903786                foreach ( $backup_sizes as $size ) {
    37913787                        $del_file = path_join( dirname($meta['file']), $size['file'] );
    3792                         $del_file = apply_filters('wp_delete_file', $del_file);
    3793                         @ unlink( path_join($uploadpath['basedir'], $del_file) );
     3788                        wp_delete_file( $del_file );
    37943789                }
    37953790        }
    37963791
    3797         $file = apply_filters('wp_delete_file', $file);
     3792        wp_delete_file( $file );
    37983793
    3799         if ( ! empty($file) )
    3800                 @ unlink($file);
    3801 
    38023794        clean_post_cache($post_id);
    38033795
    38043796        return $post;
  • wp-includes/media.php

     
    669669}
    670670
    671671/**
     672 * Applies the 'wp_delete_file' filter before deleting the file
     673 *
     674 * @since 3.3
     675 *
     676 * @param string $file A file path, absolute or relative to the wp-uploads directory
     677 */
     678function wp_delete_file( $file ) {
     679        $file = apply_filters( 'wp_delete_file', $file );
     680
     681        if ( !empty( $file ) ) {
     682                $wud = wp_upload_dir();
     683                @unlink( path_join( $wud['basedir'], $file ) );
     684        }
     685}
     686
     687/**
    672688 * Adds a 'wp-post-image' class to post thumbnail thumbnails
    673689 * Uses the begin_fetch_post_thumbnail_html and end_fetch_post_thumbnail_html action hooks to
    674690 * dynamically add/remove itself so as to only filter post thumbnail thumbnails
     
    14381454        return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&amp;hl=en&amp;fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
    14391455}
    14401456
    1441 ?>
    1442  No newline at end of file
     1457?>