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 4 times in this file.

Line Code
4195      do_action( 'deleted_post', $post_id );
4196
4197      $uploadpath = wp_upload_dir();
4198
4199      if ( ! empty($meta['thumb']) ) {
4200           // Don't delete the thumb if another attachment uses it
4201           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)) ) {
4202                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
4203                /** This filter is documented in wp-admin/custom-header.php */
4204                $thumbfile = apply_filters('wp_delete_file', $thumbfile);
4205                @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
4206           }
4207      }
4208
4209      // remove intermediate and backup images if there are any
4210      foreach ( $intermediate_sizes as $intermediate ) {
4211           /** This filter is documented in wp-admin/custom-header.php */
4212           $intermediate_file = apply_filters( 'wp_delete_file', $intermediate['path'] );
4213           @ unlink( path_join($uploadpath['basedir'], $intermediate_file) );
4214      }
4215
4216      if ( is_array($backup_sizes) ) {
4217           foreach ( $backup_sizes as $size ) {
4218                $del_file = path_join( dirname($meta['file']), $size['file'] );
4219                /** This filter is documented in wp-admin/custom-header.php */
4220                $del_file = apply_filters('wp_delete_file', $del_file);
4221                @ unlink( path_join($uploadpath['basedir'], $del_file) );
4222           }
4223      }
4224
4225      /** This filter is documented in wp-admin/custom-header.php */
4226      $file = apply_filters('wp_delete_file', $file);
4227
4228      if ( ! empty($file) )
4229           @ unlink($file);
4230
4231      clean_post_cache( $post );
4232
4233      return $post;
4234 }
4235