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
696
697                /**
698                 * Fires after the header image is set or an error is returned.
699                 *
700                 * @since 2.1.0
701                 *
702                 * @param string $file          Path to the file.
703                 * @param int    $attachment_id Attachment ID.
704                 */
705                do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
706
707                return $this->finished();
708           } elseif ( $width > $max_width ) {
709                $oitar = $width / $max_width;
710                $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
711                if ( ! $image || is_wp_error( $image ) )
712                     wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
713
714                /** This filter is documented in wp-admin/custom-header.php */
715                $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
716
717                $url = str_replace(basename($url), basename($image), $url);
718                $width = $width / $oitar;
719                $height = $height / $oitar;
720           } else {
721                $oitar = 1;
722           }
723           ?>
724
 
Line Code
847           elseif ( ! empty( $_POST['create-new-attachment'] ) )
848                $cropped = _copy_image_file( $attachment_id );
849           else
850                $cropped = get_attached_file( $attachment_id );
851
852           if ( ! $cropped || is_wp_error( $cropped ) )
853                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
854
855           /** This filter is documented in wp-admin/custom-header.php */
856           $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
857
858           $parent = get_post($attachment_id);
859           $parent_url = $parent->guid;
860           $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
861
862           $size = @getimagesize( $cropped );
863           $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
864
865           // Construct the object array