|
The following patch does not include the updates to `webp_uploads_generate_additional_image_source` to |
|
change the passed arguments from an array to a size name instead. |
|
=================================================================== |
|
|
|
diff --git a/modules/images/webp-uploads/load.php b/modules/images/webp-uploads/load.php |
|
--- a/modules/images/webp-uploads/load.php (revision 4596be0b1d3eb4faceb612b6f39d1f24c6b30dcc) |
|
+++ b/modules/images/webp-uploads/load.php (date 1647907161419) |
|
@@ -303,51 +303,65 @@ |
|
* @param string $destination_file_name The path where the file would be stored, including the extension. If empty, `generate_filename` is used to create the destination file name. |
|
* @return array|WP_Error An array with the file and filesize if the image was created correctly otherwise a WP_Error |
|
*/ |
|
-function webp_uploads_generate_additional_image_source( $attachment_id, array $size_data, $mime, $destination_file_name = null ) { |
|
- $image_path = wp_get_original_image_path( $attachment_id ); |
|
+function webp_uploads_generate_additional_image_source( $attachment_id, $size_name, $mime, $destination_file_name = null ) { |
|
+ $image = apply_filters( 'webp_uploads_file_path_additional_mime_type', null, $attachment_id, $size_name, $mime ); |
|
+ if ( $image === null ) { |
|
+ $image_path = wp_get_original_image_path( $attachment_id ); |
|
|
|
- // File does not exist. |
|
- if ( ! file_exists( $image_path ) ) { |
|
- return new WP_Error( 'original_image_file_not_found', __( 'The original image file does not exists, subsizes are created out of the original image.', 'performance-lab' ) ); |
|
- } |
|
+ // File does not exist. |
|
+ if ( ! file_exists( $image_path ) ) { |
|
+ return new WP_Error( 'original_image_file_not_found', __( 'The original image file does not exists, subsizes are created out of the original image.', 'performance-lab' ) ); |
|
+ } |
|
|
|
- $editor = wp_get_image_editor( $image_path ); |
|
+ $editor = wp_get_image_editor( $image_path ); |
|
|
|
- if ( is_wp_error( $editor ) ) { |
|
- return $editor; |
|
- } |
|
+ if ( is_wp_error( $editor ) ) { |
|
+ return $editor; |
|
+ } |
|
|
|
- $allowed_mimes = array_flip( wp_get_mime_types() ); |
|
- if ( ! isset( $allowed_mimes[ $mime ] ) || ! is_string( $allowed_mimes[ $mime ] ) ) { |
|
- return new WP_Error( 'image_mime_type_invalid', __( 'The provided mime type is not allowed.', 'performance-lab' ) ); |
|
- } |
|
+ $allowed_mimes = array_flip( wp_get_mime_types() ); |
|
+ if ( ! isset( $allowed_mimes[ $mime ] ) || ! is_string( $allowed_mimes[ $mime ] ) ) { |
|
+ return new WP_Error( 'image_mime_type_invalid', __( 'The provided mime type is not allowed.', 'performance-lab' ) ); |
|
+ } |
|
|
|
- if ( ! wp_image_editor_supports( array( 'mime_type' => $mime ) ) ) { |
|
- return new WP_Error( 'image_mime_type_not_supported', __( 'The provided mime type is not supported.', 'performance-lab' ) ); |
|
- } |
|
+ if ( ! wp_image_editor_supports( array( 'mime_type' => $mime ) ) ) { |
|
+ return new WP_Error( 'image_mime_type_not_supported', __( 'The provided mime type is not supported.', 'performance-lab' ) ); |
|
+ } |
|
|
|
- $height = isset( $size_data['height'] ) ? (int) $size_data['height'] : 0; |
|
- $width = isset( $size_data['width'] ) ? (int) $size_data['width'] : 0; |
|
- $crop = isset( $size_data['crop'] ) && $size_data['crop']; |
|
+ if ( $size_name === 'full' ) { |
|
+ $metadata = wp_get_attachment_metadata( $attachment_id ); |
|
+ $height = $metadata['height']; |
|
+ $width = $metadata['width']; |
|
+ $crop = false; |
|
+ } else { |
|
+ $sizes = wp_get_registered_image_subsizes(); |
|
+ if ( empty( $sizes[ $size_name ] ) ) { |
|
+ return new WP_Error( "The provided size name '{$size_name}' is not registered" ); |
|
+ } |
|
+ $height = $sizes[ $size_name ]['height']; |
|
+ $width = $sizes[ $size_name ]['width']; |
|
+ $crop = $sizes[ $size_name ]['crop']; |
|
+ } |
|
|
|
- if ( $width <= 0 && $height <= 0 ) { |
|
- return new WP_Error( 'image_wrong_dimensions', __( 'At least one of the dimensions must be a positive number.', 'performance-lab' ) ); |
|
- } |
|
+ if ( $width <= 0 && $height <= 0 ) { |
|
+ return new WP_Error( 'image_wrong_dimensions', __( 'At least one of the dimensions must be a positive number.', 'performance-lab' ) ); |
|
+ } |
|
|
|
- $image_meta = wp_get_attachment_metadata( $attachment_id ); |
|
- // If stored EXIF data exists, rotate the source image before creating sub-sizes. |
|
- if ( ! empty( $image_meta['image_meta'] ) ) { |
|
- $editor->maybe_exif_rotate(); |
|
- } |
|
+ $image_meta = wp_get_attachment_metadata( $attachment_id ); |
|
+ // If stored EXIF data exists, rotate the source image before creating sub-sizes. |
|
+ if ( ! empty( $image_meta['image_meta'] ) ) { |
|
+ $editor->maybe_exif_rotate(); |
|
+ } |
|
|
|
- $editor->resize( $width, $height, $crop ); |
|
+ $editor->resize( $width, $height, $crop ); |
|
|
|
- if ( null === $destination_file_name ) { |
|
- $extension = explode( '|', $allowed_mimes[ $mime ] ); |
|
- $destination_file_name = $editor->generate_filename( null, null, $extension[0] ); |
|
- } |
|
+ if ( null === $destination_file_name ) { |
|
+ $extension = explode( '|', $allowed_mimes[ $mime ] ); |
|
+ $destination_file_name = $editor->generate_filename( null, null, $extension[0] ); |
|
+ } |
|
|
|
- $image = $editor->save( $destination_file_name, $mime ); |
|
+ $image = $editor->save( $destination_file_name, $mime ); |
|
+ } |
|
|
|
if ( is_wp_error( $image ) ) { |
|
return $image; |