Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: wp_delete_file

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 3 times in this file.

Line Code
4998      do_action( 'deleted_post', $post_id );
4999
5000      $uploadpath = wp_get_upload_dir();
5001
5002      if ( ! empty($meta['thumb']) ) {
5003           // Don't delete the thumb if another attachment uses it.
5004           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)) ) {
5005                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
5006                /** This filter is documented in wp-includes/functions.php */
5007                $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
5008                @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
5009           }
5010      }
5011
5012      // Remove intermediate and backup images if there are any.
5013      if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
5014           foreach ( $meta['sizes'] as $size => $sizeinfo ) {
5015                $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
5016                /** This filter is documented in wp-includes/functions.php */
5017                $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
5018                @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
5019           }
5020      }
5021
5022      if ( is_array($backup_sizes) ) {
5023           foreach ( $backup_sizes as $size ) {
5024                $del_file = path_join( dirname($meta['file']), $size['file'] );
5025                /** This filter is documented in wp-includes/functions.php */
5026                $del_file = apply_filters( 'wp_delete_file', $del_file );
5027                @ unlink( path_join($uploadpath['basedir'], $del_file) );
5028           }
5029      }
5030
5031      wp_delete_file( $file );
5032
5033      clean_post_cache( $post );
5034
5035      return $post;