| Server IP : 38.190.208.107 / Your IP : 216.73.217.21 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.9/wp-content/themes/blocksy/inc/components/woocommerce/common/ |
Upload File : |
<?php
namespace Blocksy;
use Automattic\WooCommerce\Utilities\NumberUtil;
class WooCommerceImageSizes {
public function __construct() {
add_action(
'after_setup_theme',
[$this, 'add_image_sizes']
);
if (! is_multisite()) {
add_action(
'customize_save_after',
[$this, 'maybe_regenerate_images'],
// Run after Woo's regeneration logic
50
);
}
add_filter(
'woocommerce_get_image_size_archive_thumbnail',
function ($size) {
return $this->get_image_size('archive_thumbnail', 500);
}
);
add_filter(
'woocommerce_image_sizes_to_resize',
function ($sizes) {
$sizes[] = 'woocommerce_archive_thumbnail';
return $sizes;
}
);
add_filter(
'woocommerce_regenerate_images_intermediate_image_sizes',
function ($sizes) {
$sizes[] = 'woocommerce_archive_thumbnail';
return $sizes;
}
);
add_filter(
'woocommerce_thumbnail_size',
[$this, 'swap_archive_thumbnail_size']
);
add_filter(
'woocommerce_gallery_image_size',
[$this, 'swap_archive_thumbnail_size']
);
}
public function add_image_sizes() {
$sizes = [
[
'name' => 'archive_thumbnail',
'default_width' => 500
]
];
foreach ($sizes as $size) {
$size_info = $this->get_image_size(
$size['name'],
$size['default_width']
);
add_image_size(
'woocommerce_' . $size['name'],
$size_info['width'],
$size_info['height'],
$size_info['crop']
);
}
}
public function maybe_regenerate_images() {
$size_hash = md5(wp_json_encode([
$this->get_image_size('archive_thumbnail', 500),
blocksy_get_theme_mod('gallery_thumbnail_image_width', 100)
]));
$did_update = update_option(
'blocksy_woocommerce_maybe_regenerate_images_hash',
$size_hash
);
if ($did_update) {
\WC_Regenerate_Images::queue_image_regeneration();
}
}
public function get_image_size($size_name, $default_width = 300) {
$size = [];
$size['width'] = absint(
get_option(
'woocommerce_' . $size_name . '_image_width',
$default_width
)
);
$cropping = get_option('woocommerce_' . $size_name . '_cropping', '1:1');
if ('uncropped' === $cropping) {
$size['height'] = '';
$size['crop'] = 0;
} elseif ('custom' === $cropping) {
$width = max(
1,
get_option(
'woocommerce_' . $size_name . '_cropping_custom_width',
'4'
)
);
$height = max(
1,
get_option(
'woocommerce_' . $size_name . '_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));
if (intval($width) === 0) {
$width = 1;
}
$size['height'] = absint(
NumberUtil::round(
(intval($size['width']) / intval($width)) * intval($height)
)
);
$size['crop'] = 1;
}
return $size;
}
public function swap_archive_thumbnail_size($size) {
global $blocksy_rendering_woo_card;
if (! $blocksy_rendering_woo_card) {
return $size;
}
return 'woocommerce_archive_thumbnail';
}
}