WordPress.org

Make WordPress Core

Ticket #17864: 17864.2.diff

File 17864.2.diff, 6.3 KB (added by scribu, 7 years ago)

cover all 'wp_delete_file' filter references

  • wp-includes/post.php

     
    37333733        delete_post_meta($post_id, '_wp_trash_meta_status');
    37343734        delete_post_meta($post_id, '_wp_trash_meta_time');
    37353735
    3736         $meta = wp_get_attachment_metadata( $post_id );
    3737         $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
    3738         $file = get_attached_file( $post_id );
    3739 
    37403736        if ( is_multisite() )
    37413737                delete_transient( 'dirsize_cache' );
    37423738
     
    37673763        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
    37683764        do_action( 'deleted_post', $post_id );
    37693765
    3770         $uploadpath = wp_upload_dir();
     3766        // Delete all the associated files
     3767        $meta = wp_get_attachment_metadata( $post_id );
     3768        $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
     3769        $file = $meta['file'];
    37713770
    37723771        if ( ! empty($meta['thumb']) ) {
    37733772                // Don't delete the thumb if another attachment uses it
    3774                 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)) ) {
    3775                         $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
    3776                         $thumbfile = apply_filters('wp_delete_file', $thumbfile);
    3777                         @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
     3773                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)) ) {
     3774                        wp_delete_file( path_join( dirname($file), $meta['thumb'] ) );
    37783775                }
    37793776        }
    37803777
    3781         // remove intermediate and backup images if there are any
    37823778        foreach ( get_intermediate_image_sizes() as $size ) {
    37833779                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) );
     3780                        wp_delete_file( $intermediate['path'] );
    37863781                }
    37873782        }
    37883783
    3789         if ( is_array($backup_sizes) ) {
     3784        if ( is_array( $backup_sizes ) ) {
    37903785                foreach ( $backup_sizes as $size ) {
    3791                         $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) );
     3786                        wp_delete_file( path_join( dirname($file), $size['file'] ) );
    37943787                }
    37953788        }
    37963789
    3797         $file = apply_filters('wp_delete_file', $file);
     3790        wp_delete_file( $file );
    37983791
    3799         if ( ! empty($file) )
    3800                 @ unlink($file);
    3801 
    38023792        clean_post_cache($post_id);
    38033793
    38043794        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?>
  • wp-admin/includes/image-edit.php

     
    440440                        if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
    441441                                // delete only if it's edited image
    442442                                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
    443                                         $delpath = apply_filters('wp_delete_file', $file);
    444                                         @unlink($delpath);
     443                                        wp_delete_file( $file );
    445444                                }
    446445                        } else {
    447446                                $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
     
    465464                                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
    466465                                        // delete only if it's edited image
    467466                                        if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
    468                                                 $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
    469                                                 @unlink($delpath);
     467                                                wp_delete_file( path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
    470468                                        }
    471469                                } else {
    472470                                        $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
     
    656654        }
    657655
    658656        if ( $delete ) {
    659                 $delpath = apply_filters('wp_delete_file', $new_path);
    660                 @unlink($delpath);
     657                wp_delete_file( $new_path );
    661658        }
    662659
    663660        imagedestroy($img);
  • wp-admin/custom-header.php

     
    722722                }
    723723
    724724                $attachment_id = absint( $_POST['attachment_id'] );
    725                 $original = get_attached_file($attachment_id);
     725                $original = get_attached_file( $attachment_id );
    726726
    727727                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
    728728                if ( is_wp_error( $cropped ) )
     
    751751
    752752                set_theme_mod('header_image', $url);
    753753
    754                 // cleanup
    755                 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
    756                 @unlink( apply_filters( 'wp_delete_file', $medium ) );
    757                 @unlink( apply_filters( 'wp_delete_file', $original ) );
     754                // Delete old files
     755                $medium = path_join( dirname($original), 'midsize-' . basename($original) );
     756                wp_delete_file( $medium );
     757                wp_delete_file( $original );
    758758
    759759                return $this->finished();
    760760        }