WordPress.org

Make WordPress Core

Ticket #39476: 39476.diff

File 39476.diff, 1.9 KB (added by rmccue, 3 years ago)

Use wp_delete_file() in wp_delete_attachment

  • src/wp-includes/post.php

     
    49194919        if ( ! empty($meta['thumb']) ) {
    49204920                // Don't delete the thumb if another attachment uses it.
    49214921                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", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) {
    4922                         $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
    4923                         /** This filter is documented in wp-includes/functions.php */
    4924                         $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
    4925                         @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
     4922                        $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file );
     4923                        wp_delete_file( path_join( $uploadpath['basedir'], $thumbfile ) );
    49264924                }
    49274925        }
    49284926
     
    49304928        if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
    49314929                foreach ( $meta['sizes'] as $size => $sizeinfo ) {
    49324930                        $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
    4933                         /** This filter is documented in wp-includes/functions.php */
    4934                         $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
    4935                         @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
     4931                        wp_delete_file( path_join( $uploadpath['basedir'], $intermediate_file ) );
    49364932                }
    49374933        }
    49384934
     
    49394935        if ( is_array($backup_sizes) ) {
    49404936                foreach ( $backup_sizes as $size ) {
    49414937                        $del_file = path_join( dirname($meta['file']), $size['file'] );
    4942                         /** This filter is documented in wp-includes/functions.php */
    4943                         $del_file = apply_filters( 'wp_delete_file', $del_file );
    4944                         @ unlink( path_join($uploadpath['basedir'], $del_file) );
     4938                        wp_delete_file( path_join( $uploadpath['basedir'], $del_file ) );
    49454939                }
    49464940        }
    49474941