Make WordPress Core

Changeset 31575


Ignore:
Timestamp:
02/27/2015 04:50:14 PM (10 years ago)
Author:
wonderboymusic
Message:

Make a new function, wp_delete_file(). Use it.

Props scribu, wonderboymusic.
Fixes #17864.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/custom-header.php

    r31134 r31575  
    883883        $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
    884884        if ( file_exists( $medium ) ) {
    885             /**
    886              * Filter the path of the file to delete.
    887              *
    888              * @since 2.1.0
    889              *
    890              * @param string $medium Path to the file to delete.
    891              */
    892             @unlink( apply_filters( 'wp_delete_file', $medium ) );
     885            wp_delete_file( $medium );
    893886        }
    894887
    895888        if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
    896             /** This filter is documented in wp-admin/custom-header.php */
    897             @unlink( apply_filters( 'wp_delete_file', $original ) );
     889            wp_delete_file( $original );
    898890        }
    899891
  • trunk/src/wp-admin/includes/image-edit.php

    r31554 r31575  
    617617                // Delete only if it's edited image.
    618618                if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
    619 
    620                     /** This filter is documented in wp-admin/custom-header.php */
    621                     $delpath = apply_filters( 'wp_delete_file', $file );
    622                     @unlink($delpath);
     619                    wp_delete_file( $file );
    623620                }
    624621            } elseif ( isset( $meta['width'], $meta['height'] ) ) {
     
    643640                    // Delete only if it's edited image
    644641                    if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
    645                         /** This filter is documented in wp-admin/custom-header.php */
    646                         $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
    647                         @unlink($delpath);
     642                        $delete_file = path_join( $parts['dirname'], $meta['sizes'][$default_size]['file'] );
     643                        wp_delete_file( $delete_file );
    648644                    }
    649645                } else {
     
    858854
    859855    if ( $delete ) {
    860 
    861         /** This filter is documented in wp-admin/custom-header.php */
    862         $delpath = apply_filters( 'wp_delete_file', $new_path );
    863         @unlink( $delpath );
     856        wp_delete_file( $new_path );
    864857    }
    865858
  • trunk/src/wp-includes/functions.php

    r31554 r31575  
    48144814    return (bool) $var;
    48154815}
     4816
     4817/**
     4818 * Delete a file
     4819 *
     4820 * @since 4.2.0
     4821 *
     4822 * @param string $file The path to the file to delete.
     4823 */
     4824function wp_delete_file( $file ) {
     4825    /**
     4826     * Filter the path of the file to delete.
     4827     *
     4828     * @since 2.1.0
     4829     *
     4830     * @param string $medium Path to the file to delete.
     4831     */
     4832    $delete = apply_filters( 'wp_delete_file', $file );
     4833    if ( ! empty( $delete ) ) {
     4834        @unlink( $delete );
     4835    }
     4836}
  • trunk/src/wp-includes/post.php

    r31496 r31575  
    48484848        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)) ) {
    48494849            $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
    4850             /** This filter is documented in wp-admin/custom-header.php */
     4850            /** This filter is documented in wp-includes/functions.php */
    48514851            $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
    48524852            @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
     
    48584858        foreach ( $meta['sizes'] as $size => $sizeinfo ) {
    48594859            $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
    4860             /** This filter is documented in wp-admin/custom-header.php */
     4860            /** This filter is documented in wp-includes/functions.php */
    48614861            $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
    48624862            @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
     
    48674867        foreach ( $backup_sizes as $size ) {
    48684868            $del_file = path_join( dirname($meta['file']), $size['file'] );
    4869             /** This filter is documented in wp-admin/custom-header.php */
     4869            /** This filter is documented in wp-includes/functions.php */
    48704870            $del_file = apply_filters( 'wp_delete_file', $del_file );
    48714871            @ unlink( path_join($uploadpath['basedir'], $del_file) );
     
    48734873    }
    48744874
    4875     /** This filter is documented in wp-admin/custom-header.php */
    4876     $file = apply_filters( 'wp_delete_file', $file );
    4877 
    4878     if ( ! empty($file) )
    4879         @ unlink($file);
     4875    wp_delete_file( $file );
    48804876
    48814877    clean_post_cache( $post );
Note: See TracChangeset for help on using the changeset viewer.