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
2446
2447      $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
2448
2449      $uploadPath = wp_upload_dir();
2450
2451      if ( ! empty($meta['thumb']) ) {
2452           // Don't delete the thumb if another attachment uses it
2453           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'].'%', $postid)) ) {
2454                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
2455                $thumbfile = apply_filters('wp_delete_file', $thumbfile);
2456                @ unlink( path_join($uploadPath['basedir'], $thumbfile) );
2457           }
2458      }
2459
2460      // remove intermediate images if there are any
2461      $sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium', 'large'));
2462      foreach ( $sizes as $size ) {
2463           if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
2464                $intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
2465                @ unlink( path_join($uploadPath['basedir'], $intermediate_file) );
2466           }
2467      }
2468
2469      $file = apply_filters('wp_delete_file', $file);
2470
2471      if ( ! empty($file) )
2472           @ unlink($file);
2473
2474      clean_post_cache($postid);
2475
2476      do_action('delete_attachment', $postid);
2477
2478      return $post;