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
717           if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' )
718                && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) )
719           {
720                // Add the meta-data
721                if ( file_exists( $file ) )
722                     wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
723
724                $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
725
726                do_action('wp_create_file_in_uploads', $file, $attachment_id); // For replication
727                return $this->finished();
728           } elseif ( $width > $max_width ) {
729                $oitar = $width / $max_width;
730                $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
731                if ( ! $image || is_wp_error( $image ) )
732                     wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
733
734                $image = apply_filters('wp_create_file_in_uploads', $image, $attachment_id); // For replication
735
736                $url = str_replace(basename($url), basename($image), $url);
737                $width = $width / $oitar;
738                $height = $height / $oitar;
739           } else {
740                $oitar = 1;
741           }
742           ?>
743
 
Line Code
857                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
858           elseif ( ! empty( $_POST['create-new-attachment'] ) )
859                $cropped = _copy_image_file( $attachment_id );
860           else
861                $cropped = get_attached_file( $attachment_id );
862
863           if ( ! $cropped || is_wp_error( $cropped ) )
864                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
865
866           $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
867
868           $parent = get_post($attachment_id);
869           $parent_url = $parent->guid;
870           $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
871
872           $size = @getimagesize( $cropped );
873           $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
874
875           // Construct the object array