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
574      if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
575           $data = $backup_sizes['full-orig'];
576
577           if ( $parts['basename'] != $data['file'] ) {
578                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
579                     // delete only if it's edited image
580                     if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
581
582                          /** This filter is documented in wp-admin/custom-header.php */
583                          $delpath = apply_filters( 'wp_delete_file', $file );
584                          @unlink($delpath);
585                     }
586                } elseif ( isset( $meta['width'], $meta['height'] ) ) {
587                     $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
588                }
589           }
590
591           $restored_file = path_join($parts['dirname'], $data['file']);
592           $restored = update_attached_file($post_id, $restored_file);
 
Line Code
598
599      foreach ( $default_sizes as $default_size ) {
600           if ( isset($backup_sizes["$default_size-orig"]) ) {
601                $data = $backup_sizes["$default_size-orig"];
602                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
603                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
604                          // delete only if it's edited image
605                          if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
606                               /** This filter is documented in wp-admin/custom-header.php */
607                               $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
608                               @unlink($delpath);
609                          }
610                     } else {
611                          $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
612                     }
613                }
614
615                $meta['sizes'][$default_size] = $data;
616           } else {
 
Line Code
811                }
812           }
813      } else {
814           $delete = true;
815      }
816
817      if ( $delete ) {
818
819           /** This filter is documented in wp-admin/custom-header.php */
820           $delpath = apply_filters( 'wp_delete_file', $new_path );
821           @unlink( $delpath );
822      }
823
824      $return->msg = esc_js( __('Image saved') );
825      return $return;
826 }
827