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
434      $default_sizes = apply_filters( 'intermediate_image_sizes', array('large', 'medium', 'thumbnail') );
435
436      if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
437           $data = $backup_sizes['full-orig'];
438
439           if ( $parts['basename'] != $data['file'] ) {
440                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
441                     // delete only if it's edited image
442                     if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
443                          $delpath = apply_filters('wp_delete_file', $file);
444                          @unlink($delpath);
445                     }
446                } else {
447                     $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
448                }
449           }
450
451           $restored_file = path_join($parts['dirname'], $data['file']);
452           $restored = update_attached_file($post_id, $restored_file);
 
Line Code
459      }
460
461      foreach ( $default_sizes as $default_size ) {
462           if ( isset($backup_sizes["$default_size-orig"]) ) {
463                $data = $backup_sizes["$default_size-orig"];
464                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
465                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
466                          // delete only if it's edited image
467                          if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
468                               $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
469                               @unlink($delpath);
470                          }
471                     } else {
472                          $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
473                     }
474                }
475
476                $meta['sizes'][$default_size] = $data;
477           } else {
 
Line Code
650                     $return->thumbnail = path_join( dirname($file_url), $thumb['file'] );
651                else
652                     $return->thumbnail = "$file_url?w=128&h=128";
653           }
654      } else {
655           $delete = true;
656      }
657
658      if ( $delete ) {
659           $delpath = apply_filters('wp_delete_file', $new_path);
660           @unlink($delpath);
661      }
662
663      imagedestroy($img);
664
665      $return->msg = esc_js( __('Image saved') );
666      return $return;
667 }
668