Merge pull request #30165 from woocommerce/fix/29768

Remove potential for type (and division-by-zero) errors when determining thumbnail sizes.
This commit is contained in:
Barry Hughes 2021-06-29 07:34:33 -07:00 committed by GitHub
commit 74dfa0d825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -976,14 +976,14 @@ function wc_get_image_size( $image_size ) {
$size['height'] = '';
$size['crop'] = 0;
} elseif ( 'custom' === $cropping ) {
$width = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_width', '4' ) );
$height = max( 1, get_option( 'woocommerce_thumbnail_cropping_custom_height', '3' ) );
$width = max( 1, (float) get_option( 'woocommerce_thumbnail_cropping_custom_width', '4' ) );
$height = max( 1, (float) get_option( 'woocommerce_thumbnail_cropping_custom_height', '3' ) );
$size['height'] = absint( NumberUtil::round( ( $size['width'] / $width ) * $height ) );
$size['crop'] = 1;
} else {
$cropping_split = explode( ':', $cropping );
$width = max( 1, current( $cropping_split ) );
$height = max( 1, end( $cropping_split ) );
$width = max( 1, (float) current( $cropping_split ) );
$height = max( 1, (float) end( $cropping_split ) );
$size['height'] = absint( NumberUtil::round( ( $size['width'] / $width ) * $height ) );
$size['crop'] = 1;
}