Register gallery_thumbnail size

This commit is contained in:
Mike Jolley 2018-02-12 17:47:22 +00:00
parent c9bbbf7c5a
commit 9499b63e01
3 changed files with 22 additions and 8 deletions

View File

@ -539,11 +539,13 @@ final class WooCommerce {
* @since 2.3
*/
public function add_image_sizes() {
$thumbnail = wc_get_image_size( 'thumbnail' );
$single = wc_get_image_size( 'single' );
$thumbnail = wc_get_image_size( 'thumbnail' );
$single = wc_get_image_size( 'single' );
$gallery_thumbnail = wc_get_image_size( 'gallery_thumbnail' );
add_image_size( 'woocommerce_thumbnail', $thumbnail['width'], $thumbnail['height'], $thumbnail['crop'] );
add_image_size( 'woocommerce_single', $single['width'], $single['height'], $single['crop'] );
add_image_size( 'woocommerce_gallery_thumbnail', $gallery_thumbnail['width'], $gallery_thumbnail['height'], $gallery_thumbnail['crop'] );
// 2x thumbnail size for retina, and when showing less columns.
add_image_size( 'woocommerce_thumbnail_2x', $thumbnail['width'] * 2, '' !== $thumbnail['height'] ? $thumbnail['height'] * 2 : '', $thumbnail['crop'] );

View File

@ -156,7 +156,7 @@ class WC_Shop_Customizer {
setting.bind( function( value ) {
var min = parseInt( '<?php echo esc_js( $min_rows ); ?>', 10 );
var max = parseInt( '<?php echo esc_js( $max_rows ); ?>', 10 );
value = parseInt( value, 10 );
if ( max && value > max ) {
@ -496,7 +496,7 @@ class WC_Shop_Customizer {
'woocommerce_thumbnail_image_width',
array(
'label' => __( 'Thumbnail width', 'woocommerce' ),
'description' => __( 'Image size used for products in the catalog and product gallery thumbnails.', 'woocommerce' ),
'description' => __( 'Image size used for products in the catalog.', 'woocommerce' ),
'section' => 'woocommerce_product_images',
'settings' => 'woocommerce_thumbnail_image_width',
'type' => 'number',

View File

@ -722,6 +722,13 @@ function wc_get_image_size( $image_size ) {
'crop' => 1,
);
// Size mapping.
if ( in_array( $image_size, array( 'shop_single', 'woocommerce_single' ), true ) ) {
$image_size = 'single';
} elseif ( in_array( $image_size, array( 'shop_thumbnail', 'shop_catalog', 'woocommerce_thumbnail' ), true ) ) {
$image_size = 'thumbnail';
}
if ( is_array( $image_size ) ) {
$size = array(
'width' => isset( $image_size[0] ) ? absint( $image_size[0] ) : 600,
@ -729,12 +736,18 @@ function wc_get_image_size( $image_size ) {
'crop' => isset( $image_size[2] ) ? absint( $image_size[2] ) : 1,
);
$image_size = $size['width'] . '_' . $size['height'];
} elseif ( in_array( $image_size, array( 'single', 'shop_single', 'woocommerce_single' ), true ) ) {
} elseif ( 'single' === $image_size ) {
$size['width'] = absint( wc_get_theme_support( 'single_image_width', get_option( 'woocommerce_single_image_width', 600 ) ) );
$size['height'] = '';
$size['crop'] = 0;
$image_size = 'single';
} elseif ( in_array( $image_size, array( 'thumbnail', 'shop_thumbnail', 'shop_catalog', 'woocommerce_thumbnail' ), true ) ) {
} elseif ( 'gallery_thumbnail' === $image_size ) {
$size['width'] = absint( wc_get_theme_support( 'gallery_thumbnail_image_width', 100 ) );
$size['height'] = $size['width'];
$size['crop'] = 1;
} elseif ( 'thumbnail' === $image_size ) {
$size['width'] = absint( wc_get_theme_support( 'thumbnail_image_width', get_option( 'woocommerce_thumbnail_image_width', 300 ) ) );
$cropping = get_option( 'woocommerce_thumbnail_cropping', '1:1' );
@ -753,7 +766,6 @@ function wc_get_image_size( $image_size ) {
$size['height'] = round( ( $size['width'] / $width ) * $height );
$size['crop'] = 1;
}
$image_size = 'thumbnail';
}
return apply_filters( 'woocommerce_get_image_size_' . $image_size, $size );