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
490      $default_sizes = get_intermediate_image_sizes();
491
492      if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
493           $data = $backup_sizes['full-orig'];
494
495           if ( $parts['basename'] != $data['file'] ) {
496                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
497                     // delete only if it's edited image
498                     if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
499                          $delpath = apply_filters('wp_delete_file', $file);
500                          @unlink($delpath);
501                     }
502                } else {
503                     $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
504                }
505           }
506
507           $restored_file = path_join($parts['dirname'], $data['file']);
508           $restored = update_attached_file($post_id, $restored_file);
 
Line Code
513      }
514
515      foreach ( $default_sizes as $default_size ) {
516           if ( isset($backup_sizes["$default_size-orig"]) ) {
517                $data = $backup_sizes["$default_size-orig"];
518                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
519                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
520                          // delete only if it's edited image
521                          if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
522                               $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
523                               @unlink($delpath);
524                          }
525                     } else {
526                          $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
527                     }
528                }
529
530                $meta['sizes'][$default_size] = $data;
531           } else {
 
Line Code
713                     else
714                          $return->thumbnail = "$file_url?w=128&h=128";
715                }
716           }
717      } else {
718           $delete = true;
719      }
720
721      if ( $delete ) {
722           $delpath = apply_filters('wp_delete_file', $new_path);
723           @unlink( $delpath );
724      }
725
726      $return->msg = esc_js( __('Image saved') );
727      return $return;
728 }
729