Make a new function, wp_delete_file()
. Use it.
Props scribu, wonderboymusic. Fixes #17864. git-svn-id: https://develop.svn.wordpress.org/trunk@31575 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
65c58832cb
commit
212d6d8046
@ -882,19 +882,11 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
|||||||
// Cleanup.
|
// Cleanup.
|
||||||
$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
|
$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
|
||||||
if ( file_exists( $medium ) ) {
|
if ( file_exists( $medium ) ) {
|
||||||
/**
|
wp_delete_file( $medium );
|
||||||
* Filter the path of the file to delete.
|
|
||||||
*
|
|
||||||
* @since 2.1.0
|
|
||||||
*
|
|
||||||
* @param string $medium Path to the file to delete.
|
|
||||||
*/
|
|
||||||
@unlink( apply_filters( 'wp_delete_file', $medium ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
|
if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
wp_delete_file( $original );
|
||||||
@unlink( apply_filters( 'wp_delete_file', $original ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->finished();
|
return $this->finished();
|
||||||
|
@ -616,10 +616,7 @@ function wp_restore_image($post_id) {
|
|||||||
|
|
||||||
// Delete only if it's edited image.
|
// Delete only if it's edited image.
|
||||||
if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
|
if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
|
||||||
|
wp_delete_file( $file );
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
|
||||||
$delpath = apply_filters( 'wp_delete_file', $file );
|
|
||||||
@unlink($delpath);
|
|
||||||
}
|
}
|
||||||
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
|
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
|
||||||
$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
|
$backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
|
||||||
@ -642,9 +639,8 @@ function wp_restore_image($post_id) {
|
|||||||
|
|
||||||
// Delete only if it's edited image
|
// Delete only if it's edited image
|
||||||
if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
|
if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
$delete_file = path_join( $parts['dirname'], $meta['sizes'][$default_size]['file'] );
|
||||||
$delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
|
wp_delete_file( $delete_file );
|
||||||
@unlink($delpath);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
|
$backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
|
||||||
@ -857,10 +853,7 @@ function wp_save_image( $post_id ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $delete ) {
|
if ( $delete ) {
|
||||||
|
wp_delete_file( $new_path );
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
|
||||||
$delpath = apply_filters( 'wp_delete_file', $new_path );
|
|
||||||
@unlink( $delpath );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$return->msg = esc_js( __('Image saved') );
|
$return->msg = esc_js( __('Image saved') );
|
||||||
|
@ -4813,3 +4813,24 @@ function wp_validate_boolean( $var ) {
|
|||||||
|
|
||||||
return (bool) $var;
|
return (bool) $var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a file
|
||||||
|
*
|
||||||
|
* @since 4.2.0
|
||||||
|
*
|
||||||
|
* @param string $file The path to the file to delete.
|
||||||
|
*/
|
||||||
|
function wp_delete_file( $file ) {
|
||||||
|
/**
|
||||||
|
* Filter the path of the file to delete.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*
|
||||||
|
* @param string $medium Path to the file to delete.
|
||||||
|
*/
|
||||||
|
$delete = apply_filters( 'wp_delete_file', $file );
|
||||||
|
if ( ! empty( $delete ) ) {
|
||||||
|
@unlink( $delete );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4847,7 +4847,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
|
|||||||
// 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", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id)) ) {
|
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)) ) {
|
||||||
$thumbfile = str_replace(basename($file), $meta['thumb'], $file);
|
$thumbfile = str_replace(basename($file), $meta['thumb'], $file);
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
/** This filter is documented in wp-includes/functions.php */
|
||||||
$thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
|
$thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
|
||||||
@ unlink( path_join($uploadpath['basedir'], $thumbfile) );
|
@ unlink( path_join($uploadpath['basedir'], $thumbfile) );
|
||||||
}
|
}
|
||||||
@ -4857,7 +4857,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
|
|||||||
if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
|
if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
|
||||||
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
||||||
$intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
|
$intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
/** This filter is documented in wp-includes/functions.php */
|
||||||
$intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
|
$intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
|
||||||
@ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
|
@ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
|
||||||
}
|
}
|
||||||
@ -4866,17 +4866,13 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
|
|||||||
if ( is_array($backup_sizes) ) {
|
if ( is_array($backup_sizes) ) {
|
||||||
foreach ( $backup_sizes as $size ) {
|
foreach ( $backup_sizes as $size ) {
|
||||||
$del_file = path_join( dirname($meta['file']), $size['file'] );
|
$del_file = path_join( dirname($meta['file']), $size['file'] );
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
/** This filter is documented in wp-includes/functions.php */
|
||||||
$del_file = apply_filters( 'wp_delete_file', $del_file );
|
$del_file = apply_filters( 'wp_delete_file', $del_file );
|
||||||
@ unlink( path_join($uploadpath['basedir'], $del_file) );
|
@ unlink( path_join($uploadpath['basedir'], $del_file) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
wp_delete_file( $file );
|
||||||
$file = apply_filters( 'wp_delete_file', $file );
|
|
||||||
|
|
||||||
if ( ! empty($file) )
|
|
||||||
@ unlink($file);
|
|
||||||
|
|
||||||
clean_post_cache( $post );
|
clean_post_cache( $post );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user