PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.1
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.1
4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
← All changes | admin/class-settings.php +281 -69 3.2.54.1.1 View file →
@@ -9,8 +9,11 @@
9 9 * @subpackage Quickwebp/admin
10 10 */
11 11 class Quickwebp_Settings {
12 12
13 + const QUICKWEBP_GET_LICENSE_URL = 'https://solutions.leyoweb.com/products/quickwebp/';
14 + const QUICKWEBP_GET_MY_ACCOUNT_URL = 'https://solutions.leyoweb.com/customer-dashboard/';
15 +
13 16 /**
14 17 * The ID of this plugin.
15 18 *
16 19 * @since 1.0.0
@@ -52,13 +55,100 @@
52 55 $admin_main_settings_assets = include( QUICKWEBP_PLUGIN_PATH . 'public/assets/build/admin-main-settings.asset.php' );
53 56 wp_enqueue_style( 'quickwebpoi_admin_main_settings', QUICKWEBP_PLUGIN_URL . 'public/assets/build/admin-main-settings.css', array(), $admin_main_settings_assets['version'], 'all' );
54 57 wp_enqueue_script( 'quickwebpoi_admin_main_settings', QUICKWEBP_PLUGIN_URL . 'public/assets/build/admin-main-settings.js', $admin_main_settings_assets['dependencies'], $admin_main_settings_assets['version'], true );
55 58 wp_localize_script( 'quickwebpoi_admin_main_settings', 'QUICKWEBP_ADMIN_SETTINGS', array(
56 - 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
57 - 'nonce' => wp_create_nonce( 'image_optimize_nonce' ),
59 + 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
60 + 'nonce' => wp_create_nonce( 'image_optimize_nonce' ),
61 + 'preview_image_data' => $this->get_preview_image_data(),
62 + 'default_image_url' => QUICKWEBP_PLUGIN_URL . 'public/assets/img/preview.jpg',
58 63 ));
59 64 }
60 65 }
66 +
67 + /**
68 + * Persist dismissal of the contextual AVIF notice for the current user.
69 + */
70 + public function dismiss_avif_notice() {
71 + if ( ! isset( $_GET['quickwebp_dismiss_avif_notice'] ) || ! current_user_can( 'manage_options' ) ) {
72 + return;
73 + }
74 +
75 + check_admin_referer( 'quickwebp_dismiss_avif_notice' );
76 + update_user_meta( get_current_user_id(), 'quickwebp_avif_notice_dismissed', 1 );
77 +
78 + wp_safe_redirect( remove_query_arg( array( 'quickwebp_dismiss_avif_notice', '_wpnonce' ) ) );
79 + exit;
80 + }
81 +
82 + /**
83 + * Render the contextual AVIF upgrade notice outside QuickWebP screens.
84 + */
85 + public function render_avif_notice() {
86 + global $quickwebp_surecart_client;
87 +
88 + if ( ! current_user_can( 'manage_options' ) || get_user_meta( get_current_user_id(), 'quickwebp_avif_notice_dismissed', true ) ) {
89 + return;
90 + }
91 +
92 + $screen = get_current_screen();
93 + if ( $screen && false !== strpos( $screen->id, 'quickwebp' ) ) {
94 + return;
95 + }
96 +
97 + if ( $quickwebp_surecart_client && $quickwebp_surecart_client->license()->is_valid() ) {
98 + return;
99 + }
100 +
101 + $stats = get_option( 'quickwebp_optimization_stats', array() );
102 + $image_count = absint( $stats['images_optimized'] ?? 0 );
103 + $bytes_saved = absint( $stats['bytes_saved'] ?? 0 );
104 + $installed_at = absint( get_option( 'quickwebp_installed_at', 0 ) );
105 + $seven_days = 7 * DAY_IN_SECONDS;
106 +
107 + if ( $image_count < 20 && ( ! $installed_at || time() - $installed_at < $seven_days ) ) {
108 + return;
109 + }
110 +
111 + $avif_supported = function_exists( 'wp_image_editor_supports' ) && wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) );
112 + if ( ! $avif_supported ) {
113 + return;
114 + }
115 +
116 + $dismiss_url = wp_nonce_url(
117 + add_query_arg( 'quickwebp_dismiss_avif_notice', '1' ),
118 + 'quickwebp_dismiss_avif_notice'
119 + );
120 + ?>
121 + <div class="notice notice-success quickwebp-avif-notice">
122 + <p>
123 + <strong>
124 + <?php
125 + printf(
126 + /* translators: %s is the number of images optimized by QuickWebP. */
127 + esc_html( _n( 'QuickWebP has already optimized %s image on your site.', 'QuickWebP has already optimized %s images on your site.', $image_count, 'quickwebp' ) ),
128 + esc_html( number_format_i18n( $image_count ) )
129 + );
130 + ?>
131 + </strong>
132 + </p>
133 + <p>
134 + <?php
135 + printf(
136 + /* translators: %s is the disk space saved by QuickWebP. */
137 + esc_html__( 'You have saved %s thanks to WebP.', 'quickwebp' ),
138 + '<strong>' . esc_html( size_format( $bytes_saved, 1 ) ) . '</strong>'
139 + );
140 + ?>
141 + </p>
142 + <p><strong><?php esc_html_e( 'Your server also supports AVIF.', 'quickwebp' ); ?></strong></p>
143 + <p><strong><?php esc_html_e( 'With AVIF, your WebP images could be around 30% smaller on average.', 'quickwebp' ); ?></strong></p>
144 + <p>
145 + <a class="button button-primary" href="<?php echo esc_url( quickwebp_get_pro_url( 'avif-admin-notice' ) ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Discover AVIF', 'quickwebp' ); ?></a>
146 + <a class="button-link" href="<?php echo esc_url( $dismiss_url ); ?>"><?php esc_html_e( 'Dismiss', 'quickwebp' ); ?></a>
147 + </p>
148 + </div>
149 + <?php
150 + }
61 151
62 152 /**
63 153 * add_settings_menu
64 154 *
@@ -66,10 +156,10 @@
66 156 */
67 157 public function add_settings_menu() {
68 158 add_submenu_page(
69 159 'upload.php',
70 - __('Quickwebp Settings', QUICKWEBP_TEXT_DOMAIN),
71 - __('Quickwebp', QUICKWEBP_TEXT_DOMAIN),
160 + __('QuickWebP Settings', 'quickwebp'),
161 + __('QuickWebP', 'quickwebp'),
72 162 'manage_options',
73 163 'quickwebp-settings',
74 164 array( $this, 'render_settings_page' )
75 165 );
@@ -80,10 +170,44 @@
80 170 *
81 171 * @return void
82 172 */
83 173 public function render_settings_page() {
84 - global $is_nginx;
174 + global $is_nginx, $quickwebp_surecart_client;
85 175
176 + $php_version_valid = version_compare( PHP_VERSION, '8.1', '>=' );
177 + $license_valid = false;
178 + if ( $quickwebp_surecart_client ) {
179 + $license_valid = $quickwebp_surecart_client->license()->is_valid();
180 + }
181 +
182 + //phpcs:ignore WordPress.Security.NonceVerification.Missing
183 + if ( isset( $_POST['quickwebp_settings_conversion'] ) ) {
184 + update_option( 'quickwebp_settings_onboarding_completed', '1' );
185 + }
186 +
187 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
188 + $wpmtk_is_active = in_array( 'wpmastertoolkit/wp-mastertoolkit.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
189 + $show_onboarding = '1' !== (string) get_option( 'quickwebp_settings_onboarding_completed', '0' );
190 + $conversion = get_option( 'quickwebp_settings_conversion', quickwebp_settings_default( 'quickwebp_settings_conversion' ) );
191 + $conversion_enabled = '1' === (string) $conversion;
192 + $save_original = get_option( 'quickwebp_settings_conversion_save_original', quickwebp_settings_default( 'quickwebp_settings_conversion_save_original' ) );
193 + $save_original = is_array( $save_original ) ? $save_original : array();
194 + $save_original_enabled = in_array( 'checked', $save_original, true );
195 + $display_mode = get_option( 'quickwebp_settings_conversion_display_webp_mode', quickwebp_settings_default( 'quickwebp_settings_conversion_display_webp_mode' ) );
196 + $conversion_quality = get_option( 'quickwebp_settings_conversion_quality', quickwebp_settings_default( 'quickwebp_settings_conversion_quality' ) );
197 +
198 + $profile_label = __( 'Custom profile', 'quickwebp' );
199 + if ( $conversion_enabled && ! $save_original_enabled ) {
200 + $profile_label = __( 'New site profile', 'quickwebp' );
201 + }
202 + if ( $conversion_enabled && $save_original_enabled ) {
203 + $profile_label = __( 'Existing site profile', 'quickwebp' );
204 + }
205 +
206 + $preview_image_data = $this->get_preview_image_data();
207 + $preview_image_data_webp = $preview_image_data['1_' . $conversion_quality] ?? $preview_image_data['1_medium'];
208 + $preview_image_data_avif = $preview_image_data['2_' . $conversion_quality] ?? $preview_image_data['2_medium'];
209 +
86 210 require_once QUICKWEBP_PLUGIN_PATH . 'admin/templates/page-settings.php';
87 211 }
88 212
89 213 /**
@@ -126,9 +250,19 @@
126 250 $new_actions = array();
127 251
128 252 if ( 'quickwebp/quickwebp.php' === $plugin_file ) {
129 253
130 - $new_actions['settings'] = sprintf( __( '<a href="%s">Settings</a>', QUICKWEBP_TEXT_DOMAIN ), esc_url( admin_url( 'upload.php?page=quickwebp-settings' ) ) );
254 + $new_actions['settings'] = sprintf(
255 + // translators: %s is a placeholder for the link to the settings page.
256 + __( '<a href="%s">Settings</a>', 'quickwebp' ),
257 + esc_url( admin_url( 'upload.php?page=quickwebp-settings' ) )
258 + );
259 +
260 + $new_actions['upgrade_pro'] = sprintf(
261 + '<a href="%1$s" target="_blank" rel="noopener noreferrer" style="color: #008a20; font-weight: 600;">%2$s</a>',
262 + esc_url( quickwebp_get_pro_url( 'plugins-list-upgrade' ) ),
263 + esc_html__( 'Upgrade to Pro', 'quickwebp' )
264 + );
131 265 }
132 266
133 267 return array_merge( $new_actions, $plugin_actions );
134 268 }
@@ -133,66 +267,8 @@
133 267 return array_merge( $new_actions, $plugin_actions );
134 268 }
135 269
136 270 /**
137 - * Show notice
138 - */
139 - public function show_notice_if_library_not_exist() {
140 -
141 - $library_to_use = get_option( 'quickwebp_settings_library', quickwebp_settings_default('quickwebp_settings_library') );
142 -
143 - switch ($library_to_use) {
144 - case 'gd':
145 -
146 - if ( ! extension_loaded('gd') ) {
147 - add_action( 'admin_notices', function() {
148 - ?>
149 - <div class="notice notice-error">
150 - <p><?php _e( 'Oops! QuickWebP needs the GD library to function properly, but it looks like the library is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
151 - <p><?php _e( 'Please contact your hosting provider and ask them to install the GD library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
152 - <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
153 - </div>
154 - <?php
155 - });
156 - }
157 -
158 - break;
159 -
160 - case 'imagick':
161 -
162 - if ( ! extension_loaded('imagick') ) {
163 - add_action( 'admin_notices', function() {
164 - ?>
165 - <div class="notice notice-error">
166 - <p><?php _e( 'Oops! QuickWebP needs the Imagick library to function properly, but it looks like the library is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
167 - <p><?php _e( 'Please contact your hosting provider and ask them to install the Imagick library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
168 - <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
169 - </div>
170 - <?php
171 - });
172 - }
173 -
174 - break;
175 -
176 - default:
177 -
178 - add_action( 'admin_notices', function() {
179 - ?>
180 - <div class="notice notice-error">
181 - <p><?php _e( 'Oops! QuickWebP needs the Imagick or GD library to function properly, but it looks like the no Imagick nor GD is not installed on your server.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
182 - <p><?php _e( 'Please contact your hosting provider and ask them to install the Imagick or GD library for PHP. They should be able to assist you with this process. Once the library is installed, QuickWebP should work as expected.', QUICKWEBP_TEXT_DOMAIN ); ?></p>
183 - <p><?php _e( 'Thank you for using QuickWebP!', QUICKWEBP_TEXT_DOMAIN ); ?></p>
184 - </div>
185 - <?php
186 - });
187 -
188 - break;
189 - }
190 -
191 -
192 - }
193 -
194 - /**
195 271 * Display web mode changed
196 272 */
197 273 public function add_rewrite_rules( $values ) {
198 274 global $is_apache, $is_iis7, $is_nginx;
@@ -214,13 +290,13 @@
214 290 return $values;
215 291 }
216 292
217 293 if ( $is_apache ) {
218 - $rules = new Apache();
294 + $rules = new Quickwebp_Apache();
219 295 } elseif ( $is_iis7 ) {
220 - $rules = new IIS();
296 + $rules = new Quickwebp_IIS();
221 297 } elseif ( $is_nginx ) {
222 - $rules = new Nginx();
298 + $rules = new Quickwebp_Nginx();
223 299 } else {
224 300 return $values;
225 301 }
226 302
@@ -233,9 +309,9 @@
233 309 if ( is_wp_error( $result ) ) {
234 310 add_action( 'admin_notices', function() use ( $result ) {
235 311 ?>
236 312 <div class="notice notice-error">
237 - <p><?php echo $result->get_error_message(); ?></p>
313 + <p><?php echo esc_html( $result->get_error_message() ); ?></p>
238 314 </div>
239 315 <?php
240 316 });
241 317 }
@@ -242,5 +318,141 @@
242 318
243 319 return $values;
244 320 }
245 321
246 -}
322 + /**
323 + * Ensure display mode remains consistent with conversion mode.
324 + */
325 + public function sanitize_display_mode_for_consistency( $value, $option = '', $original_value = '' ) {
326 +
327 + $allowed_modes = array( 'disabled', 'picture', 'rewrite' );
328 + $value = sanitize_text_field( (string) $value );
329 +
330 + if ( ! in_array( $value, $allowed_modes, true ) ) {
331 + $value = 'disabled';
332 + }
333 +
334 + $conversion_enabled = $this->is_conversion_enabled_from_request_or_option();
335 + if ( ! $conversion_enabled ) {
336 + return 'disabled';
337 + }
338 +
339 + $save_original = $this->is_save_original_enabled_from_request_or_option();
340 + if ( ! $save_original ) {
341 + return 'disabled';
342 + }
343 +
344 + if ( 'disabled' === $value ) {
345 + return 'picture';
346 + }
347 +
348 + return $value;
349 + }
350 +
351 + /**
352 + * Get whether original images should be preserved.
353 + */
354 + private function is_save_original_enabled_from_request_or_option() {
355 +
356 + //phpcs:ignore WordPress.Security.NonceVerification.Missing
357 + if ( isset( $_POST['quickwebp_settings_conversion_save_original'] ) ) {
358 + //phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
359 + $raw_value = wp_unslash( $_POST['quickwebp_settings_conversion_save_original'] );
360 +
361 + if ( is_array( $raw_value ) ) {
362 + $raw_value = array_map( 'sanitize_text_field', $raw_value );
363 + return in_array( 'checked', $raw_value, true );
364 + }
365 +
366 + return false;
367 + }
368 +
369 + $saved_value = get_option(
370 + 'quickwebp_settings_conversion_save_original',
371 + quickwebp_settings_default( 'quickwebp_settings_conversion_save_original' )
372 + );
373 +
374 + $saved_value = is_array( $saved_value ) ? $saved_value : array();
375 + return in_array( 'checked', $saved_value, true );
376 + }
377 +
378 + /**
379 + * Get whether image conversion is enabled.
380 + */
381 + private function is_conversion_enabled_from_request_or_option() {
382 +
383 + //phpcs:ignore WordPress.Security.NonceVerification.Missing
384 + if ( isset( $_POST['quickwebp_settings_conversion'] ) ) {
385 + //phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
386 + $raw_value = wp_unslash( $_POST['quickwebp_settings_conversion'] );
387 + $raw_value = sanitize_text_field( (string) $raw_value );
388 +
389 + return '1' === $raw_value;
390 + }
391 +
392 + $saved_value = get_option(
393 + 'quickwebp_settings_conversion',
394 + quickwebp_settings_default( 'quickwebp_settings_conversion' )
395 + );
396 +
397 + return '1' === (string) $saved_value;
398 + }
399 +
400 + /**
401 + * Data for the preview image used in the settings page.
402 + */
403 + private function get_preview_image_data() {
404 + return array(
405 + 'name' => 'preview.jpg',
406 + 'size' => '423.17 KB',
407 + 'dimensions' => '1264 x 848',
408 + '1_low' => array(
409 + 'size' => '175.32 KB',
410 + 'save' => '247.85 KB',
411 + 'save_percent' => '59%',
412 + 'percent' => '41%',
413 + ),
414 + '1_medium' => array(
415 + 'size' => '196.08 KB',
416 + 'save' => '227.09 KB',
417 + 'save_percent' => '54%',
418 + 'percent' => '46%',
419 + ),
420 + '1_high' => array(
421 + 'size' => '229.29 KB',
422 + 'save' => '193.88 KB',
423 + 'save_percent' => '46%',
424 + 'percent' => '54%',
425 + ),
426 + '1_extra_high' => array(
427 + 'size' => '387.46 KB',
428 + 'save' => '35.71 KB',
429 + 'save_percent' => '8%',
430 + 'percent' => '92%',
431 + ),
432 + '2_low' => array(
433 + 'size' => '73.44 KB',
434 + 'save' => '349.73 KB',
435 + 'save_percent' => '83%',
436 + 'percent' => '17%',
437 + ),
438 + '2_medium' => array(
439 + 'size' => '120.06 KB',
440 + 'save' => '303.11 KB',
441 + 'save_percent' => '72%',
442 + 'percent' => '28%',
443 + ),
444 + '2_high' => array(
445 + 'size' => '183.21 KB',
446 + 'save' => '239.96 KB',
447 + 'save_percent' => '57%',
448 + 'percent' => '43%',
449 + ),
450 + '2_extra_high' => array(
451 + 'size' => '290.54 KB',
452 + 'save' => '132.63 KB',
453 + 'save_percent' => '31%',
454 + 'percent' => '69%',
455 + ),
456 + );
457 + }
458 +}