Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: wp_create_file_in_uploads

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
681           if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' )
682                && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) )
683           {
684                // Add the meta-data
685                if ( file_exists( $file ) )
686                     wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
687
688                $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
689
690                do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication
691                return $this->finished();
692           } elseif ( $width > $max_width ) {
693                $oitar = $width / $max_width;
694                $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
695                if ( ! $image || is_wp_error( $image ) )
696                     wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
697
698                $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication
699
700                $url = str_replace(basename($url), basename($image), $url);
701                $width = $width / $oitar;
702                $height = $height / $oitar;
703           } else {
704                $oitar = 1;
705           }
706           ?>
707
 
Line Code
830                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
831           elseif ( ! empty( $_POST['create-new-attachment'] ) )
832                $cropped = _copy_image_file( $attachment_id );
833           else
834                $cropped = get_attached_file( $attachment_id );
835
836           if ( ! $cropped || is_wp_error( $cropped ) )
837                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
838
839           $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
840
841           $parent = get_post($attachment_id);
842           $parent_url = $parent->guid;
843           $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
844
845           $size = @getimagesize( $cropped );
846           $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
847
848           // Construct the object array