PluginProbe
Squeeze – Image Optimization & Compression, WEBP Conversion / 1.7.8
Squeeze – Image Optimization & Compression, WEBP Conversion v1.7.8
1.7.15 1.7.14 1.7.13 1.7.12 1.7.11 1.7.10 trunk 1.0 1.1 1.2 1.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5 1.5.1 1.5.2 1.6 All 42 releases
squeeze / inc / settings.php

settings.php in Squeeze – Image Optimization & Compression, WEBP Conversion 1.7.8, at inc/settings.php

1,732 lines 83.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SqueezeFree;
4
5 // Exit if accessed directly.
6 if ( !defined( 'ABSPATH' ) ) {
7 exit;
8 }
9 class SqueezeSettings extends SqueezeInit {
10 public function __construct() {
11 add_action( 'admin_menu', [$this, 'options_page'] );
12 add_action( 'admin_menu', [$this, 'options_bulk_page'] );
13 add_action( 'admin_init', [$this, 'register_settings'] );
14 add_action(
15 'update_option_squeeze_options',
16 [$this, 'restore_defaults'],
17 10,
18 2
19 );
20 add_action(
21 'update_option_squeeze_options',
22 [$this, 'flush_rewrite_rules'],
23 10,
24 2
25 );
26 add_filter(
27 'attachment_fields_to_edit',
28 [$this, 'add_custom_field_to_attachment'],
29 10,
30 2
31 );
32 add_filter( 'manage_media_columns', [$this, 'add_media_columns'] );
33 add_action(
34 'manage_media_custom_column',
35 [$this, 'media_custom_column'],
36 10,
37 2
38 );
39 add_filter( 'manage_upload_sortable_columns', [$this, 'sortable_columns'] );
40 add_action( 'pre_get_posts', [$this, 'sortable_columns_orderby'] );
41 add_action( 'restrict_manage_posts', [$this, 'media_filter_dropdown'] );
42 add_action( 'pre_get_posts', [$this, 'media_filter_query'] );
43 add_filter(
44 'ajax_query_attachments_args',
45 [$this, 'media_filter_ajax_query'],
46 10,
47 1
48 );
49 add_action( 'admin_footer', [$this, 'svg_sprite_output'] );
50 add_action( 'admin_notices', [$this, 'incompatibility_notices'] );
51 add_action( 'edit_form_after_title', [$this, 'add_preview_button_placeholder'], 10 );
52 }
53
54 public function options_page() {
55 add_submenu_page(
56 'options-general.php',
57 __( 'Squeeze Settings', 'squeeze' ),
58 __( 'Squeeze', 'squeeze' ),
59 'manage_options',
60 'squeeze',
61 [$this, 'options_page_html']
62 );
63 }
64
65 public function options_bulk_page() {
66 add_submenu_page(
67 'upload.php',
68 __( 'Bulk Squeeze', 'squeeze' ),
69 __( 'Bulk Squeeze', 'squeeze' ),
70 'manage_options',
71 'squeeze-bulk',
72 [$this, 'options_bulk_page_html']
73 );
74 }
75
76 public function options_bulk_page_html() {
77 // check user capabilities
78 if ( !current_user_can( 'manage_options' ) ) {
79 return;
80 }
81 $is_single_page_squeeze = false;
82 $uncompressed_count = self::$SqueezeHelpers->get_uncompressed_images_count();
83 $uncompressed_pages = ceil( $uncompressed_count / self::$MEDIA_PER_PAGE );
84 $total_count = self::$SqueezeHelpers->get_total_images_count();
85 $total_pages = ceil( $total_count / self::$MEDIA_PER_PAGE );
86 $compressed_count = $total_count - $uncompressed_count;
87 $compressed_percentage = ( $total_count > 0 ? round( $compressed_count / $total_count * 100, 2 ) : 0 );
88 $dasharray = $compressed_percentage * 560 / 100;
89 //$total_count = array_sum((array)wp_count_attachments("image"));
90 $not_compressed_posts = implode( ",", self::$SqueezeHelpers->get_uncompressed_images() );
91 $all_posts = implode( ",", self::$SqueezeHelpers->get_total_images() );
92 $directory_path = ( get_transient( 'squeeze_bulk_path' ) ? get_transient( 'squeeze_bulk_path' ) : array('/wp-content/uploads/') );
93 $directory_path_json = wp_json_encode( $directory_path );
94 $is_direct_webp = self::$SqueezeHelpers->get_option( 'direct_webp' );
95 ?>
96 <div class="wrap">
97 <h1>
98 <?php
99 echo esc_html( get_admin_page_title() );
100 ?>
101 </h1>
102 <section class="squeeze-box">
103 <div class="squeeze-box-bulk-grid">
104 <?php
105 if ( !$is_single_page_squeeze ) {
106 ?>
107 <div class="squeeze-box-bulk-grid__col">
108 <div class="squeeze-box-header">
109 <h2><?php
110 esc_html_e( 'Bulk Media Library Squeeze', 'squeeze' );
111 ?></h2>
112 </div>
113 <div class="squeeze-box-content">
114 <?php
115 if ( $is_direct_webp ) {
116 ?>
117 <div class="squeeze-box-content__col squeeze-box-content__col--start">
118 <div class="squeeze-banner squeeze-banner--notice">
119 <svg class="squeeze-icon">
120 <use xlink:href="#info-icon"></use>
121 </svg>
122 <div class="squeeze-banner__content">
123 <p><?php
124 esc_html_e( 'Heads up! Direct WebP conversion is enabled.', 'squeeze' );
125 ?></p>
126 <p><?php
127 esc_html_e( 'Your JPG/PNG images will be automatically converted to WebP. To avoid broken links, please check and update any places where you\'ve hard-coded JPG/PNG URLs (e.g. image blocks, custom HTML, CSS, or shortcodes).', 'squeeze' );
128 ?></p>
129 </div>
130 </div>
131 </div>
132 <?php
133 }
134 ?>
135 <div class="squeeze-box-content__col squeeze-box-content__col--main">
136 <div class="squeeze-bulk-media-stats">
137 <div class="squeeze-bulk-media-stats-chart" style="--squeeze-dasharray: <?php
138 echo esc_attr( $dasharray );
139 ?>;">
140 <svg width="200" height="200">
141 <circle cx="100" cy="100" r="90" class="squeeze-bulk-media-stats-chart-total" fill="none" />
142 <circle cx="100" cy="100" r="90" class="squeeze-bulk-media-stats-chart-squeezed" fill="none"/>
143
144 <g class="squeeze-bulk-media-stats-chart-value">
145 <text x="100" y="100" alignment-baseline="central" text-anchor="middle"><?php
146 echo esc_html( $compressed_percentage );
147 ?>%</text>
148 </g>
149 </svg>
150 </div>
151 <div class="squeeze-bulk-media-stats-item">
152 <div class="squeeze-bulk-media-stats-item-label"><?php
153 esc_html_e( 'Squeezed images: ', 'squeeze' );
154 ?></div>
155 <div class="squeeze-bulk-media-stats-item-value"><?php
156 echo esc_html( $compressed_count );
157 ?> / <?php
158 echo esc_html( $total_count );
159 ?></div>
160 </div>
161 </div>
162 </div>
163 <div class="squeeze-box-content__col squeeze-box-content__col--end">
164 <div class="squeeze-bulk-media-actions">
165 <button name="squeeze_bulk" class="button button-primary button-hero" type="button" <?php
166 echo ( $uncompressed_count === 0 ? 'hidden disabled' : '' );
167 ?>>
168 <svg class="squeeze-icon">
169 <use xlink:href="#play-button-round-icon"></use>
170 </svg>
171 <?php
172 esc_attr_e( 'Run Bulk Squeeze', 'squeeze' );
173 ?>
174 </button>
175 <button name="squeeze_bulk_again" class="button button-secondary button-large" type="button">
176 <svg class="squeeze-icon">
177 <use xlink:href="#repeat-icon"></use>
178 </svg>
179 <?php
180 esc_attr_e( 'Repeat Bulk Squeeze', 'squeeze' );
181 ?>
182 </button>
183 </div>
184 </div>
185 </div>
186 </div>
187 <div class="squeeze-box-bulk-grid__col">
188 <div class="squeeze-box-header">
189 <h2><?php
190 esc_html_e( 'Directory Squeeze', 'squeeze' );
191 ?></h2>
192 </div>
193 <div class="squeeze-box-content">
194 <div class="squeeze-box-content__col squeeze-box-content__col--start">
195 <div class="squeeze-banner squeeze-banner--notice">
196 <svg class="squeeze-icon">
197 <use xlink:href="#info-icon"></use>
198 </svg>
199 <div class="squeeze-banner__content">
200 <p><?php
201 esc_html_e( 'Heads up! Automatic backup is not available here.', 'squeeze' );
202 ?></p>
203 <p><?php
204 esc_html_e( 'Please make a manual backup of your images before starting directory squeezing.', 'squeeze' );
205 ?></p>
206 </div>
207 </div>
208 </div>
209 <div class="squeeze-box-content__col squeeze-box-content__col--main">
210 <label>
211 <?php
212 esc_html_e( 'Directory Path:', 'squeeze' );
213 ?><br>
214
215 <input type="hidden" name="squeeze_bulk_path" value="<?php
216 echo esc_attr( $directory_path_json );
217 ?>" />
218
219 <div class="squeeze-path-list">
220 <?php
221 foreach ( $directory_path as $path ) {
222 ?>
223 <div class="squeeze-path-list__item">
224 <input name="squeeze-path-list__item[]" type="text" class="squeeze-path-list__input" value="<?php
225 echo esc_attr( $path );
226 ?>" readonly />
227 <button name="squeeze_remove_path_button" class="squeeze-path-list__remove" type="button">
228 <svg class="squeeze-icon">
229 <use xlink:href="#trash-icon"></use>
230 </svg>
231 </button>
232 </div>
233 <?php
234 }
235 ?>
236 </div>
237 </label>
238 <button name="squeeze_select_path_button" class="button button-secondary button-large" type="button">
239 <svg class="squeeze-icon">
240 <use xlink:href="#open-folder-outline-icon"></use>
241 </svg>
242 <?php
243 esc_attr_e( 'Select Directory', 'squeeze' );
244 ?>
245 </button>
246 <dialog id="squeeze-path-dialog">
247 <div class="squeeze-box-header">
248 <h2><?php
249 esc_html_e( "Select Directory for Squeeze", "squeeze" );
250 ?></h2>
251 <button name="squeeze_close_path_dialog_button" class="button button-link" type="button">
252 <svg class="squeeze-icon">
253 <use xlink:href="#close-round-icon"></use>
254 </svg>
255 </button>
256 </div>
257
258 <div id="squeeze-bulk-directory-list">
259 <svg class="squeeze-icon">
260 <use xlink:href="#reload-sync-icon"></use>
261 </svg>
262 <?php
263 esc_attr_e( "Loading directories...", "squeeze" );
264 ?>
265 </div>
266
267 <div class="squeeze-box-footer">
268 <button disabled name="squeeze_save_path_button" class="button button-secondary button-large" type="button">
269 <svg class="squeeze-icon">
270 <use xlink:href="#open-folder-outline-icon"></use>
271 </svg>
272 <?php
273 esc_attr_e( 'Select Directory', 'squeeze' );
274 ?>
275 </button>
276 </div>
277 </dialog>
278 </div>
279 <div class="squeeze-box-content__col squeeze-box-content__col--end">
280 <button name="squeeze_bulk_path_button" class="button button-primary button-hero" type="button">
281 <svg class="squeeze-icon">
282 <use xlink:href="#play-button-round-icon"></use>
283 </svg>
284 <?php
285 esc_attr_e( 'Run Directory Squeeze', 'squeeze' );
286 ?>
287 </button>
288 </div>
289 </div>
290 </div>
291 <?php
292 }
293 ?>
294
295 <?php
296 ?>
297
298
299 <div class="squeeze-box-bulk-grid__row">
300 <div class="squeeze-box-content">
301 <p class="squeeze-hint">
302 <?php
303 $images_formats = self::$SqueezeHelpers->get_image_formats();
304 $images_formats = implode( ', ', $images_formats );
305 esc_html_e( 'Processed formats:', 'squeeze' );
306 echo esc_html( '&nbsp;' . $images_formats . '. ' );
307 printf( __( 'You can change the image formats for squeezing on the <a href="%s" target="_blank">settings page.</a>', 'squeeze' ), esc_url( admin_url( 'options-general.php?page=squeeze' ) ) );
308 ?>
309 </p>
310 </div>
311 </div>
312
313 </div>
314 </section>
315 <section class="squeeze-box" name="squeeze_bulk_log" id="squeeze_bulk_log" contenteditable="false">
316 <div class="squeeze-log-placeholder">
317 <?php
318 esc_html_e( 'Start Squeezing your images and watch the progress here.', 'squeeze' );
319 ?>
320 </div>
321 <div id="squeeze-log-data"></div>
322 <div id="squeeze-anchor"></div><!-- to force scroll to the bottom -->
323 <input type="hidden" value="<?php
324 echo wp_kses_data( $not_compressed_posts );
325 ?>" name="squeeze_bulk_ids" />
326 <input type="hidden" value="<?php
327 echo wp_kses_data( $all_posts );
328 ?>" name="squeeze_bulk_all_ids" />
329 <input type="hidden" value="<?php
330 echo wp_kses_data( $total_pages );
331 ?>" name="squeeze_bulk_total_pages" />
332 <input type="hidden" value="<?php
333 echo wp_kses_data( $uncompressed_pages );
334 ?>" name="squeeze_bulk_uncompressed_pages" />
335 <input type="hidden" value="<?php
336 echo wp_kses_data( $total_count );
337 ?>" name="squeeze_bulk_total_images" />
338 <input type="hidden" value="<?php
339 echo wp_kses_data( $uncompressed_count );
340 ?>" name="squeeze_bulk_uncompressed_images" />
341 </section>
342 </div>
343 <?php
344 }
345
346 public function options_page_html() {
347 // check user capabilities
348 if ( !current_user_can( 'manage_options' ) ) {
349 return;
350 }
351 $modules = self::$SqueezeHelpers->apache_get_modules();
352 if ( !is_array( $modules ) || !in_array( 'mod_rewrite', $modules ) ) {
353 $is_auto_webp = self::$SqueezeHelpers->get_option( 'auto_webp' );
354 $is_webp_replace_urls = self::$SqueezeHelpers->get_option( 'webp_replace_urls' );
355 if ( $is_auto_webp && !$is_webp_replace_urls ) {
356 add_settings_error(
357 'squeeze_notices',
358 'squeeze_notices',
359 __( 'The Apache mod_rewrite module is not enabled on your server OR your server is not running Apache.', 'squeeze' ) . '<br>' . __( 'In order to make WebP serving work, you need to check the "Replace images URLs" option OR enable the mod_rewrite module.', 'squeeze' ),
360 'warning'
361 );
362 }
363 }
364 /*if (!self::$SqueezeHelpers->is_rest_enabled()) {
365 add_settings_error(
366 'squeeze_notices',
367 'squeeze_notices',
368 __('The REST API is not enabled on your site. Please enable it in order to use Squeeze plugin.', 'squeeze'),
369 'error'
370 );
371 }*/
372 ?>
373 <div class="wrap">
374 <h1>
375 <?php
376 echo esc_html( get_admin_page_title() );
377 ?>
378 </h1>
379 <nav class="nav-tab-wrapper">
380 <a href="#squeeze_basic" class="nav-tab nav-tab-active"><?php
381 esc_html_e( 'Basic Settings', 'squeeze' );
382 ?></a>
383 <a href="#squeeze_jpeg" class="nav-tab"><?php
384 esc_html_e( 'JPEG Settings', 'squeeze' );
385 ?></a>
386 <a href="#squeeze_png" class="nav-tab"><?php
387 esc_html_e( 'PNG Settings', 'squeeze' );
388 ?></a>
389 <a href="#squeeze_webp" class="nav-tab"><?php
390 esc_html_e( 'WEBP Settings', 'squeeze' );
391 ?></a>
392 <a href="#squeeze_avif" class="nav-tab"><?php
393 esc_html_e( 'AVIF Settings', 'squeeze' );
394 ?></a>
395 <a href="#squeeze_docs" class="nav-tab"><?php
396 esc_html_e( 'Documentation', 'squeeze' );
397 ?></a>
398 <?php
399 ?>
400 <a href="#squeeze_upgrade" class="nav-tab"><?php
401 esc_html_e( 'Upgrade', 'squeeze' );
402 ?></a>
403 <?php
404 ?>
405 <?php
406 ?>
407 </nav>
408 <div class="tab-content">
409 <form action="options.php" method="post">
410 <?php
411 settings_errors( 'squeeze_notices' );
412 settings_fields( 'squeeze_options' );
413 //do_settings_sections( 'squeeze_options' );
414 ?>
415
416 <section id="squeeze_basic">
417 <div class="squeeze-box squeeze-box--settings">
418 <div class="squeeze-box-header">
419 <div class="squeeze-box-header__col">
420 <h2><?php
421 esc_html_e( 'Basic Settings', 'squeeze' );
422 ?></h2>
423 <?php
424 $this->setting_basic_desc();
425 ?>
426 </div>
427 </div>
428 <table class="form-table" role="presentation">
429 <?php
430 do_settings_fields( 'squeeze_options', 'squeeze_basic_settings' );
431 ?>
432 </table>
433 </div>
434 </section>
435 <section id="squeeze_jpeg">
436 <div class="squeeze-box squeeze-box--settings">
437 <div class="squeeze-box-header">
438 <div class="squeeze-box-header__col">
439 <h2><?php
440 esc_html_e( 'JPEG Settings', 'squeeze' );
441 ?></h2>
442 <?php
443 $this->setting_jpeg_desc();
444 ?>
445 </div>
446 </div>
447 <table class="form-table" role="presentation">
448 <?php
449 do_settings_fields( 'squeeze_options', 'squeeze_jpeg_settings' );
450 ?>
451 </table>
452 </div>
453 <div class="squeeze-box">
454 <div class="squeeze-box-header">
455 <div class="squeeze-box-header__col">
456 <h2><?php
457 esc_html_e( 'JPEG Advanced Settings', 'squeeze' );
458 ?></h2>
459 <?php
460 $this->setting_jpeg_advanced_desc();
461 ?>
462 </div>
463 </div>
464 <table class="form-table" role="presentation">
465 <?php
466 do_settings_fields( 'squeeze_options', 'squeeze_jpeg_advanced_settings' );
467 ?>
468 </table>
469 </div>
470 </section>
471 <section id="squeeze_png">
472 <div class="squeeze-box squeeze-box--settings">
473 <div class="squeeze-box-header">
474 <div class="squeeze-box-header__col">
475 <h2><?php
476 esc_html_e( 'PNG Settings', 'squeeze' );
477 ?></h2>
478 <?php
479 $this->setting_png_desc();
480 ?>
481 </div>
482 </div>
483 <table class="form-table" role="presentation">
484 <?php
485 do_settings_fields( 'squeeze_options', 'squeeze_png_settings' );
486 ?>
487 </table>
488 </div>
489 </section>
490 <section id="squeeze_webp">
491 <div class="squeeze-box squeeze-box--settings">
492 <div class="squeeze-box-header">
493 <div class="squeeze-box-header__col">
494 <h2><?php
495 esc_html_e( 'WEBP Settings', 'squeeze' );
496 ?></h2>
497 <?php
498 $this->setting_webp_desc();
499 ?>
500 </div>
501 </div>
502 <table class="form-table" role="presentation">
503 <?php
504 do_settings_fields( 'squeeze_options', 'squeeze_webp_settings' );
505 ?>
506 </table>
507 </div>
508 </section>
509 <section id="squeeze_avif">
510 <div class="squeeze-box squeeze-box--settings">
511 <div class="squeeze-box-header">
512 <div class="squeeze-box-header__col">
513 <h2><?php
514 esc_html_e( 'AVIF Settings', 'squeeze' );
515 ?></h2>
516 <?php
517 $this->setting_avif_desc();
518 ?>
519 </div>
520 </div>
521 <table class="form-table" role="presentation">
522 <?php
523 do_settings_fields( 'squeeze_options', 'squeeze_avif_settings' );
524 ?>
525 </table>
526 </div>
527 </section>
528 <section id="squeeze_docs">
529 <div class="squeeze-box squeeze-box--settings">
530 <div class="squeeze-box-header">
531 <div class="squeeze-box-header__col">
532 <h2><?php
533 esc_html_e( 'Documentation', 'squeeze' );
534 ?></h2>
535 <?php
536 echo '<p>' . esc_html__( 'Documentation for Squeeze plugin.', 'squeeze' ) . '</p>';
537 ?>
538 </div>
539 </div>
540 <table class="form-table" role="presentation">
541 <tbody>
542 <tr>
543 <th scope="row" colspan="2">
544 <?php
545 echo '<p>' . sprintf( __( 'For more information, please visit the <a href="%s" target="_blank">official documentation website</a>.', 'squeeze' ) . '&nbsp;↗', esc_url( self::$DOCS_URL ) ) . '</p>';
546 ?>
547 </th>
548 </tr>
549 </tbody>
550 </table>
551 </div>
552 </section>
553 <?php
554 ?>
555 <section id="squeeze_upgrade">
556 <div class="squeeze-box squeeze-box--settings">
557 <div class="squeeze-box-header">
558 <div class="squeeze-box-header__col">
559 <h2><?php
560 esc_html_e( 'Upgrade', 'squeeze' );
561 ?></h2>
562 <?php
563 $this->setting_upgrade_desc();
564 ?>
565 </div>
566 </div>
567 <div class="squeeze-upgrade-features">
568 <?php
569 $features = [
570 ['icon-compare.svg', __( 'Image Comparison', 'squeeze' ), __( 'Compare original and Squeezed image directly in the Media Library.', 'squeeze' )],
571 ['icon-resize.svg', __( 'Resize Original Image', 'squeeze' ), __( 'Set maximum width and height for the original image.', 'squeeze' )],
572 ['icon-bulk-page.svg', __( 'Bulk Squeeze from a Page', 'squeeze' ), __( 'Compress all images from a specific page.', 'squeeze' )],
573 ['icon-exclude.svg', __( 'Image Exclusion', 'squeeze' ), __( 'Exclude specific images from bulk compression.', 'squeeze' )]
574 ];
575 foreach ( $features as $feature ) {
576 ?>
577 <div class="squeeze-box--fieldset">
578 <img src="<?php
579 echo esc_url( self::$PLUGIN_URL . 'assets/images/' . $feature[0] );
580 ?>" alt="<?php
581 echo esc_attr( $feature[1] );
582 ?>" />
583 <h3><?php
584 echo esc_html( $feature[1] );
585 ?></h3>
586 <p><?php
587 echo esc_html( $feature[2] );
588 ?></p>
589 </div>
590 <?php
591 }
592 ?>
593 </div>
594 <div class="squeeze-box-footer">
595 <h3 style="text-align: center;">
596 <?php
597 echo sprintf( __( 'To upgrade to the Premium version, <a href="%s" target="_blank">click here</a>.', 'squeeze' ), esc_url( self::CHECKOUT_URL ) );
598 ?>&nbsp;
599 </h3>
600 </div>
601 </div>
602 </section>
603 <?php
604 ?>
605
606 <?php
607 ?>
608
609 <p class="submit">
610 <input type="submit" name="submit" id="submit" class="button button-primary" value="<?php
611 esc_attr_e( 'Save Changes', 'squeeze' );
612 ?>">
613 <input name="squeeze_restore_button" class="button button-secondary" type="button" value="<?php
614 esc_attr_e( 'Restore defaults', 'squeeze' );
615 ?>" />
616 </p>
617 </form>
618 </div>
619 </div>
620 <?php
621 }
622
623 public function register_settings() {
624 $auto_webp = self::$SqueezeHelpers->get_option( 'auto_webp' );
625 $webp_lossless = self::$SqueezeHelpers->get_option( 'webp_lossless' );
626 register_setting( 'squeeze_options', 'squeeze_options', [$this, 'options_validate'] );
627 add_settings_section(
628 'squeeze_basic_settings',
629 __( 'Basic Settings', 'squeeze' ),
630 'squeeze_setting_basic_desc',
631 'squeeze_options',
632 array(
633 'section_class' => 'squeeze_basic',
634 )
635 );
636 add_settings_field(
637 'squeeze_setting_auto_compress',
638 __( 'Squeeze on upload', 'squeeze' ),
639 [$this, 'options_callback'],
640 'squeeze_options',
641 'squeeze_basic_settings',
642 array(
643 'label_for' => 'auto_compress',
644 'class' => 'squeeze_setting_auto_compress',
645 'type' => 'checkbox',
646 )
647 );
648 add_settings_field(
649 'squeeze_setting_backup_original',
650 __( 'Backup original image', 'squeeze' ),
651 [$this, 'options_callback'],
652 'squeeze_options',
653 'squeeze_basic_settings',
654 array(
655 'label_for' => 'backup_original',
656 'class' => 'squeeze_setting_backup_original',
657 'type' => 'checkbox',
658 )
659 );
660 add_settings_field(
661 'squeeze_setting_compress_formats',
662 __( 'Image formats', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Select which image formats you want to be squeezed.', 'squeeze' ) ),
663 [$this, 'options_callback'],
664 'squeeze_options',
665 'squeeze_basic_settings',
666 array(
667 'label_for' => 'compress_formats',
668 'class' => 'squeeze_setting_compress_formats',
669 'type' => 'formats_checkbox_group',
670 )
671 );
672 add_settings_field(
673 'squeeze_setting_direct_webp',
674 __( 'Direct WebP Conversion', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Convert all uploaded images to WEBP format and replace the originals. The original JPEG/PNG files are not stored on the server, which reduces disk usage.', 'squeeze' ) ),
675 [$this, 'options_callback'],
676 'squeeze_options',
677 'squeeze_basic_settings',
678 array(
679 'label_for' => 'direct_webp',
680 'class' => 'squeeze_setting_direct_webp',
681 'type' => 'checkbox',
682 'has_example' => true,
683 )
684 );
685 add_settings_field(
686 'squeeze_setting_auto_webp',
687 __( 'Generate WEBP', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Instead of the original image URL, the image will be served in WEBP format. WEBP images are stored in a separate directory: wp-content/squeeze-webp.', 'squeeze' ) . ' ' . __( 'This is the old method, in case you already have images being converted using this approach. Otherwise, it is recommended that you use the direct WEBP conversion method above.', 'squeeze' ) ),
688 [$this, 'options_callback'],
689 'squeeze_options',
690 'squeeze_basic_settings',
691 array(
692 'label_for' => 'auto_webp',
693 'class' => 'squeeze_setting_auto_webp',
694 'type' => 'checkbox',
695 'has_example' => true,
696 )
697 );
698 add_settings_field(
699 'squeeze_setting_webp_replace_urls',
700 __( 'Replace images URLs', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'If the method above does not work, try this option. This method replaces the original URLs of the images with related WEBP images.', 'squeeze' ) ),
701 [$this, 'options_callback'],
702 'squeeze_options',
703 'squeeze_basic_settings',
704 array(
705 'label_for' => 'webp_replace_urls',
706 'class' => 'squeeze_setting_webp_replace_urls',
707 'type' => 'checkbox',
708 'has_example' => true,
709 'hidden' => ( $auto_webp ? '' : true ),
710 )
711 );
712 add_settings_field(
713 'squeeze_setting_compress_thumbs',
714 __( 'Squeeze thumbnails', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Choose which image thumbnail sizes you want to squeeze along with the original image.', 'squeeze' ) ),
715 [$this, 'options_callback'],
716 'squeeze_options',
717 'squeeze_basic_settings',
718 array(
719 'label_for' => 'compress_thumbs',
720 'class' => 'squeeze_setting_compress_thumbs',
721 'type' => 'thumbs_checkbox_group',
722 )
723 );
724 add_settings_field(
725 'squeeze_setting_max_width',
726 __( 'Max. image width', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Limit a width of an original image. Leave this field empty if you do not want to crop the image by width.', 'squeeze' ) ),
727 [$this, 'options_callback'],
728 'squeeze_options',
729 'squeeze_basic_settings',
730 array(
731 'label_for' => 'max_width',
732 'class' => 'squeeze_setting_max_width',
733 'type' => 'placeholder',
734 )
735 );
736 add_settings_field(
737 'squeeze_setting_max_height',
738 __( 'Max. image height', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Limit a height of an original image. Leave this field empty if you do not want to crop the image by height.', 'squeeze' ) ),
739 [$this, 'options_callback'],
740 'squeeze_options',
741 'squeeze_basic_settings',
742 array(
743 'label_for' => 'max_height',
744 'class' => 'squeeze_setting_max_height',
745 'type' => 'placeholder',
746 )
747 );
748 add_settings_field(
749 'squeeze_setting_excluded_images',
750 __( 'Excluded images', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Enter a list of images that you want to exclude from squeezing. Both full URLs and partial strings can be used. One URL per line.', 'squeeze' ) ),
751 [$this, 'options_callback'],
752 'squeeze_options',
753 'squeeze_basic_settings',
754 array(
755 'label_for' => 'excluded_images',
756 'class' => 'squeeze_setting_excluded_images',
757 'type' => 'placeholder',
758 )
759 );
760 add_settings_field(
761 'squeeze_setting_timeout',
762 __( 'Squeeze timeout', 'squeeze' ) . self::$SqueezeHelpers->get_hint( __( 'Time limit for squeezing an image. If you get an error during image squeezing, try to increase this value.', 'squeeze' ) ),
763 [$this, 'options_callback'],
764 'squeeze_options',
765 'squeeze_basic_settings',
766 array(
767 'label_for' => 'timeout',
768 'class' => 'squeeze_setting_timeout',
769 'type' => 'number',
770 'units' => 'sec',
771 'min' => 1,
772 )
773 );
774 add_settings_field(
775 'squeeze_setting_restore_defaults',
776 '',
777 [$this, 'options_callback'],
778 'squeeze_options',
779 'squeeze_basic_settings',
780 array(
781 'label_for' => 'restore_defaults',
782 'class' => 'squeeze_setting_restore_defaults',
783 'type' => 'hidden',
784 )
785 );
786 add_settings_section(
787 'squeeze_jpeg_settings',
788 __( 'JPEG Settings', 'squeeze' ),
789 'squeeze_setting_jpeg_desc',
790 'squeeze_options',
791 array(
792 'section_class' => 'squeeze_jpeg',
793 )
794 );
795 add_settings_field(
796 'squeeze_setting_jpeg_quality',
797 __( 'Quality', 'squeeze' ),
798 [$this, 'options_callback'],
799 'squeeze_options',
800 'squeeze_jpeg_settings',
801 array(
802 'label_for' => 'jpeg_quality',
803 'class' => 'squeeze_setting_jpeg_quality',
804 'type' => 'range',
805 )
806 );
807 add_settings_field(
808 'squeeze_setting_jpeg_smoothing',
809 __( 'Smoothing', 'squeeze' ),
810 [$this, 'options_callback'],
811 'squeeze_options',
812 'squeeze_jpeg_settings',
813 array(
814 'label_for' => 'jpeg_smoothing',
815 'class' => 'squeeze_setting_jpeg_smoothing',
816 'type' => 'range',
817 )
818 );
819 add_settings_field(
820 'squeeze_setting_jpeg_baseline',
821 __( 'Pointless spec compliance', 'squeeze' ),
822 [$this, 'options_callback'],
823 'squeeze_options',
824 'squeeze_jpeg_advanced_settings',
825 array(
826 'label_for' => 'jpeg_baseline',
827 'class' => 'squeeze_setting_jpeg_baseline',
828 'type' => 'checkbox',
829 )
830 );
831 // deactivated, because throws error when enabled
832 //add_settings_field('squeeze_setting_jpeg_arithmetic', __('Arithmetic', 'squeeze'), [$this, 'options_callback'], 'squeeze_options', 'squeeze_jpeg_advanced_settings', array('label_for' => 'jpeg_arithmetic', 'class' => 'squeeze_setting_jpeg_arithmetic', 'type' => 'checkbox'));
833 add_settings_field(
834 'squeeze_setting_jpeg_progressive',
835 __( 'Progressive rendering', 'squeeze' ),
836 [$this, 'options_callback'],
837 'squeeze_options',
838 'squeeze_jpeg_advanced_settings',
839 array(
840 'label_for' => 'jpeg_progressive',
841 'class' => 'squeeze_setting_jpeg_progressive',
842 'type' => 'checkbox',
843 )
844 );
845 add_settings_field(
846 'squeeze_setting_jpeg_optimize_coding',
847 __( 'Optimize Huffman table', 'squeeze' ),
848 [$this, 'options_callback'],
849 'squeeze_options',
850 'squeeze_jpeg_advanced_settings',
851 array(
852 'label_for' => 'jpeg_optimize_coding',
853 'class' => 'squeeze_setting_jpeg_optimize_coding',
854 'type' => 'checkbox',
855 )
856 );
857 add_settings_field(
858 'squeeze_setting_jpeg_color_space',
859 __( 'Channels', 'squeeze' ),
860 [$this, 'options_callback'],
861 'squeeze_options',
862 'squeeze_jpeg_advanced_settings',
863 array(
864 'label_for' => 'jpeg_color_space',
865 'class' => 'squeeze_setting_jpeg_color_space',
866 'type' => 'select',
867 'options' => array(
868 '3' => 'YCbCr',
869 '1' => 'Grayscale',
870 '2' => 'RGB',
871 ),
872 )
873 );
874 add_settings_field(
875 'squeeze_setting_jpeg_quant_table',
876 __( 'Quantization', 'squeeze' ),
877 [$this, 'options_callback'],
878 'squeeze_options',
879 'squeeze_jpeg_advanced_settings',
880 array(
881 'label_for' => 'jpeg_quant_table',
882 'class' => 'squeeze_setting_jpeg_quant_table',
883 'type' => 'select',
884 'options' => array(
885 '0' => 'JPEG Annex K',
886 '1' => 'Flat',
887 '2' => 'MSSIM-tuned Kodak',
888 '3' => 'ImageMagick',
889 '4' => 'PSNR-HVS-M-tuned Kodak',
890 '5' => 'Klein et al',
891 '6' => 'Watson et al',
892 '7' => 'Ahumada et al',
893 '8' => 'Peterson et al',
894 ),
895 )
896 );
897 add_settings_field(
898 'squeeze_setting_jpeg_trellis_multipass',
899 __( 'Trellis multipass', 'squeeze' ),
900 [$this, 'options_callback'],
901 'squeeze_options',
902 'squeeze_jpeg_advanced_settings',
903 array(
904 'label_for' => 'jpeg_trellis_multipass',
905 'class' => 'squeeze_setting_jpeg_trellis_multipass',
906 'type' => 'checkbox',
907 )
908 );
909 add_settings_field(
910 'squeeze_setting_jpeg_trellis_opt_zero',
911 __( 'Optimize zero block runs', 'squeeze' ),
912 [$this, 'options_callback'],
913 'squeeze_options',
914 'squeeze_jpeg_advanced_settings',
915 array(
916 'label_for' => 'jpeg_trellis_opt_zero',
917 'class' => 'squeeze_setting_jpeg_trellis_opt_zero',
918 'type' => 'checkbox',
919 )
920 );
921 add_settings_field(
922 'squeeze_setting_jpeg_trellis_opt_table',
923 __( 'Optimize after trellis quantization', 'squeeze' ),
924 [$this, 'options_callback'],
925 'squeeze_options',
926 'squeeze_jpeg_advanced_settings',
927 array(
928 'label_for' => 'jpeg_trellis_opt_table',
929 'class' => 'squeeze_setting_jpeg_trellis_opt_table',
930 'type' => 'checkbox',
931 )
932 );
933 add_settings_field(
934 'squeeze_setting_jpeg_trellis_loops',
935 __( 'Trellis quantization passes', 'squeeze' ),
936 [$this, 'options_callback'],
937 'squeeze_options',
938 'squeeze_jpeg_advanced_settings',
939 array(
940 'label_for' => 'jpeg_trellis_loops',
941 'class' => 'squeeze_setting_jpeg_trellis_loops',
942 'type' => 'range',
943 'min' => 1,
944 'max' => 50,
945 )
946 );
947 add_settings_field(
948 'squeeze_setting_jpeg_auto_subsample',
949 __( 'Auto subsample chroma', 'squeeze' ),
950 [$this, 'options_callback'],
951 'squeeze_options',
952 'squeeze_jpeg_advanced_settings',
953 array(
954 'label_for' => 'jpeg_auto_subsample',
955 'class' => 'squeeze_setting_jpeg_auto_subsample',
956 'type' => 'checkbox',
957 )
958 );
959 add_settings_field(
960 'squeeze_setting_jpeg_chroma_subsample',
961 __( 'Subsample chroma by', 'squeeze' ),
962 [$this, 'options_callback'],
963 'squeeze_options',
964 'squeeze_jpeg_advanced_settings',
965 array(
966 'label_for' => 'jpeg_chroma_subsample',
967 'class' => 'squeeze_setting_jpeg_chroma_subsample',
968 'type' => 'range',
969 'min' => 1,
970 'max' => 4,
971 )
972 );
973 add_settings_field(
974 'squeeze_setting_jpeg_separate_chroma_quality',
975 __( 'Separate chroma quality', 'squeeze' ),
976 [$this, 'options_callback'],
977 'squeeze_options',
978 'squeeze_jpeg_advanced_settings',
979 array(
980 'label_for' => 'jpeg_separate_chroma_quality',
981 'class' => 'squeeze_setting_jpeg_separate_chroma_quality',
982 'type' => 'checkbox',
983 )
984 );
985 add_settings_field(
986 'squeeze_setting_jpeg_chroma_quality',
987 __( 'Chroma quality', 'squeeze' ),
988 [$this, 'options_callback'],
989 'squeeze_options',
990 'squeeze_jpeg_advanced_settings',
991 array(
992 'label_for' => 'jpeg_chroma_quality',
993 'class' => 'squeeze_setting_jpeg_chroma_quality',
994 'type' => 'range',
995 )
996 );
997 add_settings_section(
998 'squeeze_png_settings',
999 __( 'PNG Settings', 'squeeze' ),
1000 'squeeze_setting_png_desc',
1001 'squeeze_options',
1002 array(
1003 'section_class' => 'squeeze_png',
1004 )
1005 );
1006 add_settings_field(
1007 'squeeze_setting_png_quality',
1008 __( 'Quality', 'squeeze' ),
1009 [$this, 'options_callback'],
1010 'squeeze_options',
1011 'squeeze_png_settings',
1012 array(
1013 'label_for' => 'png_quality',
1014 'class' => 'squeeze_setting_png_quality',
1015 'type' => 'range',
1016 'min' => 0.01,
1017 'max' => 1,
1018 'step' => 0.01,
1019 )
1020 );
1021 add_settings_section(
1022 'squeeze_webp_settings',
1023 __( 'WEBP Settings', 'squeeze' ),
1024 'squeeze_setting_webp_desc',
1025 'squeeze_options',
1026 array(
1027 'section_class' => 'squeeze_webp',
1028 )
1029 );
1030 add_settings_field(
1031 'squeeze_setting_webp_method',
1032 __( 'Effort', 'squeeze' ),
1033 [$this, 'options_callback'],
1034 'squeeze_options',
1035 'squeeze_webp_settings',
1036 array(
1037 'label_for' => 'webp_method',
1038 'class' => 'squeeze_setting_webp_method',
1039 'type' => 'range',
1040 'min' => 0,
1041 'max' => 6,
1042 )
1043 );
1044 add_settings_field(
1045 'squeeze_setting_webp_quality',
1046 __( 'Quality', 'squeeze' ),
1047 [$this, 'options_callback'],
1048 'squeeze_options',
1049 'squeeze_webp_settings',
1050 array(
1051 'label_for' => 'webp_quality',
1052 'class' => 'squeeze_setting_webp_quality',
1053 'type' => 'range',
1054 'min' => 0,
1055 'max' => 100,
1056 'hidden' => ( $webp_lossless ? true : '' ),
1057 )
1058 );
1059 add_settings_field(
1060 'squeeze_setting_webp_lossless',
1061 __( 'Lossless', 'squeeze' ),
1062 [$this, 'options_callback'],
1063 'squeeze_options',
1064 'squeeze_webp_settings',
1065 array(
1066 'label_for' => 'webp_lossless',
1067 'class' => 'squeeze_setting_webp_lossless',
1068 'type' => 'checkbox',
1069 )
1070 );
1071 add_settings_field(
1072 'squeeze_setting_webp_near_lossless',
1073 __( 'Near lossless', 'squeeze' ),
1074 [$this, 'options_callback'],
1075 'squeeze_options',
1076 'squeeze_webp_settings',
1077 array(
1078 'label_for' => 'webp_near_lossless',
1079 'class' => 'squeeze_setting_webp_near_lossless',
1080 'type' => 'range',
1081 'min' => 0,
1082 'max' => 100,
1083 )
1084 );
1085 add_settings_section(
1086 'squeeze_avif_settings',
1087 __( 'AVIF Settings', 'squeeze' ),
1088 'squeeze_setting_avif_desc',
1089 'squeeze_options',
1090 array(
1091 'section_class' => 'squeeze_avif',
1092 )
1093 );
1094 add_settings_field(
1095 'squeeze_setting_avif_cqLevel',
1096 __( 'Quality', 'squeeze' ),
1097 [$this, 'options_callback'],
1098 'squeeze_options',
1099 'squeeze_avif_settings',
1100 array(
1101 'label_for' => 'avif_cqLevel',
1102 'class' => 'squeeze_setting_avif_cqLevel',
1103 'type' => 'range',
1104 'min' => 1,
1105 'max' => 100,
1106 )
1107 );
1108 }
1109
1110 public function options_validate( $input ) {
1111 $input['jpeg_quality'] = absint( $input['jpeg_quality'] );
1112 $input['jpeg_smoothing'] = ( isset( $input['jpeg_smoothing'] ) ? absint( $input['jpeg_smoothing'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_smoothing' ) );
1113 $input['jpeg_color_space'] = ( isset( $input['jpeg_color_space'] ) ? absint( $input['jpeg_color_space'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_color_space' ) );
1114 $input['jpeg_quant_table'] = ( isset( $input['jpeg_quant_table'] ) ? absint( $input['jpeg_quant_table'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_quant_table' ) );
1115 $input['jpeg_trellis_loops'] = ( isset( $input['jpeg_trellis_loops'] ) ? absint( $input['jpeg_trellis_loops'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_trellis_loops' ) );
1116 $input['jpeg_chroma_subsample'] = ( isset( $input['jpeg_chroma_subsample'] ) ? absint( $input['jpeg_chroma_subsample'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_chroma_subsample' ) );
1117 $input['jpeg_chroma_quality'] = ( isset( $input['jpeg_chroma_quality'] ) ? absint( $input['jpeg_chroma_quality'] ) : self::$SqueezeHelpers->get_default_value( 'jpeg_chroma_quality' ) );
1118 $input['png_level'] = ( isset( $input['png_level'] ) ? absint( $input['png_level'] ) : self::$SqueezeHelpers->get_default_value( 'png_level' ) );
1119 $input['png_quality'] = ( isset( $input['png_quality'] ) ? floatval( $input['png_quality'] ) : self::$SqueezeHelpers->get_default_value( 'png_quality' ) );
1120 $input['webp_method'] = ( isset( $input['webp_method'] ) ? absint( $input['webp_method'] ) : self::$SqueezeHelpers->get_default_value( 'webp_method' ) );
1121 $input['webp_quality'] = ( isset( $input['webp_quality'] ) ? absint( $input['webp_quality'] ) : self::$SqueezeHelpers->get_default_value( 'webp_quality' ) );
1122 $input['webp_near_lossless'] = ( isset( $input['webp_near_lossless'] ) ? absint( $input['webp_near_lossless'] ) : self::$SqueezeHelpers->get_default_value( 'webp_near_lossless' ) );
1123 $input['avif_cqLevel'] = ( isset( $input['avif_cqLevel'] ) ? absint( $input['avif_cqLevel'] ) : self::$SqueezeHelpers->get_default_value( 'avif_cqLevel' ) );
1124 $input['jpeg_baseline'] = ( isset( $input['jpeg_baseline'] ) ? boolval( $input['jpeg_baseline'] ) : '0' );
1125 //$input[ 'jpeg_arithmetic' ] = isset($input[ 'jpeg_arithmetic' ]) ? boolval($input[ 'jpeg_arithmetic' ]) : '0';
1126 $input['jpeg_progressive'] = ( isset( $input['jpeg_progressive'] ) ? boolval( $input['jpeg_progressive'] ) : '0' );
1127 $input['jpeg_optimize_coding'] = ( isset( $input['jpeg_optimize_coding'] ) ? boolval( $input['jpeg_optimize_coding'] ) : '0' );
1128 $input['jpeg_trellis_multipass'] = ( isset( $input['jpeg_trellis_multipass'] ) ? boolval( $input['jpeg_trellis_multipass'] ) : '0' );
1129 $input['jpeg_trellis_opt_zero'] = ( isset( $input['jpeg_trellis_opt_zero'] ) ? boolval( $input['jpeg_trellis_opt_zero'] ) : '0' );
1130 $input['jpeg_trellis_opt_table'] = ( isset( $input['jpeg_trellis_opt_table'] ) ? boolval( $input['jpeg_trellis_opt_table'] ) : '0' );
1131 $input['jpeg_auto_subsample'] = ( isset( $input['jpeg_auto_subsample'] ) ? boolval( $input['jpeg_auto_subsample'] ) : '0' );
1132 $input['jpeg_separate_chroma_quality'] = ( isset( $input['jpeg_separate_chroma_quality'] ) ? boolval( $input['jpeg_separate_chroma_quality'] ) : '0' );
1133 $input['png_interlace'] = ( isset( $input['png_interlace'] ) ? boolval( $input['png_interlace'] ) : '0' );
1134 $input['webp_lossless'] = ( isset( $input['webp_lossless'] ) ? boolval( $input['webp_lossless'] ) : '0' );
1135 $input['auto_compress'] = ( isset( $input['auto_compress'] ) ? boolval( $input['auto_compress'] ) : '0' );
1136 // TBD: maybe get default value from the database
1137 $input['auto_webp'] = ( isset( $input['auto_webp'] ) ? boolval( $input['auto_webp'] ) : '0' );
1138 $input['webp_replace_urls'] = ( isset( $input['webp_replace_urls'] ) && $input['auto_webp'] ? boolval( $input['webp_replace_urls'] ) : '0' );
1139 $input['direct_webp'] = ( isset( $input['direct_webp'] ) ? boolval( $input['direct_webp'] ) : '0' );
1140 $input['cdn_url'] = ( isset( $input['cdn_url'] ) && $input['auto_webp'] ? $input['cdn_url'] : '' );
1141 $input['backup_original'] = ( isset( $input['backup_original'] ) ? boolval( $input['backup_original'] ) : '0' );
1142 $input['compress_formats'] = ( isset( $input['compress_formats'] ) && is_array( $input['compress_formats'] ) ? $this->validate_image_formats( $input['compress_formats'], $input['direct_webp'] ) : array() );
1143 $input['compress_thumbs'] = ( isset( $input['compress_thumbs'] ) && is_array( $input['compress_thumbs'] ) ? $input['compress_thumbs'] : array() );
1144 $input['max_width'] = ( isset( $input['max_width'] ) && $input['max_width'] > 0 ? absint( $input['max_width'] ) : '' );
1145 $input['max_height'] = ( isset( $input['max_height'] ) && $input['max_height'] > 0 ? absint( $input['max_height'] ) : '' );
1146 $input['excluded_images'] = ( isset( $input['excluded_images'] ) ? $input['excluded_images'] : '' );
1147 $input['timeout'] = ( isset( $input['timeout'] ) && $input['timeout'] > 0 ? absint( $input['timeout'] ) : 1 );
1148 $input['restore_defaults'] = ( isset( $input['restore_defaults'] ) ? $input['restore_defaults'] : '0' );
1149 if ( !isset( $input['restore_defaults'] ) || $input['restore_defaults'] !== '1' ) {
1150 add_settings_error(
1151 'squeeze_notices',
1152 'settings_updated',
1153 __( 'Settings have been updated.', 'squeeze' ),
1154 'success'
1155 );
1156 }
1157 return $input;
1158 }
1159
1160 protected function validate_image_formats( $input, $is_direct_webp = false ) {
1161 $formats = self::ALLOWED_IMAGE_FORMATS;
1162 if ( !isset( $input ) || !is_array( $input ) ) {
1163 return array();
1164 }
1165 // remove all formats that are not in the allowed formats list
1166 $input = array_filter( $input, function ( $format ) use($formats) {
1167 //check by key
1168 return array_key_exists( $format, $formats );
1169 }, ARRAY_FILTER_USE_KEY );
1170 // if direct webp conversion is enabled, webp format is mandatory
1171 if ( $is_direct_webp && !array_key_exists( 'webp', $input ) ) {
1172 $input['webp'] = 'on';
1173 }
1174 return $input;
1175 }
1176
1177 public function options_callback( $args ) {
1178 $label_for = ( isset( $args['label_for'] ) ? $args['label_for'] : '' );
1179 if ( empty( $label_for ) ) {
1180 return;
1181 }
1182 $type = ( isset( $args['type'] ) ? $args['type'] : 'text' );
1183 $class = ( isset( $args['class'] ) ? $args['class'] : '' );
1184 $default = self::$SqueezeHelpers->get_default_value( $label_for );
1185 $options = get_option( 'squeeze_options' );
1186 $is_hidden = ( isset( $args['hidden'] ) && $args['hidden'] ? 'hidden' : '' );
1187 $has_example = ( isset( $args['has_example'] ) && $args['has_example'] ? true : false );
1188 $extra_classes = [];
1189 if ( $is_hidden ) {
1190 $extra_classes[] = 'squeeze-hidden';
1191 }
1192 $extra_classes = implode( ' ', $extra_classes );
1193 switch ( $type ) {
1194 case 'text':
1195 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1196 $placeholder = ( isset( $args['placeholder'] ) ? $args['placeholder'] : '' );
1197 echo "<input class='" . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]' type='text' value='" . esc_attr( $value ) . "' placeholder='" . esc_attr( $placeholder ) . "' />";
1198 break;
1199 case 'number':
1200 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1201 $units = ( isset( $args['units'] ) ? $args['units'] : '' );
1202 $min = ( isset( $args['min'] ) ? $args['min'] : '' );
1203 $max = ( isset( $args['max'] ) ? $args['max'] : '' );
1204 echo "<input class='" . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]' type='number' value='" . esc_attr( $value ) . "' " . (( $min ? "min='" . esc_attr( $min ) . "'" : "" )) . " " . (( $max ? "min='" . esc_attr( $max ) . "'" : "" )) . " />";
1205 if ( $units ) {
1206 echo "<span class='squeeze-setting-units'>" . esc_html( $units ) . "</span>";
1207 }
1208 break;
1209 case 'range':
1210 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1211 $min = ( isset( $args['min'] ) ? $args['min'] : 0 );
1212 $max = ( isset( $args['max'] ) ? $args['max'] : 100 );
1213 $step = ( isset( $args['step'] ) ? $args['step'] : 1 );
1214 echo "<input class='" . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]' min='" . (int) $min . "' max='" . (int) $max . "' step='" . floatval( $step ) . "' type='range' value='" . esc_attr( $value ) . "' />";
1215 echo '<output id="squeeze_setting_' . esc_attr( $label_for ) . '_value"></output>';
1216 ?>
1217 <script>
1218 (function () {
1219 const value = document.querySelector("#squeeze_setting_<?php
1220 echo esc_attr( $label_for );
1221 ?>_value")
1222 const input = document.querySelector("#squeeze_setting_<?php
1223 echo esc_attr( $label_for );
1224 ?>")
1225 value.textContent = input.value
1226 input.addEventListener("input", (event) => {
1227 value.textContent = event.target.value
1228 })
1229 })()
1230 </script>
1231 <?php
1232 break;
1233 case 'checkbox':
1234 $value = ( isset( $options[$label_for] ) ? (bool) $options[$label_for] : $default );
1235 //echo (bool)$options[ $label_for ];
1236 echo "<input class='squeeze-ios8-switch " . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]' type='checkbox' " . checked( $value, true, false ) . " />";
1237 echo '<label for="squeeze_setting_' . esc_attr( $label_for ) . '"></label>';
1238 break;
1239 case 'select':
1240 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1241 echo "<select class='" . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]'>";
1242 foreach ( $args['options'] as $key => $option ) {
1243 echo "<option value='" . esc_attr( $key ) . "'" . selected( $value, $key, false ) . ">" . esc_html( $option ) . "</option>";
1244 }
1245 echo "</select>";
1246 break;
1247 case 'thumbs_checkbox_group':
1248 $thumbs = array();
1249 $value = ( isset( $options[$label_for] ) ? (array) $options[$label_for] : $default );
1250 $available_sizes = wp_get_registered_image_subsizes();
1251 foreach ( $available_sizes as $key => $size ) {
1252 $thumbs[$key] = ucwords( str_replace( '_', ' ', $key ) ) . ' (' . $size['width'] . 'x' . $size['height'] . ')';
1253 }
1254 // Add the scaled image size option
1255 $big_image_size_threshold = apply_filters( 'big_image_size_threshold', 2560 );
1256 $thumbs['full'] = 'Scaled (' . $big_image_size_threshold . 'x' . $big_image_size_threshold . ')';
1257 echo '<div class="squeeze-box squeeze-box--fieldset">';
1258 echo '<div class="squeeze-box-content">';
1259 foreach ( $thumbs as $key => $option ) {
1260 echo '<div class="squeeze-suboption">';
1261 echo "<input class='squeeze-ios8-switch' id='squeeze_setting_" . esc_attr( $label_for ) . "_" . esc_attr( $key ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "][" . esc_attr( $key ) . "]' type='checkbox' " . checked( array_key_exists( $key, $value ), true, false ) . " /> ";
1262 echo "<label for='squeeze_setting_" . esc_attr( $label_for ) . "_" . esc_attr( $key ) . "'>" . esc_html( $option ) . "</label>";
1263 echo '</div>';
1264 }
1265 echo '</div>';
1266 echo '</div>';
1267 break;
1268 case 'formats_checkbox_group':
1269 $is_direct_webp = ( isset( $options['direct_webp'] ) ? (bool) $options['direct_webp'] : false );
1270 $formats = self::ALLOWED_IMAGE_FORMATS;
1271 $value = ( isset( $options[$label_for] ) ? (array) $options[$label_for] : $default );
1272 echo '<div class="squeeze-box squeeze-box--fieldset">';
1273 echo '<div class="squeeze-box-content">';
1274 foreach ( $formats as $key => $option ) {
1275 echo '<div class="squeeze-suboption ' . (( $is_direct_webp && $key === 'webp' ? 'squeeze-disabled' : '' )) . '">';
1276 echo "<input class='squeeze-ios8-switch' id='squeeze_setting_" . esc_attr( $label_for ) . "_" . esc_attr( $key ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "][" . esc_attr( $key ) . "]' type='checkbox' " . checked( array_key_exists( $key, $value ), true, false ) . " /> ";
1277 echo "<label for='squeeze_setting_" . esc_attr( $label_for ) . "_" . esc_attr( $key ) . "'>" . esc_html( $key ) . "</label>";
1278 if ( $is_direct_webp && $key === 'webp' ) {
1279 echo '<span class="squeeze-hint">' . __( '(mandatory when Direct WEBP is enabled)', 'squeeze' ) . '</span>';
1280 }
1281 echo '</div>';
1282 }
1283 echo '</div>';
1284 echo '</div>';
1285 break;
1286 case 'hidden':
1287 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1288 echo "<input id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]' type='hidden' value='" . esc_attr( $value ) . "' />";
1289 break;
1290 case 'textarea':
1291 $value = ( isset( $options[$label_for] ) ? $options[$label_for] : $default );
1292 echo "<textarea class='" . esc_attr( $extra_classes ) . "' id='squeeze_setting_" . esc_attr( $label_for ) . "' name='squeeze_options[" . esc_attr( $label_for ) . "]'>" . esc_textarea( $value ) . "</textarea>";
1293 break;
1294 case 'placeholder':
1295 echo '<p>' . sprintf( __( 'This feature is available only in the <a href="%s">premium version</a>.', 'squeeze' ), esc_url( self::$UPGRADE_URL ) ) . '</p>';
1296 break;
1297 }
1298 if ( $has_example ) {
1299 $value = ( isset( $options[$label_for] ) ? (bool) $options[$label_for] : $default );
1300 echo '<div class="squeeze-settings-example squeeze-settings-example--' . $label_for . (( $value ? ' enabled' : '' )) . '">';
1301 switch ( $label_for ) {
1302 case 'direct_webp':
1303 ?>
1304 <span class="squeeze-hint"><?php
1305 echo __( "Example:", 'squeeze' );
1306 ?></span>
1307 <div class="squeeze-box squeeze-box--fieldset">
1308 <div class="squeeze-box-content">
1309 <p><strong><?php
1310 echo __( 'Before', 'squeeze' );
1311 ?></strong></p>
1312 <p><span><?php
1313 echo __( 'image.jpg', 'squeeze' );
1314 ?></span> <span><?php
1315 echo __( '500 KB', 'squeeze' );
1316 ?></span></p>
1317 <p><span><?php
1318 echo __( 'image-100x100.jpg', 'squeeze' );
1319 ?></span> <span><?php
1320 echo __( '98 KB', 'squeeze' );
1321 ?></span></p>
1322 <p><span><?php
1323 echo __( 'image-300x300.jpg', 'squeeze' );
1324 ?></span> <span><?php
1325 echo __( '230 KB', 'squeeze' );
1326 ?></span></p>
1327 </div>
1328 <div class="squeeze-box-content">
1329 <p><strong><?php
1330 echo __( 'After', 'squeeze' );
1331 ?></strong></p>
1332 <p><span class="striked"><?php
1333 echo __( 'image.jpg', 'squeeze' );
1334 ?></span> <span><?php
1335 echo __( '500 KB', 'squeeze' );
1336 ?></span></p>
1337 <p><span class="striked"><?php
1338 echo __( 'image-100x100.jpg', 'squeeze' );
1339 ?></span> <span><?php
1340 echo __( '98 KB', 'squeeze' );
1341 ?></span></p>
1342 <p><span class="striked"><?php
1343 echo __( 'image-300x300.jpg', 'squeeze' );
1344 ?></span> <span><?php
1345 echo __( '230 KB', 'squeeze' );
1346 ?></span></p>
1347 <p><span class="greened"><?php
1348 echo __( 'image.webp', 'squeeze' );
1349 ?></span> <span><?php
1350 echo __( '50 KB', 'squeeze' );
1351 ?></span></p>
1352 <p><span class="greened"><?php
1353 echo __( 'image-100x100.webp', 'squeeze' );
1354 ?></span> <span><?php
1355 echo __( '5 KB', 'squeeze' );
1356 ?></span></p>
1357 <p><span class="greened"><?php
1358 echo __( 'image-300x300.webp', 'squeeze' );
1359 ?></span> <span><?php
1360 echo __( '20 KB', 'squeeze' );
1361 ?></span></p>
1362 </div>
1363 </div>
1364 <?php
1365 break;
1366 case 'auto_webp':
1367 ?>
1368 <span class="squeeze-hint"><?php
1369 echo __( "Example:", 'squeeze' );
1370 ?></span>
1371 <div class="squeeze-box squeeze-box--fieldset">
1372 <div class="squeeze-box-content">
1373 <p><strong><?php
1374 echo __( 'Before', 'squeeze' );
1375 ?></strong></p>
1376 <code><?php
1377 echo __( '/uploads/2025/07/', 'squeeze' );
1378 ?></code>
1379 <p><span><?php
1380 echo __( 'image.jpg', 'squeeze' );
1381 ?></span> <span><?php
1382 echo __( '500 KB', 'squeeze' );
1383 ?></span></p>
1384 <p><span><?php
1385 echo __( 'image-100x100.jpg', 'squeeze' );
1386 ?></span> <span><?php
1387 echo __( '98 KB', 'squeeze' );
1388 ?></span></p>
1389 <p><span><?php
1390 echo __( 'image-300x300.jpg', 'squeeze' );
1391 ?></span> <span><?php
1392 echo __( '230 KB', 'squeeze' );
1393 ?></span></p>
1394 </div>
1395 <div class="squeeze-box-content">
1396 <p><strong><?php
1397 echo __( 'After', 'squeeze' );
1398 ?></strong></p>
1399 <code><?php
1400 echo __( '/uploads/2025/07/', 'squeeze' );
1401 ?></code>
1402 <p><span class="greened"><?php
1403 echo __( 'image.jpg', 'squeeze' );
1404 ?></span> <span><?php
1405 echo __( '100 KB', 'squeeze' );
1406 ?></span></p>
1407 <p><span class="greened"><?php
1408 echo __( 'image-100x100.jpg', 'squeeze' );
1409 ?></span> <span><?php
1410 echo __( '15 KB', 'squeeze' );
1411 ?></span></p>
1412 <p><span class="greened"><?php
1413 echo __( 'image-300x300.jpg', 'squeeze' );
1414 ?></span> <span><?php
1415 echo __( '40 KB', 'squeeze' );
1416 ?></span></p>
1417 <code><?php
1418 echo __( '/squeeze-webp/uploads/2025/07/', 'squeeze' );
1419 ?></code>
1420 <p><span class="greened"><?php
1421 echo __( 'image.webp', 'squeeze' );
1422 ?></span> <span><?php
1423 echo __( '50 KB', 'squeeze' );
1424 ?></span></p>
1425 <p><span class="greened"><?php
1426 echo __( 'image-100x100.webp', 'squeeze' );
1427 ?></span> <span><?php
1428 echo __( '5 KB', 'squeeze' );
1429 ?></span></p>
1430 <p><span class="greened"><?php
1431 echo __( 'image-300x300.webp', 'squeeze' );
1432 ?></span> <span><?php
1433 echo __( '20 KB', 'squeeze' );
1434 ?></span></p>
1435 </div>
1436 </div>
1437 <?php
1438 break;
1439 case 'webp_replace_urls':
1440 ?>
1441 <span class="squeeze-hint"><?php
1442 echo __( "Example:", 'squeeze' );
1443 ?></span>
1444 <div class="squeeze-box squeeze-box--fieldset">
1445 <div class="squeeze-box-content">
1446 <img src="<?php
1447 echo esc_url( plugin_dir_url( __FILE__ ) . '../assets/images/replace_urls.jpg' );
1448 ?>" alt="<?php
1449 echo esc_attr__( 'Example image', 'squeeze' );
1450 ?>">
1451 </div>
1452 </div>
1453 <?php
1454 break;
1455 }
1456 echo '</div>';
1457 }
1458 }
1459
1460 public function setting_basic_desc() {
1461 echo '<p>' . esc_html__( 'Basic squeezing settings.', 'squeeze' ) . '</p>';
1462 }
1463
1464 public function setting_jpeg_desc() {
1465 echo '<p>' . esc_html__( 'Squeezing settings for JPEG images.', 'squeeze' ) . '</p>';
1466 }
1467
1468 public function setting_jpeg_advanced_desc() {
1469 echo '<p>' . esc_html__( 'More precise settings for experienced users.', 'squeeze' ) . '</p>';
1470 }
1471
1472 public function setting_png_desc() {
1473 echo '<p>' . esc_html__( 'Squeezing settings for PNG images.', 'squeeze' ) . '</p>';
1474 }
1475
1476 public function setting_webp_desc() {
1477 echo '<p>' . esc_html__( 'Squeezing settings for WebP images.', 'squeeze' ) . '</p>';
1478 }
1479
1480 public function setting_avif_desc() {
1481 echo '<p>' . esc_html__( 'Squeezing settings for Avif images.', 'squeeze' ) . '</p>';
1482 }
1483
1484 public function setting_upgrade_desc() {
1485 echo '<p>' . esc_html__( 'Upgrade to premium version for more features.', 'squeeze' ) . '</p>';
1486 }
1487
1488 public function setting_license_desc() {
1489 }
1490
1491 public function restore_defaults( $old_value, $value ) {
1492 if ( isset( $value['restore_defaults'] ) && $value['restore_defaults'] === '1' ) {
1493 $result = delete_option( 'squeeze_options', "" );
1494 if ( $result ) {
1495 add_settings_error(
1496 'squeeze_notices',
1497 'settings_restored',
1498 __( 'Settings have been restored.', 'squeeze' ),
1499 'success'
1500 );
1501 } else {
1502 add_settings_error(
1503 'squeeze_notices',
1504 'settings_not_restored',
1505 __( 'Settings have not been restored.', 'squeeze' ),
1506 'error'
1507 );
1508 }
1509 }
1510 }
1511
1512 public function flush_rewrite_rules( $old_value, $value ) {
1513 if ( isset( $value['auto_webp'] ) && $value['auto_webp'] !== $old_value['auto_webp'] ) {
1514 flush_rewrite_rules();
1515 add_settings_error(
1516 'squeeze_notices',
1517 'rewrite_rules_flushed',
1518 __( 'Rewrite rules have been flushed.', 'squeeze' ),
1519 'success'
1520 );
1521 }
1522 }
1523
1524 public function add_custom_field_to_attachment( $form_fields, $post ) {
1525 $all_formats = self::ALLOWED_IMAGE_FORMATS;
1526 $all_mimes = self::$SqueezeHelpers->get_image_formats( true, $all_formats );
1527 if ( in_array( $post->post_mime_type, $all_mimes ) ) {
1528 $selected_mimes = self::$SqueezeHelpers->get_image_formats( true );
1529 $is_compressed = get_post_meta( $post->ID, 'squeeze_is_compressed', true );
1530 $can_restore = self::$SqueezeHelpers->can_restore( $post->ID );
1531 $is_excluded = false;
1532 $form_fields['squeeze_is_compressed'] = array(
1533 'label' => __( 'Squeeze', 'squeeze' ),
1534 'input' => 'html',
1535 'html' => ( !in_array( $post->post_mime_type, $selected_mimes ) ? '<span class="squeeze_status"><span style="padding-top: 0; line-height: 1; color: gray;" class="dashicons dashicons-info"></span>&nbsp;' . __( 'Image format is not selected for compression in the plugin settings', 'squeeze' ) . '</span><br>' : (( $is_excluded ? '<span class="squeeze_status"><span style="padding-top: 0; line-height: 1; color: #6c757d;" class="dashicons dashicons-hidden"></span>&nbsp;' . __( 'Image is excluded from compression', 'squeeze' ) . ' (' . esc_html__( 'found substring: ', 'squeeze' ) . $is_excluded['exclude_reason'] . ')</span>' : (( $is_compressed ? '<p><span class="squeeze_status"><span style="padding-top: 0; line-height: 1; color: #6BCB77;" class="dashicons dashicons-performance"></span>&nbsp;' . __( 'Squeezed', 'squeeze' ) . '</span></p>' . (( $can_restore ? '
1536 <p><button name="squeeze_restore" type="button" class="button button-secondary squeeze-restore-button" data-attachment="' . $post->ID . '">' . __( 'Restore original image', 'squeeze' ) . '</button></p>' : '' )) . '
1537 <p><button name="squeeze_compress_again" type="button" class="button button-primary squeeze-compress-button" data-attachment="' . $post->ID . '">' . __( 'Re-Squeeze image', 'squeeze' ) . '</button></p>' : '<p><span class="squeeze_status"><span style="padding-top: 0; line-height: 1; color: #FFD93D; scale: -1 1;" class="dashicons dashicons-performance"></span>&nbsp;' . __( 'Not squeezed', 'squeeze' ) . '</span></p>
1538 <p><button name="squeeze_compress_single" type="button" class="button button-primary squeeze-compress-button" data-attachment="' . $post->ID . '">' . __( 'Squeeze Now', 'squeeze' ) . '</button></p>' )) )) ),
1539 );
1540 }
1541 return $form_fields;
1542 }
1543
1544 public function add_media_columns( $posts_columns ) {
1545 $posts_columns['squeeze'] = __( 'Squeeze', 'squeeze' );
1546 return $posts_columns;
1547 }
1548
1549 public function media_custom_column( $column_name, $post_id ) {
1550 if ( 'squeeze' !== $column_name ) {
1551 return;
1552 }
1553 $form_fields = $this->add_custom_field_to_attachment( array(), get_post( $post_id ) );
1554 if ( $form_fields ) {
1555 echo wp_kses_post( $form_fields['squeeze_is_compressed']['html'] );
1556 }
1557 }
1558
1559 public function sortable_columns( $columns ) {
1560 $columns['squeeze'] = 'squeeze';
1561 return $columns;
1562 }
1563
1564 public function sortable_columns_orderby( $query ) {
1565 if ( !is_admin() || !$query->is_main_query() ) {
1566 return;
1567 }
1568 $orderby = $query->get( 'orderby' );
1569 if ( 'squeeze' === $orderby ) {
1570 // Define the allowed image formats
1571 $allowed_formats = self::$SqueezeHelpers->get_image_formats( true );
1572 // include all media
1573 $query->set( 'meta_query', array(
1574 'relation' => 'OR',
1575 array(
1576 'key' => 'squeeze_is_compressed',
1577 'compare' => 'NOT EXISTS',
1578 ),
1579 array(
1580 'key' => 'squeeze_is_compressed',
1581 'compare' => 'EXISTS',
1582 ),
1583 ) );
1584 // Add the meta_query to filter by specific image formats
1585 //$query->set('post_mime_type', $allowed_formats);
1586 $query->set( 'orderby', 'meta_value' );
1587 }
1588 }
1589
1590 public function media_filter_dropdown() {
1591 global $wp_query;
1592 $post_type = 'attachment';
1593 if ( isset( $_GET['post_type'] ) ) {
1594 $post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) );
1595 }
1596 if ( 'attachment' !== $post_type ) {
1597 return;
1598 }
1599 $selected = ( isset( $_GET['squeeze_filter'] ) ? sanitize_text_field( wp_unslash( $_GET['squeeze_filter'] ) ) : '' );
1600 $options = array(
1601 'all' => __( 'Squeeze: All images', 'squeeze' ),
1602 'non-squeezed' => __( 'Non Squeezed Images', 'squeeze' ),
1603 );
1604 echo '<select name="squeeze_filter" id="squeeze-filter">';
1605 foreach ( $options as $value => $label ) {
1606 printf(
1607 '<option value="%s"%s>%s</option>',
1608 esc_attr( $value ),
1609 selected( $selected, $value, false ),
1610 esc_html( $label )
1611 );
1612 }
1613 echo '</select>';
1614 }
1615
1616 public function media_filter_query( $query ) {
1617 global $current_screen;
1618 if ( !is_admin() || !empty( $current_screen ) && 'upload' !== $current_screen->base || 'attachment' !== $query->get( 'post_type' ) ) {
1619 return $query;
1620 }
1621 if ( isset( $_GET['squeeze_filter'] ) ) {
1622 $squeeze_filter = sanitize_text_field( wp_unslash( $_GET['squeeze_filter'] ) );
1623 if ( 'non-squeezed' === $squeeze_filter ) {
1624 $query->set( 'meta_query', array(
1625 'relation' => 'OR',
1626 array(
1627 'key' => 'squeeze_is_compressed',
1628 'compare' => '!=',
1629 'value' => '1',
1630 ),
1631 array(
1632 'key' => 'squeeze_is_compressed',
1633 'compare' => 'NOT EXISTS',
1634 ),
1635 ) );
1636 $query->set( 'orderby', 'meta_value' );
1637 $query->set( 'post_mime_type', self::$SqueezeHelpers->get_image_formats( true ) );
1638 }
1639 }
1640 return $query;
1641 }
1642
1643 public function media_filter_ajax_query( $query ) {
1644 if ( !isset( $_POST['query']['squeeze_filter'] ) ) {
1645 return $query;
1646 }
1647 $squeeze_filter = sanitize_text_field( wp_unslash( $_POST['query']['squeeze_filter'] ) );
1648 if ( 'non-squeezed' === $squeeze_filter ) {
1649 $query['meta_query'] = array(
1650 'relation' => 'OR',
1651 array(
1652 'key' => 'squeeze_is_compressed',
1653 'compare' => '!=',
1654 'value' => '1',
1655 ),
1656 array(
1657 'key' => 'squeeze_is_compressed',
1658 'compare' => 'NOT EXISTS',
1659 ),
1660 );
1661 $query['orderby'] = 'meta_value';
1662 $query['post_mime_type'] = self::$SqueezeHelpers->get_image_formats( true );
1663 }
1664 return $query;
1665 }
1666
1667 public function svg_sprite_output() {
1668 global $pagenow;
1669 if ( $pagenow === 'upload.php' && isset( $_GET['page'] ) && $_GET['page'] === 'squeeze-bulk' ) {
1670 include self::$PLUGIN_DIR . 'assets/images/sprite.svg';
1671 }
1672 }
1673
1674 public function add_preview_button_placeholder( $post ) {
1675 if ( !wp_attachment_is_image( $post->ID ) ) {
1676 return;
1677 }
1678 echo '<div class="squeeze-preview-button is-placeholder">';
1679 echo '<input type="checkbox" disabled class="squeeze-ios8-switch" id="squeeze-ios8-switch"><label for="squeeze-ios8-switch" title="' . esc_attr__( "Image comparison with Squeeze", "squeeze" ) . '">' . esc_html__( "Compare Squeeze", "squeeze" ) . ' ';
1680 echo sprintf( __( '(<a href="%s" target="_blank">premium only</a>)', 'squeeze' ), esc_url( self::$UPGRADE_URL ) ) . '</label>';
1681 echo '</div>';
1682 }
1683
1684 public function incompatibility_notices() {
1685 // Bail if we're not in the admin or the screen helper isn't available.
1686 if ( !is_admin() || !function_exists( 'get_current_screen' ) ) {
1687 return;
1688 }
1689 $screen = get_current_screen();
1690 // List of screen IDs where we want the warning.
1691 $target_screens = array(
1692 'settings_page_squeeze',
1693 // options-general.php?page=squeeze
1694 'media_page_squeeze-bulk',
1695 // upload.php?page=squeeze-bulk
1696 'upload',
1697 // the core Media → Library (list table)
1698 'media',
1699 // the core Media → Add New
1700 'plugins',
1701 );
1702 if ( !in_array( $screen->id, $target_screens ) ) {
1703 return;
1704 }
1705 // check if webp-express/webp-express.php plugin is active and show a notice
1706 if ( is_plugin_active( 'webp-express/webp-express.php' ) ) {
1707 ?>
1708 <div class="notice notice-warning is-dismissible">
1709 <p>
1710 <?php
1711 echo __( 'The WebP Express plugin is active. Please deactivate it in order to use correct WebP serving from <strong>Squeeze plugin</strong>.', 'squeeze' );
1712 ?>
1713 </p>
1714 </div>
1715 <?php
1716 }
1717 // check if image-converter-webp/image-converter-webp.php plugin is active and show a notice
1718 if ( is_plugin_active( 'image-converter-webp/image-converter-webp.php' ) ) {
1719 ?>
1720 <div class="notice notice-warning is-dismissible">
1721 <p>
1722 <?php
1723 echo __( 'The Image Converter for WebP plugin is active. Please deactivate it in order to use correct WebP serving from <strong>Squeeze plugin</strong>.', 'squeeze' );
1724 ?>
1725 </p>
1726 </div>
1727 <?php
1728 }
1729 }
1730
1731 }
1732