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 4 times in this file.

Line Code
771
772                /**
773                 * Fires after the header image is set or an error is returned.
774                 *
775                 * @since 2.1.0
776                 *
777                 * @param string $file          Path to the file.
778                 * @param int    $attachment_id Attachment ID.
779                 */
780                do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
781
782                return $this->finished();
783           } elseif ( $width > $max_width ) {
784                $oitar = $width / $max_width;
785                $image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
786                if ( ! $image || is_wp_error( $image ) )
787                     wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
788
789                /** This filter is documented in wp-admin/custom-header.php */
790                $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
791
792                $url = str_replace(basename($url), basename($image), $url);
793                $width = $width / $oitar;
794                $height = $height / $oitar;
795           } else {
796                $oitar = 1;
797           }
798           ?>
799
 
Line Code
917           elseif ( ! empty( $_POST['create-new-attachment'] ) )
918                $cropped = _copy_image_file( $attachment_id );
919           else
920                $cropped = get_attached_file( $attachment_id );
921
922           if ( ! $cropped || is_wp_error( $cropped ) )
923                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
924
925           /** This filter is documented in wp-admin/custom-header.php */
926           $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
927
928           $object = $this->create_attachment_object( $cropped, $attachment_id );
929
930           if ( ! empty( $_POST['create-new-attachment'] ) )
931                unset( $object['ID'] );
932
933           // Update the attachment
934           $attachment_id = $this->insert_attachment( $object, $cropped );
935
 
Line Code
1235                (int) $dimensions['dst_width'],
1236                (int) $dimensions['dst_height']
1237           );
1238
1239           if ( ! $cropped || is_wp_error( $cropped ) ) {
1240                wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) );
1241           }
1242
1243           /** This filter is documented in wp-admin/custom-header.php */
1244           $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
1245
1246           $object = $this->create_attachment_object( $cropped, $attachment_id );
1247
1248           unset( $object['ID'] );
1249
1250           $new_attachment_id = $this->insert_attachment( $object, $cropped );
1251
1252           $object['attachment_id'] = $new_attachment_id;
1253           $object['url']           = wp_get_attachment_url( $new_attachment_id );;