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
584           $data = $backup_sizes['full-orig'];
585
586           if ( $parts['basename'] != $data['file'] ) {
587                if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
588
589                     // Delete only if it's edited image.
590                     if ( preg_match('/-e[0-9]{13}\./', $parts['basename']) ) {
591
592                          /** This filter is documented in wp-admin/custom-header.php */
593                          $delpath = apply_filters( 'wp_delete_file', $file );
594                          @unlink($delpath);
595                     }
596                } elseif ( isset( $meta['width'], $meta['height'] ) ) {
597                     $backup_sizes["full-$suffix"] = array('width' => $meta['width'], 'height' => $meta['height'], 'file' => $parts['basename']);
598                }
599           }
600
601           $restored_file = path_join($parts['dirname'], $data['file']);
602           $restored = update_attached_file($post_id, $restored_file);
 
Line Code
609      foreach ( $default_sizes as $default_size ) {
610           if ( isset($backup_sizes["$default_size-orig"]) ) {
611                $data = $backup_sizes["$default_size-orig"];
612                if ( isset($meta['sizes'][$default_size]) && $meta['sizes'][$default_size]['file'] != $data['file'] ) {
613                     if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE ) {
614
615                          // Delete only if it's edited image
616                          if ( preg_match('/-e[0-9]{13}-/', $meta['sizes'][$default_size]['file']) ) {
617                               /** This filter is documented in wp-admin/custom-header.php */
618                               $delpath = apply_filters( 'wp_delete_file', path_join($parts['dirname'], $meta['sizes'][$default_size]['file']) );
619                               @unlink($delpath);
620                          }
621                     } else {
622                          $backup_sizes["$default_size-{$suffix}"] = $meta['sizes'][$default_size];
623                     }
624                }
625
626                $meta['sizes'][$default_size] = $data;
627           } else {
 
Line Code
823                }
824           }
825      } else {
826           $delete = true;
827      }
828
829      if ( $delete ) {
830
831           /** This filter is documented in wp-admin/custom-header.php */
832           $delpath = apply_filters( 'wp_delete_file', $new_path );
833           @unlink( $delpath );
834      }
835
836      $return->msg = esc_js( __('Image saved') );
837      return $return;
838 }
839