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
4806      do_action( 'deleted_post', $post_id );
4807
4808      $uploadpath = wp_upload_dir();
4809
4810      if ( ! empty($meta['thumb']) ) {
4811           // Don't delete the thumb if another attachment uses it.
4812           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)) ) {
4813                $thumbfile = str_replace(basename($file), $meta['thumb'], $file);
4814                /** This filter is documented in wp-admin/custom-header.php */
4815                $thumbfile = apply_filters( 'wp_delete_file', $thumbfile );
4816                @ unlink( path_join($uploadpath['basedir'], $thumbfile) );
4817           }
4818      }
4819
4820      // Remove intermediate and backup images if there are any.
4821      if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
4822           foreach ( $meta['sizes'] as $size => $sizeinfo ) {
4823                $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
4824                /** This filter is documented in wp-admin/custom-header.php */
4825                $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
4826                @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
4827           }
4828      }
4829
4830      if ( is_array($backup_sizes) ) {
4831           foreach ( $backup_sizes as $size ) {
4832                $del_file = path_join( dirname($meta['file']), $size['file'] );
4833                /** This filter is documented in wp-admin/custom-header.php */
4834                $del_file = apply_filters( 'wp_delete_file', $del_file );
4835                @ unlink( path_join($uploadpath['basedir'], $del_file) );
4836           }
4837      }
4838
4839      /** This filter is documented in wp-admin/custom-header.php */
4840      $file = apply_filters( 'wp_delete_file', $file );
4841
4842      if ( ! empty($file) )
4843           @ unlink($file);
4844
4845      clean_post_cache( $post );
4846
4847      return $post;
4848 }
4849