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