Skip to content

Commit af35deb

Browse files
committed
Simplify crop condition checks
1 parent 83b0edf commit af35deb

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

plugins/webp-uploads/helper.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ function webp_uploads_get_upload_image_mime_transforms(): array {
8282
* @since 1.0.0
8383
* @access private
8484
*
85-
* @param int $attachment_id The ID of the attachment from where this image would be created.
86-
* @param string $image_size The size name that would be used to create the image source, out of the registered subsizes.
87-
* @param array{ width: int, height: int, crop: bool|array{0: string, 1: string}} $size_data An array with the dimensions of the image: height, width and crop.
88-
* @param string $mime The target mime in which the image should be created.
89-
* @param string|null $destination_file_name The path where the file would be stored, including the extension. If null, `generate_filename` is used to create the destination file name.
85+
* @param int $attachment_id The ID of the attachment from where this image would be created.
86+
* @param string $image_size The size name that would be used to create the image source, out of the registered subsizes.
87+
* @param array{ width: int, height: int, crop: bool|array{string, string}} $size_data An array with the dimensions of the image: height, width and crop.
88+
* @param string $mime The target mime in which the image should be created.
89+
* @param string|null $destination_file_name The path where the file would be stored, including the extension. If null, `generate_filename` is used to create the destination file name.
9090
*
9191
* @return array{ file: string, filesize: int }|WP_Error An array with the file and filesize if the image was created correctly, otherwise a WP_Error.
9292
*/
@@ -109,7 +109,7 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri
109109
* @param array{
110110
* width: int,
111111
* height: int,
112-
* crop: bool|array{0: string, 1: string}
112+
* crop: bool|array{string, string}
113113
* } $size_data An array with the dimensions of the image.
114114
* @param string $mime The target mime in which the image should be created.
115115
*/
@@ -240,20 +240,7 @@ function webp_uploads_generate_image_size( int $attachment_id, string $size, str
240240
$size_data['height'] = $metadata['sizes'][ $size ]['height'];
241241
}
242242

243-
if (
244-
isset( $sizes[ $size ]['crop'] ) &&
245-
(
246-
(
247-
is_array( $sizes[ $size ]['crop'] ) &&
248-
count( $sizes[ $size ]['crop'] ) === 2 &&
249-
isset( $sizes[ $size ]['crop'][0] ) &&
250-
isset( $sizes[ $size ]['crop'][1] ) &&
251-
is_string( $sizes[ $size ]['crop'][0] ) &&
252-
is_string( $sizes[ $size ]['crop'][1] )
253-
) ||
254-
is_bool( $sizes[ $size ]['crop'] )
255-
)
256-
) {
243+
if ( isset( $sizes[ $size ]['crop'] ) ) {
257244
$size_data['crop'] = $sizes[ $size ]['crop'];
258245
}
259246

0 commit comments

Comments
 (0)