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
394      $default_sizes = get_intermediate_image_sizes();
395
396      if ( isset($backup_sizes['full-orig']) && is_array($backup_sizes['full-orig']) ) {
397           $data = $backup_sizes['full-orig'];
398
399           if ( $parts['basename'] != $data['file'] ) {
400                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
401                     // delete only if it's edited image
402                     if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
403                          $delpath = apply_filters('wp_delete_file', $file);
404                          @unlink($delpath);
405                     }
406                } else {
407                     $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
408                }
409           }
410
411           $restored_file = path_join($parts['dirname'], $data['file']);
412           $restored = update_attached_file($post_id, $restored_file);
 
Line Code
419      }
420
421      foreach ( $default_sizes as $default_size ) {
422           if ( isset($backup_sizes["$default_size-orig"]) ) {
423                $data = $backup_sizes["$default_size-orig"];
424                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
425                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
426                          // delete only if it's edited image
427                          if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
428                               $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
429                               @unlink($delpath);
430                          }
431                     } else {
432                          $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
433                     }
434                }
435
436                $meta['sizes'][$default_size] = $data;
437           } else {
 
Line Code
610                     $return->thumbnail = path_join( dirname($file_url), $thumb['file'] );
611                else
612                     $return->thumbnail = "$file_url?w=128&h=128";
613           }
614      } else {
615           $delete = true;
616      }
617
618      if ( $delete ) {
619           $delpath = apply_filters('wp_delete_file', $new_path);
620           @unlink($delpath);
621      }
622
623      imagedestroy($img);
624
625      $return->msg = esc_js( __('Image saved') );
626      return $return;
627 }
628