bulk_optimization=new CompressX_Bulk_Optimization_Display();
add_action('compressx_output_review_v2', array($this, 'output_review'));
add_action('wp_ajax_compressx_save_image_optimization_settings', array($this, 'set_setting'));
add_action('wp_ajax_compressx_rating_dismiss', array($this, 'compressx_rating_dismiss'));
add_action('wp_ajax_compressx_hide_big_update_v2', array($this, 'hide_big_update'));
}
public function display()
{
$view = isset($_GET['view']) ? sanitize_text_field($_GET['view']) : '';
switch ($view)
{
case 'bulk':
$this->bulk_optimization->display();
break;
default:
$this->display_image_optimization();
break;
}
}
public function display_image_optimization()
{
?>
output_header();
$this->output_review();
$this->output_notice();
$this->output_format();
$this->output_quality();
$this->output_settings();
$this->output_save_section();
$this->output_footer();
?>
get_bulk_progress();
?>
0 && $bulk_progress < 100): ?>
(%)
' . esc_html( $opt_size ) . ''
);
?>
' . esc_html__( '5-star review', 'compressx' ) . ''
);
?>
⭐
🚀
let us know — we\'ll fix it quickly.', 'compressx' )
),
esc_url( 'https://wordpress.org/support/plugin/compressx/' )
);
?>
test();
if (!$result )
{
?>
is_active_cache())
{
?>
is_apache())
{
?>
How-to: Config Apache htaccess Rules', 'compressx')) ?>
is_nginx())
{
?>
How-to: Config Nginx htaccess Rules', 'compressx')) ?>
is_litespeed())
{
?>
output_tooltip(
'cx-v2-tip-auto-optimize',
esc_html__('Enable it to convert the new uploaded images.', 'compressx'),
'large'
);
?>
output_tooltip(
'cx-v2-tip-library',
esc_html__('Choose the PHP extension for image processing. GD is faster for large images but supports fewer formats. Imagick supports more formats and produces higher quality results.', 'compressx')
);
?>
output_tooltip(
'cx-v2-tip-formats',
esc_html__('Convert .jpg and .png images to WebP or/and AVIF format.', 'compressx')
);
?>
get_bulk_progress();
?>
output_tooltip(
'cx-v2-tip-quality',
esc_html__('Choose the most appropriate compression level. Higher quality means larger file sizes but better image appearance.', 'compressx'),
'large'
);
?>
0 && $bulk_progress < 100) : ?>
(%)
output_free_quality_section(); ?>
WebP 99 ,AVIF 99 .
WebP 80 ,
AVIF 60 .
output_general();?>
output_smart();?>
WebP
i
Tip
Lower values apply stronger compression to further reduce file sizes.
AVIF
i
Tip
Lower values apply stronger compression to further reduce file sizes.
Threshold)', 'compressx' ); ?>
output_tooltip('', esc_html__('Auto-delete larger AVIF/WebP images Automatically delete AVIF/WebP images when they are larger than the original images.', 'compressx')); ?>
output_tooltip('', esc_html__('Number of WordPress image attachments (including original and thumbnails) processed per AJAX cycle. Default is 5.', 'compressx')); ?>
>
>
>
>
output_cron_watermark_placeholders();
?>
output_tooltip('', esc_html__('Choose when to process new uploads: immediately (real-time but may delay availability), after a delay (recommended to avoid workflow interruption), or during scheduled low-traffic windows (minimizes server impact).', 'compressx')); ?>
output_tooltip('', esc_html__('Enable this option to automatically tag newly uploaded images, making them ready for batch watermarking. This feature allows you to easily identify and process recent uploads for watermark application, streamlining your image protection process.', 'compressx')); ?>
'compressx-v2-h-4 compressx-v2-w-4',
'medium' => 'compressx-v2-h-5 compressx-v2-w-5',
'large' => 'compressx-v2-h-6 compressx-v2-w-6'
);
$button_class = isset($size_classes[$button_size]) ? $size_classes[$button_size] : $size_classes['medium'];
?>
ajax_check_security('compressx-can-use-general-settings');
if (isset($_POST['settings']) && !empty($_POST['settings']))
{
$json_setting = sanitize_text_field($_POST['settings']);
$json_setting = stripslashes($json_setting);
$setting = json_decode($json_setting, true);
if (is_null($setting)) {
$ret['result'] = 'failed';
$ret['error'] = 'json decode failed';
echo wp_json_encode($ret);
die();
}
if (isset($setting['auto_optimize']))
{
if ($setting['auto_optimize'] == '1')
{
$options = true;
} else {
$options = false;
}
if (CompressX_Options::get_option('compressx_show_review', false) === false)
{
CompressX_Options::update_option('compressx_show_review', time() + 259200);
}
CompressX_Options::update_option('compressx_auto_optimize', $options);
}
if (isset($setting['convert_to_webp']))
{
if ($setting['convert_to_webp'] == '1')
{
$options = 1;
} else {
$options = 0;
}
CompressX_Options::update_option('compressx_output_format_webp', $options);
}
if (isset($setting['convert_to_avif']))
{
if ($setting['convert_to_avif'] == '1')
{
$options = 1;
} else {
$options = 0;
}
CompressX_Options::update_option('compressx_output_format_avif', $options);
}
if (isset($setting['converter_method'])&&!empty($setting['converter_method']))
{
$converter_method = $setting['converter_method'];
CompressX_Options::update_option('compressx_converter_method', $converter_method);
}
if (isset($setting['quality_webp'])&&isset($setting['quality_avif']))
{
$quality_options['quality'] = "custom";
$quality_options['quality_webp'] = isset($setting['quality_webp']) ? $setting['quality_webp'] : 80;
$quality_options['quality_avif'] = isset($setting['quality_avif']) ? $setting['quality_avif'] : 60;
CompressX_Options::update_option('compressx_quality', $quality_options);
}
$options = CompressX_Options::get_option('compressx_general_settings', array());
if (isset($setting['remove_exif']))
$options['remove_exif'] = $setting['remove_exif'];
if (isset($setting['exclude_png']))
$options['exclude_png'] = $setting['exclude_png'];
if (isset($setting['exclude_png_webp']))
$options['exclude_png_webp'] = $setting['exclude_png_webp'];
//
if (isset($setting['auto_remove_larger_format']))
$options['auto_remove_larger_format'] = $setting['auto_remove_larger_format'];
$interface_version_changed=false;
/*
if (isset($setting['interface_version'])) {
$old_interface_version = isset($options['interface_version']) ? $options['interface_version'] : 'v1';
if ($old_interface_version !== $setting['interface_version']) {
$interface_version_changed = true;
}
$options['interface_version'] = $setting['interface_version'];
}*/
$reset_rewrite=false;
if (isset($setting['image_load'])) {
if (!isset($options['image_load'])) {
$options['image_load'] = 'htaccess';
}
if ($options['image_load'] != $setting['image_load'])
$reset_rewrite = true;
$options['image_load'] = $setting['image_load'];
}
if (isset($setting['resize']))
{
if($setting['resize']=='1')
{
$options['resize']['enable']=true;
}
else
{
$options['resize']['enable']=false;
}
}
if (isset($setting['resize_width']))
$options['resize']['width'] = $setting['resize_width'];
if (isset($setting['resize_height']))
$options['resize']['height'] = $setting['resize_height'];
if (isset($setting['converter_images_pre_request']))
$options['converter_images_pre_request'] = intval($setting['converter_images_pre_request']);
//
if ($options['image_load'] == 'htaccess')
{
if ($reset_rewrite)
{
include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php';
$rewrite = new CompressX_Webp_Rewrite();
$rewrite->create_rewrite_rules();
$ret['test'] = '1';
}
} else if ($options['image_load'] == 'compat_htaccess') {
if ($reset_rewrite) {
include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php';
$rewrite = new CompressX_Webp_Rewrite();
$rewrite->create_rewrite_rules_ex();
$ret['test'] = '1';
}
} else {
include_once COMPRESSX_DIR . '/includes/class-compressx-webp-rewrite.php';
$rewrite = new CompressX_Webp_Rewrite();
$rewrite->remove_rewrite_rule();
}
CompressX_Options::update_option('compressx_general_settings', $options);
if ($interface_version_changed)
{
$ret['interface_version_changed']=true;
}
else
{
$ret['interface_version_changed']=false;
}
$ret['result'] = 'success';
echo wp_json_encode($ret);
die();
}
else
{
die();
}
}
public function compressx_rating_dismiss()
{
global $compressx;
$compressx->ajax_check_security();
if (isset($_POST['value'])) {
$value = sanitize_text_field($_POST['value']);
if ($value == 'ask_me_later') {
$time = time() + 259200;
CompressX_Options::update_option('compressx_rating_dismiss', $time);
}
if ($value == 'close') {
$time = time() + 604800;
CompressX_Options::update_option('compressx_rating_dismiss', $time);
} else if ($value == 'already') {
CompressX_Options::update_option('compressx_rating_dismiss', 0);
} else if ($value == 'dismiss') {
CompressX_Options::update_option('compressx_rating_dismiss', 0);
}
}
die();
}
public function hide_big_update()
{
global $compressx;
$compressx->ajax_check_security('compressx-can-use-image-optimization');
CompressX_Options::update_option('compressx_hide_big_update', true);
die();
}
}