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