output_header(); $this->output_settings(); $this->output_save_section(); $this->output_footer(); ?>

output_thumbnail_sizes(); ?> output_exclude_folders(); ?> output_custom_folders(); ?> output_cache_control_settings(); ?> output_scan_page_settings(); ?> output_scan_max_count_settings(); ?> output_delete_images(); ?>
$_wp_additional_image_sizes[$size_key]['width'], 'height' => $_wp_additional_image_sizes[$size_key]['height'], 'crop' => $_wp_additional_image_sizes[$size_key]['crop'], ); if (isset($options['skip_size'][$size_key]) && $options['skip_size'][$size_key]) { $image_sizes[$size_key]['skip'] = true; } else { $image_sizes[$size_key]['skip'] = false; } } } if (! isset($image_sizes['medium_large']) || empty($image_sizes['medium_large'])) { $width = intval(get_option('medium_large_size_w')); $height = intval(get_option('medium_large_size_h')); $image_sizes['medium_large'] = array( 'width' => $width, 'height' => $height, ); if (isset($options['skip_size']['medium_large']) && $options['skip_size']['medium_large']) { $image_sizes['medium_large']['skip'] = true; } else { $image_sizes['medium_large']['skip'] = false; } } ?>

output_tooltip('', esc_html__('Choose thumbnail sizes you want to process. Some themes may generate new thumbnail sizes sometimes, then you\'ll need to reprocess the thumbnails sizes using the Bulk Processing function.', 'compressx'), 'large'); ?>

$size) { if ($showed > $max_show) { $style = "display:none"; if (!$show_more) { $show_more = true; ?>

output_tooltip('', esc_html__('Select folders in the Uploads folder (media library) and exclude them from the processing.', 'compressx'), 'large'); ?>

  • get_children_count($exclude) . ') images') ?>
get_custom_stats($custom_folders); $found = $stats['files']; $saved = $stats['saved']; $processed = $stats['processed_files']; ?>

output_tooltip('', esc_html__('Select custom folders in the /wp-content folder and process images inside them.', 'compressx'), 'large'); ?>

  • get_custom_children_count($folder) . ')') ?>
| % |

⚠️ WebP AVIF

DELETE

output_tooltip('', esc_html__('You can try to check this option if the site cannot be cached by Cloudflare.', 'compressx'), 'large'); ?>

output_tooltip( '', esc_html__('Set the number of images processed per scan batch. A higher value may speed up scanning but requires more server resources.', 'compressx'), 'large' ); ?>

output_tooltip( '', esc_html__('Set the maximum number of images that can be processed in one AJAX request. A higher value may speed up scanning but requires more server resources.', 'compressx'), 'large' ); ?>

'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']; ?>
get_folder_stats($include, $stats, $convert_to_webp, $convert_to_avif); } if ($stats['total'] > 0) { $stats['saved'] = ($stats['processed'] / $stats['total']) * 100; $stats['saved'] = round($stats['saved'], 1); } return $stats; } private function get_folder_stats($path, &$stats, $convert_to_webp, $convert_to_avif) { try { if (!class_exists('CompressX_Custom_Image_Meta')) { return 0; } $support_extension = array('jpg', 'jpeg', 'png', 'webp'); $count = 0; $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($rii as $file) { if ($file->isDir()) { continue; } $extension = strtolower($file->getExtension()); if (in_array($extension, $support_extension)) { $filename = $path . '/' . $file->getFilename(); $filename = $this->transfer_path($filename); $type = pathinfo($filename, PATHINFO_EXTENSION); if ($convert_to_webp && $type != "webp") { if (CompressX_Custom_Image_Meta::is_convert_webp($filename)) { $stats['processed_files']++; $stats['processed'] += CompressX_Custom_Image_Meta::get_convert_webp_size($filename); } $count++; $stats['files']++; $stats['total'] += $file->getSize(); } else if ($convert_to_avif && $type != "avif") { if (CompressX_Custom_Image_Meta::is_convert_avif($filename)) { $stats['processed_files']++; $stats['processed'] += CompressX_Custom_Image_Meta::get_convert_avif_size($filename); } $count++; $stats['files']++; $stats['total'] += $file->getSize(); } } } return $count; } catch (Exception $exception) { return 0; } } private function transfer_path($path) { $path = str_replace('\\', '/', $path); $values = explode('/', $path); return implode(DIRECTORY_SEPARATOR, $values); } public function get_custom_tree_dir() { global $compressx; $compressx->ajax_check_security('compressx-can-use-exclude'); try { $node_array = array(); if ($_POST['tree_node']['node']['id'] == '#') { $path = ABSPATH; if (!empty($_POST['tree_node']['path'])) { $path = sanitize_text_field($_POST['tree_node']['path']); } /* $node_array[] = array( 'text' => basename($path), 'children' => true, 'id' => $path, 'icon' => 'dashicons dashicons-category cx-icon-color-yellow', 'state' => array( 'opened' => true ) );*/ } else { $path = sanitize_text_field($_POST['tree_node']['node']['id']); } $upload_dir = wp_upload_dir(); $uploads_path = $upload_dir['basedir']; $uploads_path = str_replace('\\', '/', $uploads_path); $uploads_path = $uploads_path . '/'; if ($path == $uploads_path) { $init = true; $key = gmdate('Y', time()); } else { $init = false; $key = gmdate('Y', time()); } $path = trailingslashit(str_replace('\\', '/', realpath($path))); if ($dh = opendir($path)) { while (substr($path, -1) == '/') { $path = rtrim($path, '/'); } $skip_paths = array(".", ".."); while (($value = readdir($dh)) !== false) { trailingslashit(str_replace('\\', '/', $value)); if (!in_array($value, $skip_paths)) { if (is_dir($path . '/' . $value)) { $node['children'] = $this->has_children($path . '/' . $value); $node['id'] = $path . '/' . $value; if ($init) { if ($value == $key) { $node['state']['opened'] = true; } } // $node['icon'] = 'dashicons dashicons-open-folder cx-icon-color-techblue compressx-text'; $node['children_count'] = $this->get_children_count($path . '/' . $value); $node['text'] = $value . ',(' . $node['children_count'] . ') images'; $node['text'] .= ''; $node_array[] = $node; /* if($this->is_media_folder($path . '/' . $value)) { $node['children'] = $this->has_children($path . '/' . $value); $node['id'] = $path . '/' . $value; if($init) { if($value==$key) { $node['state']['opened']=true; } } // $node['icon'] = 'dashicons dashicons-open-folder cx-icon-color-techblue compressx-text'; $node['children_count']=$this->get_children_count($path . '/' . $value); $node['text'] = $value.',('. $node['children_count'].') images'; $node['text'] .=''; $node_array[] = $node; } else { continue; }*/ } else { //$node['text'] = $value; //$node['children'] = true; //$node['id'] = $path . '/' . $value; //$node['icon'] = 'dashicons dashicons-media-default cx-icon-color-yellow'; //$node_array[] = $node; continue; } } } } $ret['nodes'] = $node_array; echo wp_json_encode($ret); } catch (Exception $error) { $message = 'An exception has occurred. class: ' . get_class($error) . ';msg: ' . $error->getMessage() . ';code: ' . $error->getCode() . ';line: ' . $error->getLine() . ';in_file: ' . $error->getFile() . ';'; //error_log($message); echo wp_json_encode(array('result' => 'failed', 'error' => $message)); } die(); } public function has_children($path) { if ($dh = opendir($path)) { while (substr($path, -1) == '/') { $path = rtrim($path, '/'); } $skip_paths = array(".", ".."); while (($value = readdir($dh)) !== false) { trailingslashit(str_replace('\\', '/', $value)); if (!in_array($value, $skip_paths)) { if (is_dir($path . '/' . $value)) { return true; } } } } return false; } public function is_media_folder($path) { $upload_dir = wp_upload_dir(); $base_dir = $upload_dir['basedir']; $base_dir = trailingslashit(str_replace('\\', '/', realpath($base_dir))); $path = str_replace($base_dir, '', $path); $path_arr = explode('/', $path); if (count($path_arr) >= 1) { if (is_numeric($path_arr[0]) && $path_arr[0] > 1950 && $path_arr[0] < 2050) { return true; } } return false; } public function get_children_count($path) { try { $rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); $files = 0; /** @var SplFileInfo $file */ foreach ($rii as $file) { if ($file->isDir()) { continue; } $files++; } return $files; } catch (Exception $e) { return 0; } } public function add_exclude_folders() { global $compressx; $compressx->ajax_check_security('compressx-can-use-exclude'); $json_excludes = sanitize_text_field($_POST['excludes']); $json_excludes = stripslashes($json_excludes); $new_excludes = json_decode($json_excludes, true); CompressX_Options::update_option('compressx_media_excludes', $new_excludes); $abs_path = trailingslashit(str_replace('\\', '/', realpath(ABSPATH))); $html = '