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
3806      $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
3807      do_action( 'deleted_post', $post_id );
3808
3809      $uploadpath = wp_upload_dir();
3810
3811      if ( ! empty($meta['thumb']) ) {
3812           // Don't delete the thumb if another attachment uses it
3813           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)) ) {
3814                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
3815                $thumbfile = apply_filters('wp_delete_file', $thumbfile);
3816                @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
3817           }
3818      }
3819
3820      // remove intermediate and backup images if there are any
3821      foreach ( get_intermediate_image_sizes() as $size ) {
3822           if ( $intermediate = image_get_intermediate_size($post_id, $size) ) {
3823                $intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
3824                @ unlink( path_join($uploadpath['basedir'], $intermediate_file) );
3825           }
3826      }
3827
3828      if ( is_array($backup_sizes) ) {
3829           foreach ( $backup_sizes as $size ) {
3830                $del_file = path_join( dirname($meta['file']), $size['file'] );
3831                $del_file = apply_filters('wp_delete_file', $del_file);
3832                @ unlink( path_join($uploadpath['basedir'], $del_file) );
3833           }
3834      }
3835
3836      $file = apply_filters('wp_delete_file', $file);
3837
3838      if ( ! empty($file) )
3839           @ unlink($file);
3840
3841      clean_post_cache($post_id);
3842
3843      return $post;
3844 }
3845