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
876
877                /**
878                 * Fires after the header image is set or an error is returned.
879                 *
880                 * @since 2.1.0
881                 *
882                 * @param string $file          Path to the file.
883                 * @param int    $attachment_id Attachment ID.
884                 */
885                do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication.
886
887                return $this->finished();
888           } elseif ( $width > $max_width ) {
889                $oitar = $width / $max_width;
890
891                $image = wp_crop_image(
892                     $attachment_id,
893                     0,
894                     0,
 
Line Code
899                     false,
900                     str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file )
901                );
902
903                if ( ! $image || is_wp_error( $image ) ) {
904                     wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
905                }
906
907                /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
908                $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication.
909
910                $url    = str_replace( wp_basename( $url ), wp_basename( $image ), $url );
911                $width  = $width / $oitar;
912                $height = $height / $oitar;
913           } else {
914                $oitar = 1;
915           }
916           ?>
917
 
Line Code
1058           } else {
1059                $cropped = get_attached_file( $attachment_id );
1060           }
1061
1062           if ( ! $cropped || is_wp_error( $cropped ) ) {
1063                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
1064           }
1065
1066           /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
1067           $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
1068
1069           $attachment = $this->create_attachment_object( $cropped, $attachment_id );
1070
1071           if ( ! empty( $_POST['create-new-attachment'] ) ) {
1072                unset( $attachment['ID'] );
1073           }
1074
1075           // Update the attachment.
1076           $attachment_id = $this->insert_attachment( $attachment, $cropped );
 
Line Code
1402                (int) $dimensions['dst_width'],
1403                (int) $dimensions['dst_height']
1404           );
1405
1406           if ( ! $cropped || is_wp_error( $cropped ) ) {
1407                wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) );
1408           }
1409
1410           /** This filter is documented in wp-admin/includes/class-custom-image-header.php */
1411           $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
1412
1413           $attachment = $this->create_attachment_object( $cropped, $attachment_id );
1414
1415           $previous = $this->get_previous_crop( $attachment );
1416
1417           if ( $previous ) {
1418                $attachment['ID'] = $previous;
1419           } else {
1420                unset( $attachment['ID'] );