Changeset 3789337
- Timestamp:
- 11/07/2026 10:23:07 AM (less than one hour ago)
- Location:
- disable-thumbnails-and-threshold
- Files:
-
- 6 edited
- 9 copied
-
tags/0.8.0 (copied) (copied from disable-thumbnails-and-threshold/trunk )
-
tags/0.8.0/disable-thumbnails-and-thresold.php (copied) (copied from disable-thumbnails-and-threshold/trunk/disable-thumbnails-and-thresold.php ) (20 diffs)
-
tags/0.8.0/includes/admin.css (copied) (copied from disable-thumbnails-and-threshold/trunk/includes/admin.css ) (1 diff)
-
tags/0.8.0/includes/index.php (copied) (copied from disable-thumbnails-and-threshold/trunk/includes/index.php )
-
tags/0.8.0/includes/option-quality.php (copied) (copied from disable-thumbnails-and-threshold/trunk/includes/option-quality.php ) (11 diffs)
-
tags/0.8.0/includes/option-threshold-exif.php (copied) (copied from disable-thumbnails-and-threshold/trunk/includes/option-threshold-exif.php ) (15 diffs)
-
tags/0.8.0/includes/option-thumbnails.php (copied) (copied from disable-thumbnails-and-threshold/trunk/includes/option-thumbnails.php ) (14 diffs)
-
tags/0.8.0/index.php (copied) (copied from disable-thumbnails-and-threshold/trunk/index.php )
-
tags/0.8.0/readme.txt (copied) (copied from disable-thumbnails-and-threshold/trunk/readme.txt ) (3 diffs)
-
trunk/disable-thumbnails-and-thresold.php (modified) (20 diffs)
-
trunk/includes/admin.css (modified) (1 diff)
-
trunk/includes/option-quality.php (modified) (11 diffs)
-
trunk/includes/option-threshold-exif.php (modified) (15 diffs)
-
trunk/includes/option-thumbnails.php (modified) (14 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
disable-thumbnails-and-threshold/tags/0.8.0/disable-thumbnails-and-thresold.php
r3504636 r3789337 1 1 <?php 2 /* 3 Plugin Name: Disable Thumbnails, Threshold and Image Options 4 Version: 0.7.0 5 Description: Disable Thumbnails, Threshold and Image Options 6 Author: KGM Servizi 7 Author URI: https://kgmservizi.com 8 License: GPLv2 or later 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 Text Domain: disable-thumbnails-and-threshold 11 Requires at least: 5.4 12 Requires PHP: 7.4 13 */ 2 /** 3 * Plugin Name: Disable Thumbnails, Threshold and Image Options 4 * Version: 0.8.0 5 * Description: Disable Thumbnails, Threshold and Image Options 6 * Author: KGM Servizi 7 * Author URI: https://kgmservizi.com 8 * License: GPLv2 or later 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 * Text Domain: disable-thumbnails-and-threshold 11 * Requires at least: 5.6 12 * Requires PHP: 8.0 13 * 14 * @package Disable_Thumbnails_Threshold 15 */ 14 16 15 17 if ( ! defined( 'ABSPATH' ) ) { 16 exit; // Exit if accessed directly 17 } 18 19 // Define plugin constants for better maintainability 18 exit; // Exit if accessed directly. 19 } 20 21 // Define plugin constants for better maintainability. 20 22 define( 'DTAT_QUALITY_OPTION', 'dtat_imgquality_option_name' ); 21 23 define( 'DTAT_THRESHOLD_OPTION', 'dtat_disablethreshold_option_name' ); 22 24 define( 'DTAT_THUMBNAILS_OPTION', 'dtat_disablethumbnails_option_name' ); 23 25 define( 'DTAT_MIGRATION_OPTION', 'dtat_migration_done' ); 24 define( 'DTAT_VERSION', '0.7.0' ); 25 26 /** 27 * PHPCS Suppressions 28 * 29 * This file contains phpcs:ignore comments for the following cases: 30 * - Line 151, 131 (option-quality.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 31 * Reason: Using WordPress core hook (jpeg_quality) which doesn't require plugin prefix 32 * - Line 174, 172 (option-threshold-exif.php), 206 (option-threshold-exif.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 33 * Reason: Using WordPress core hook (big_image_size_threshold) which doesn't require plugin prefix 34 * - Line 241 (option-threshold-exif.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 35 * Reason: Using WordPress core hook (wp_image_maybe_exif_rotate) which doesn't require plugin prefix 36 */ 37 38 // Check WordPress version compatibility - requires WordPress 5.4+ for PHP 7.4+ support 39 // Use admin_init hook to ensure WordPress is fully loaded 26 define( 'DTAT_VERSION', '0.8.0' ); 27 define( 'DTAT_MIN_WP_VERSION', '5.6' ); 28 define( 'DTAT_MIN_PHP_VERSION', '8.0' ); 29 30 // Check WordPress version compatibility - WordPress 5.6 is the first release that supports PHP 8.0. 31 // Use admin_init hook to ensure WordPress is fully loaded. 40 32 add_action( 'admin_init', 'dtat_check_wordpress_version' ); 41 33 … … 50 42 51 43 /** 52 * 44 * 53 45 * Retrieve options for quality and threshold 54 46 * Cache options globally to avoid multiple database calls 55 *56 47 */ 57 48 $GLOBALS['dtat_imgquality_options'] = get_option( DTAT_QUALITY_OPTION ); … … 77 68 $processed = true; 78 69 70 // admin_init also fires for logged-out admin-ajax.php/admin-post.php requests. 71 if ( ! current_user_can( 'manage_options' ) ) { 72 return; 73 } 74 79 75 // Skip migration if already completed for this plugin version. 80 76 if ( get_option( DTAT_MIGRATION_OPTION ) === DTAT_VERSION ) { … … 82 78 } 83 79 84 $option_map = [85 DTAT_QUALITY_OPTION => 'kgmimgquality_option_name',86 DTAT_THRESHOLD_OPTION => 'kgmdisablethreshold_option_name',87 DTAT_THUMBNAILS_OPTION => 'kgmdisablethumbnails_option_name',88 ];80 $option_map = array( 81 DTAT_QUALITY_OPTION => 'kgmimgquality_option_name', 82 DTAT_THRESHOLD_OPTION => 'kgmdisablethreshold_option_name', 83 DTAT_THUMBNAILS_OPTION => 'kgmdisablethumbnails_option_name', 84 ); 89 85 90 86 foreach ( $option_map as $new_option => $legacy_option ) { … … 105 101 } 106 102 103 /* 104 * The globals were cached at load time, before the migration. Without a refresh, 105 * dtat_initialize_options() (same hook, later) sees them empty and overwrites the 106 * migrated values with defaults, after the legacy rows are already deleted. 107 */ 108 $GLOBALS['dtat_imgquality_options'] = get_option( DTAT_QUALITY_OPTION ); 109 $GLOBALS['dtat_disablethreshold_options'] = get_option( DTAT_THRESHOLD_OPTION ); 110 $GLOBALS['dtat_disablethumbnails_options'] = get_option( DTAT_THUMBNAILS_OPTION ); 111 107 112 update_option( DTAT_MIGRATION_OPTION, DTAT_VERSION ); 108 113 } 109 114 110 115 111 // Initialize with current WordPress values if options don't exist 112 // This will be handled in the admin_init hook to ensure WordPress is fully loaded 116 // Initialize with current WordPress values if options don't exist. 117 // This will be handled in the admin_init hook to ensure WordPress is fully loaded. 113 118 add_action( 'admin_init', 'dtat_initialize_options' ); 114 119 115 // Hook to apply filters after themes are loaded to ensure priority 120 // Hook to apply filters after themes are loaded to ensure priority. 116 121 add_action( 'after_setup_theme', 'dtat_apply_filters', 20 ); 117 122 … … 126 131 */ 127 132 function dtat_check_wordpress_version(): void { 128 // Only run in admin 133 // Only run in admin. 129 134 if ( ! is_admin() ) { 130 135 return; 131 136 } 132 133 // Check if WordPress version is compatible 134 if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) {137 138 // Check if WordPress version is compatible. 139 if ( version_compare( get_bloginfo( 'version' ), DTAT_MIN_WP_VERSION, '<' ) ) { 135 140 add_action( 'admin_notices', 'dtat_wordpress_version_notice' ); 136 141 } … … 146 151 function dtat_wordpress_version_notice(): void { 147 152 printf( 148 '<div class="notice notice-error"><p><strong>%s</strong> %s</p></div>', 149 esc_html__( 'Disable Thumbnails, Threshold and Image Options', 'disable-thumbnails-and-threshold' ), 150 esc_html__( 'requires WordPress 5.4 or higher (PHP 7.4+). Please update WordPress.', 'disable-thumbnails-and-threshold' ) 153 '<div class="notice notice-error"><p>%s</p></div>', 154 esc_html( 155 sprintf( 156 /* translators: 1: Plugin name, 2: Minimum WordPress version, 3: Minimum PHP version. */ 157 __( '%1$s requires WordPress %2$s or higher and PHP %3$s or higher. Please update.', 'disable-thumbnails-and-threshold' ), 158 'Disable Thumbnails, Threshold and Image Options', 159 DTAT_MIN_WP_VERSION, 160 DTAT_MIN_PHP_VERSION 161 ) 162 ) 151 163 ); 152 164 } … … 162 174 */ 163 175 function dtat_initialize_options(): void { 164 // Only run in admin and if user has proper capabilities 176 // Only run in admin and if user has proper capabilities. 165 177 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { 166 178 return; 167 179 } 168 169 // Initialize JPEG quality option if it doesn't exist or is invalid 170 if ( ! $GLOBALS['dtat_imgquality_options'] || 171 ! is_array( $GLOBALS['dtat_imgquality_options'] ) || 172 ! isset( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 173 ! is_numeric( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 174 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) < 1 || 175 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) > 100 ) { 176 177 // Get current WordPress JPEG quality (respects existing filters/plugins) 178 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 179 $current_quality = apply_filters( 'jpeg_quality', 82 ); 180 181 // Validate the quality value from filters 180 181 // Initialize JPEG quality option if it doesn't exist or is invalid. 182 if ( ! $GLOBALS['dtat_imgquality_options'] || 183 ! is_array( $GLOBALS['dtat_imgquality_options'] ) || 184 ! isset( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 185 ! is_numeric( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 186 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) < 1 || 187 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) > 100 ) { 188 /* 189 * Get current WordPress JPEG quality (respects existing filters/plugins). 190 * Pass every argument core passes: on PHP 8 a third-party callback with a 191 * required $context would otherwise throw ArgumentCountError here. 192 */ 193 try { 194 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 195 $current_quality = apply_filters( 'jpeg_quality', 82, 'image_resize' ); 196 } catch ( Throwable $e ) { 197 $current_quality = 82; 198 } 199 200 // Validate the quality value from filters. 182 201 if ( ! is_numeric( $current_quality ) || $current_quality < 1 || $current_quality > 100 ) { 183 $current_quality = 82; // Fallback to WordPress default 184 } 185 186 // Preserve existing options and only update jpeg_quality 202 $current_quality = 82; // Fallback to WordPress default. 203 } 204 205 // Preserve existing options and only update jpeg_quality. 187 206 if ( ! is_array( $GLOBALS['dtat_imgquality_options'] ) ) { 188 $GLOBALS['dtat_imgquality_options'] = [];207 $GLOBALS['dtat_imgquality_options'] = array(); 189 208 } 190 209 $GLOBALS['dtat_imgquality_options']['jpeg_quality'] = intval( $current_quality ); 191 210 update_option( DTAT_QUALITY_OPTION, $GLOBALS['dtat_imgquality_options'] ); 192 211 } 193 194 // Initialize threshold option if it doesn't exist or is invalid 195 if ( ! $GLOBALS['dtat_disablethreshold_options'] || 196 ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) || 197 ! isset( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 198 ! is_numeric( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 199 intval( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) <= 0 ) { 200 201 // Get current WordPress big image threshold (respects existing filters/plugins) 202 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 203 $current_threshold = apply_filters( 'big_image_size_threshold', 2560 ); 204 205 // Validate the threshold value from filters 212 213 // Initialize threshold option if it doesn't exist or is invalid. 214 if ( ! $GLOBALS['dtat_disablethreshold_options'] || 215 ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) || 216 ! isset( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 217 ! is_numeric( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 218 intval( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) <= 0 ) { 219 /* 220 * Get current WordPress big image threshold (respects existing filters/plugins). 221 * Core passes $imagesize, $file and $attachment_id; there is no real image here, 222 * so neutral values are passed and any callback failure falls back to the default. 223 */ 224 try { 225 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 226 $current_threshold = apply_filters( 'big_image_size_threshold', 2560, array( 0, 0 ), '', 0 ); 227 } catch ( Throwable $e ) { 228 $current_threshold = 2560; 229 } 230 231 // Validate the threshold value from filters. 206 232 if ( ! is_numeric( $current_threshold ) || $current_threshold <= 0 ) { 207 $current_threshold = 2560; // Fallback to WordPress default 208 } 209 210 // Preserve existing options and only update new_threshold 233 $current_threshold = 2560; // Fallback to WordPress default. 234 } 235 236 // Preserve existing options and only update new_threshold. 211 237 if ( ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) ) { 212 $GLOBALS['dtat_disablethreshold_options'] = [];238 $GLOBALS['dtat_disablethreshold_options'] = array(); 213 239 } 214 240 $GLOBALS['dtat_disablethreshold_options']['new_threshold'] = intval( $current_threshold ); … … 225 251 */ 226 252 function dtat_jpeg_quality_filter(): int { 227 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);228 253 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 254 229 255 if ( ! is_array( $dtat_imgquality_options ) || ! isset( $dtat_imgquality_options['jpeg_quality'] ) ) { 230 return 82; // WordPress default 231 } 232 256 return 82; // WordPress default. 257 } 258 233 259 $quality = intval( $dtat_imgquality_options['jpeg_quality'] ); 234 235 // Validate quality range (0-100)236 if ( $quality < 0|| $quality > 100 ) {237 return 82; // WordPress default 238 } 239 260 261 // Same 1-100 range accepted by the settings page. 262 if ( $quality < 1 || $quality > 100 ) { 263 return 82; // WordPress default. 264 } 265 240 266 return $quality; 241 267 } … … 249 275 */ 250 276 function dtat_big_image_threshold_filter(): int { 251 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, []);252 277 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, array() ); 278 253 279 if ( ! is_array( $dtat_disablethreshold_options ) || ! isset( $dtat_disablethreshold_options['new_threshold'] ) ) { 254 return 2560; // WordPress default 255 } 256 280 return 2560; // WordPress default. 281 } 282 257 283 $threshold = intval( $dtat_disablethreshold_options['new_threshold'] ); 258 259 // Validate threshold is positive 284 285 // Validate threshold is positive. 260 286 if ( $threshold <= 0 ) { 261 return 2560; // WordPress default 262 } 263 287 return 2560; // WordPress default. 288 } 289 264 290 return $threshold; 265 291 } … … 270 296 * @since 0.1 271 297 * @package Disable_Thumbnails_Threshold 272 * @param array $sizes Registered intermediate image sizes. 273 * @return array Filtered image sizes with disabled ones removed. 274 */ 275 function dtat_thumbnail_sizes_filter( array $sizes ): array { 276 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, [] ); 277 298 * @param mixed $sizes Registered intermediate image sizes (an array, unless another filter broke it). 299 * @return mixed Filtered image sizes with disabled ones removed. 300 */ 301 function dtat_thumbnail_sizes_filter( $sizes ) { 302 // Untyped on purpose: a TypeError here would break every media upload. 303 if ( ! is_array( $sizes ) ) { 304 return $sizes; 305 } 306 307 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, array() ); 308 278 309 if ( ! is_array( $dtat_disablethumbnails_options ) || empty( $dtat_disablethumbnails_options ) ) { 279 310 return $sizes; 280 311 } 281 282 // Validate that all values in the array are strings (security check) 312 313 // Validate that all values in the array are strings (security check). 283 314 $valid_options = array_filter( $dtat_disablethumbnails_options, 'is_string' ); 284 315 285 316 return array_diff( $sizes, $valid_options ); 286 317 } … … 294 325 */ 295 326 function dtat_apply_filters(): void { 296 // Prevent multiple applications 327 // Prevent multiple applications. 297 328 static $applied = false; 298 329 if ( $applied ) { … … 300 331 } 301 332 $applied = true; 302 303 // Remove any existing filters to prevent accumulation 333 334 // Remove any existing filters to prevent accumulation. 304 335 remove_filter( 'jpeg_quality', 'dtat_jpeg_quality_filter' ); 305 336 remove_filter( 'big_image_size_threshold', 'dtat_big_image_threshold_filter' ); 306 337 remove_filter( 'intermediate_image_sizes', 'dtat_thumbnail_sizes_filter' ); 307 308 // Safely get options with fallback 309 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);310 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, []);311 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, []);312 313 // Apply JPEG quality filter 338 339 // Safely get options with fallback. 340 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 341 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, array() ); 342 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, array() ); 343 344 // Apply JPEG quality filter. 314 345 $jpeg_quality = null; 315 346 if ( is_array( $dtat_imgquality_options ) ) { 316 347 $jpeg_quality = $dtat_imgquality_options['jpeg_quality'] ?? null; 317 348 } 318 349 319 350 $quality = $jpeg_quality ? intval( $jpeg_quality ) : 0; 320 351 if ( $jpeg_quality && is_numeric( $jpeg_quality ) && $quality > 0 && $quality <= 100 ) { … … 322 353 } 323 354 324 // Apply threshold filters 355 // Apply threshold filters. 325 356 if ( is_array( $dtat_disablethreshold_options ) ) { 326 // Set new threshold 357 // Set new threshold. 327 358 if ( ! empty( $dtat_disablethreshold_options['new_threshold'] ) 328 359 && is_numeric( $dtat_disablethreshold_options['new_threshold'] ) ) { … … 333 364 } 334 365 335 // Disable threshold 366 // Disable threshold. 336 367 if ( 'disable_threshold' === ( $dtat_disablethreshold_options['disable_threshold'] ?? null ) ) { 337 368 add_filter( 'big_image_size_threshold', '__return_false', 100 ); 338 369 } 339 370 340 // Disable EXIF rotation 371 // Disable EXIF rotation. 341 372 if ( 'disable_image_rotation_exif' === ( $dtat_disablethreshold_options['disable_image_rotation_exif'] ?? null ) ) { 342 373 add_filter( 'wp_image_maybe_exif_rotate', '__return_zero', 100, 2 ); … … 344 375 } 345 376 346 // Apply thumbnail size filters 377 // Apply thumbnail size filters. 347 378 if ( ! empty( $dtat_disablethumbnails_options ) ) { 348 379 add_filter( 'intermediate_image_sizes', 'dtat_thumbnail_sizes_filter', 100 ); … … 350 381 } 351 382 352 // All filters are now applied in dtat_apply_filters() function after themes are loaded 383 // All filters are now applied in dtat_apply_filters() function after themes are loaded. 353 384 354 385 /** … … 361 392 */ 362 393 function dtat_action_links( array $actions ): array { 363 // Check if user has proper capabilities before showing action links 394 // Check if user has proper capabilities before showing action links. 364 395 if ( ! current_user_can( 'manage_options' ) ) { 365 396 return $actions; 366 397 } 367 368 $mylinks = [398 399 $mylinks = array( 369 400 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmdisablethumbnails' ) ) . '">' . esc_html__( 'Image sizes', 'disable-thumbnails-and-threshold' ) . '</a>', 370 401 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmimgquality' ) ) . '">' . esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ) . '</a>', 371 402 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmdisablethreshold' ) ) . '">' . esc_html__( 'Threshold & EXIF', 'disable-thumbnails-and-threshold' ) . '</a>', 372 ];403 ); 373 404 return array_merge( $mylinks, $actions ); 374 405 } … … 383 414 */ 384 415 function dtat_admin_styles( string $hook ): void { 385 /**386 * Check if in plugin options page and user has proper capabilities387 */388 416 if ( ! current_user_can( 'manage_options' ) ) { 389 417 return; 390 418 } 391 392 $screen = get_current_screen(); 393 if ( ! $screen ) { 394 return; 395 } 396 397 if ( 'tools_page_kgmdisablethumbnails' === $screen->base || 'tools_page_kgmdisablethreshold' === $screen->base ) { 398 wp_enqueue_style( 'dtat-admin-css', plugins_url( 'includes/admin.css', __FILE__ ), [], DTAT_VERSION ); 399 } 400 } 419 420 $plugin_pages = array( 'tools_page_kgmdisablethumbnails', 'tools_page_kgmdisablethreshold', 'tools_page_kgmimgquality' ); 421 if ( in_array( $hook, $plugin_pages, true ) ) { 422 wp_enqueue_style( 'dtat-admin-css', plugins_url( 'includes/admin.css', __FILE__ ), array(), DTAT_VERSION ); 423 } 424 } 425 426 register_uninstall_hook( __FILE__, 'dtat_plugin_uninstall' ); 401 427 402 428 /** 403 429 * Clean up plugin options on uninstall. 404 430 * 405 * @since 0.1 406 * @package Disable_Thumbnails_Threshold 407 * @return void 408 */ 409 register_uninstall_hook( __FILE__, 'dtat_plugin_uninstall' ); 431 * Also removes the pre-0.6.5 `kgm*` options, which survive when the migration never ran. 432 * 433 * @since 0.1 434 * @package Disable_Thumbnails_Threshold 435 * @return void 436 */ 410 437 function dtat_plugin_uninstall(): void { 411 438 delete_option( DTAT_THUMBNAILS_OPTION ); … … 413 440 delete_option( DTAT_QUALITY_OPTION ); 414 441 delete_option( DTAT_MIGRATION_OPTION ); 415 } 442 delete_option( 'kgmimgquality_option_name' ); 443 delete_option( 'kgmdisablethreshold_option_name' ); 444 delete_option( 'kgmdisablethumbnails_option_name' ); 445 } -
disable-thumbnails-and-threshold/tags/0.8.0/includes/admin.css
r3504636 r3789337 1 1 .switch { position: relative; display: inline-block; width: 33px; height: 17px; margin-right: 0.4em; } 2 2 .switch input { position: absolute; opacity: 0; width: 1px; height: 1px; clip: rect(0 0 0 0); overflow: hidden; } 3 .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 18px; display:inline; } 3 /* Inset border #757575: 4.05:1 on the form-table background #f0f0f1 (SC 1.4.11 needs 3:1). */ 4 .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; box-shadow: inset 0 0 0 1px #757575; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 18px; display:inline; } 4 5 .slider::before { position: absolute; content: ""; height: 10px; width: 10px; left: 4px; bottom: 4px; background-color: #fff; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 50%; } 5 6 input:checked + .screen-reader-text + .slider, 6 7 input:checked + .slider { background-color: #b12222; } 8 /* Transparent outline: box-shadow is dropped in forced-colors mode, the outline is not. */ 7 9 input:focus + .screen-reader-text + .slider, 8 input:focus + .slider { box-shadow:0 0 0 3px #005fcc; }10 input:focus + .slider { outline: 2px solid transparent; outline-offset: 2px; box-shadow: inset 0 0 0 1px #757575, 0 0 0 3px #005fcc; } 9 11 input:checked + .screen-reader-text + .slider::before, 10 12 input:checked + .slider::before { -webkit-transform: translateX(16px); -ms-transform: translateX(16px); transform: translateX(16px); } 11 .dtat-notice-warning { color: #d63638; } 12 .dtat-notice-caution { color: #dba617; } 13 @media (forced-colors: active) { 14 .slider { border: 1px solid ButtonText; } 15 .slider::before { background-color: ButtonText; } 16 input:checked + .screen-reader-text + .slider, 17 input:checked + .slider { background-color: Highlight; } 18 } 19 /* Ratios on #f0f0f1: warning 5.53:1, caution 4.86:1, info 5.04:1 (SC 1.4.3 needs 4.5:1). */ 20 .dtat-notice-warning { color: #b32d2e; } 21 .dtat-notice-caution { color: #8a6100; } 13 22 .dtat-notice-info { color: #666; } -
disable-thumbnails-and-threshold/tags/0.8.0/includes/option-quality.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Image Quality settings page. 19 * 20 * @since 0.2 21 */ 17 22 class DTAT_Img_Quality { 18 private array|false $dtat_imgquality_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_imgquality_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 40 50 'manage_options', 41 51 'kgmimgquality', 42 [ $this, 'create_admin_page' ]52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <?php settings_errors(); ?> 67 77 … … 74 84 </form> 75 85 </div> 76 <?php } 86 <?php 87 } 77 88 78 89 /** … … 86 97 'kgmimgquality_option_group', 87 98 DTAT_QUALITY_OPTION, 88 [ $this, 'sanitize' ]99 array( $this, 'sanitize' ) 89 100 ); 90 101 91 102 add_settings_section( 92 103 'kgmimgquality_setting_section', 93 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 94 [ $this, 'section_info' ],95 'kgmimgquality-admin' 104 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 105 array( $this, 'section_info' ), 106 'kgmimgquality-admin' 96 107 ); 97 108 … … 99 110 'jpeg_quality', 100 111 esc_html__( 'JPEG Quality', 'disable-thumbnails-and-threshold' ) . ' <br> <small>' . esc_html__( 'Default WordPress: 82%', 'disable-thumbnails-and-threshold' ) . '</small>', 101 [ $this, 'jpeg_quality_callback' ],112 array( $this, 'jpeg_quality_callback' ), 102 113 'kgmimgquality-admin', 103 'kgmimgquality_setting_section' 114 'kgmimgquality_setting_section', 115 array( 'label_for' => 'jpeg_quality' ) 104 116 ); 105 117 } … … 108 120 * Sanitize and validate form input before saving. 109 121 * 110 * @since 0.2 111 * @param array $input Raw form input values. 122 * Runs on every update_option() of this option, not only on form submit, so it 123 * must not depend on the current user: options.php already enforces the nonce 124 * and the manage_options capability before saving. 125 * 126 * @since 0.2 127 * @param mixed $input Raw value; null when the field is missing from the request. 112 128 * @return array Sanitized values. 113 129 */ 114 public function sanitize( array $input ): array { 115 // Check user capabilities for security 116 if ( ! current_user_can( 'manage_options' ) ) { 117 return $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, [] ); 118 } 119 120 // Nonce is already verified by WordPress options.php handler via settings_fields(). 121 $sanitary_values = []; 130 public function sanitize( $input ): array { 131 if ( ! is_array( $input ) ) { 132 $input = array(); 133 } 134 135 $sanitary_values = array(); 122 136 123 137 if ( isset( $input['jpeg_quality'] ) ) { 124 $quality = sanitize_text_field( $input['jpeg_quality'] );138 $quality = sanitize_text_field( $input['jpeg_quality'] ); 125 139 $quality_int = intval( $quality ); 126 140 if ( is_numeric( $quality ) && $quality_int >= 1 && $quality_int <= 100 ) { … … 128 142 } else { 129 143 add_settings_error( 'kgmimgquality_option_notice', 'invalid_quality', esc_html__( 'JPEG quality must be a number between 1 and 100.', 'disable-thumbnails-and-threshold' ) ); 130 $existing = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);144 $existing = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 131 145 if ( is_array( $existing ) && isset( $existing['jpeg_quality'] ) ) { 132 return [ 'jpeg_quality' => absint( $existing['jpeg_quality'] ) ];146 return array( 'jpeg_quality' => absint( $existing['jpeg_quality'] ) ); 133 147 } 134 return [];148 return array(); 135 149 } 136 150 } … … 162 176 esc_html__( '%', 'disable-thumbnails-and-threshold' ) 163 177 ); 164 178 165 179 // Compare plugin value against WordPress default. 166 180 // We avoid calling apply_filters() here because the jpeg_quality filter expects … … 173 187 174 188 if ( $plugin_quality && $plugin_quality !== $wp_default_quality ) { 175 printf( '<br><small class="description dtat-notice-warning">%s %s</small>', 189 printf( 190 '<br><small class="description dtat-notice-warning">%s %s</small>', 176 191 esc_html( '⚠️' ), 177 / / translators: %1$d: Plugin quality percentage, %2$d: WordPress default quality percentage192 /* translators: %1$d: Plugin quality percentage, %2$d: WordPress default quality percentage */ 178 193 esc_html( sprintf( __( 'Plugin quality (%1$d%%) differs from WordPress default (%2$d%%)', 'disable-thumbnails-and-threshold' ), $plugin_quality, $wp_default_quality ) ) 179 194 ); 180 195 } else { 181 printf( '<br><small class="description dtat-notice-info">%s</small>', 182 // translators: %d: WordPress default JPEG quality percentage 196 printf( 197 '<br><small class="description dtat-notice-info">%s</small>', 198 /* translators: %d: WordPress default JPEG quality percentage */ 183 199 esc_html( sprintf( __( 'WordPress default JPEG quality: %d%%', 'disable-thumbnails-and-threshold' ), $wp_default_quality ) ) 184 200 ); 185 201 } 186 202 } 187 188 203 } 189 204 if ( is_admin() ) { 190 $ DTAT_Img_Quality = new DTAT_Img_Quality();205 $dtat_img_quality = new DTAT_Img_Quality(); 191 206 } -
disable-thumbnails-and-threshold/tags/0.8.0/includes/option-threshold-exif.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Threshold & EXIF settings page. 19 * 20 * @since 0.1 21 */ 17 22 class DTAT_Disable_Threshold { 18 private array|false $dtat_disablethreshold_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_disablethreshold_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 40 50 'manage_options', 41 51 'kgmdisablethreshold', 42 [ $this, 'create_admin_page' ]52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Disable Threshold&EXIF', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Disable Threshold&EXIF', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <?php settings_errors(); ?> 67 77 … … 74 84 </form> 75 85 </div> 76 <?php } 86 <?php 87 } 77 88 78 89 /** … … 86 97 'kgmdisablethreshold_option_group', 87 98 DTAT_THRESHOLD_OPTION, 88 [ $this, 'sanitize' ]99 array( $this, 'sanitize' ) 89 100 ); 90 101 91 102 add_settings_section( 92 103 'kgmdisablethreshold_setting_section', 93 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 94 [ $this, 'section_info' ],95 'kgmdisablethreshold-admin' 104 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 105 array( $this, 'section_info' ), 106 'kgmdisablethreshold-admin' 96 107 ); 97 108 … … 99 110 'new_threshold', 100 111 esc_html__( 'New Size Threshold', 'disable-thumbnails-and-threshold' ) . ' <br> <small>' . esc_html__( 'Default WordPress: 2560px', 'disable-thumbnails-and-threshold' ) . '</small>', 101 [ $this, 'new_threshold_callback' ],112 array( $this, 'new_threshold_callback' ), 102 113 'kgmdisablethreshold-admin', 103 'kgmdisablethreshold_setting_section' 114 'kgmdisablethreshold_setting_section', 115 array( 'label_for' => 'new_threshold' ) 104 116 ); 105 117 add_settings_field( 106 118 'disable_threshold', 107 119 esc_html__( 'Disable Threshold', 'disable-thumbnails-and-threshold' ), 108 [ $this, 'disable_threshold_callback' ],120 array( $this, 'disable_threshold_callback' ), 109 121 'kgmdisablethreshold-admin', 110 122 'kgmdisablethreshold_setting_section' … … 113 125 'disable_image_rotation_exif', 114 126 esc_html__( 'Disable Image Rotation by EXIF', 'disable-thumbnails-and-threshold' ), 115 [ $this, 'disable_image_rotation_exif_callback' ],127 array( $this, 'disable_image_rotation_exif_callback' ), 116 128 'kgmdisablethreshold-admin', 117 129 'kgmdisablethreshold_setting_section' … … 122 134 * Sanitize and validate form input before saving. 123 135 * 124 * @since 0.1 125 * @param array $input Raw form input values. 136 * Runs on every update_option() of this option, not only on form submit, so it 137 * must not depend on the current user: options.php already enforces the nonce 138 * and the manage_options capability before saving. 139 * 140 * @since 0.1 141 * @param mixed $input Raw value; null when no field is present in the request. 126 142 * @return array Sanitized values. 127 143 */ 128 public function sanitize( array $input ): array { 129 // Check user capabilities for security 130 if ( ! current_user_can( 'manage_options' ) ) { 131 return $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, [] ); 132 } 133 134 // Nonce is already verified by WordPress options.php handler via settings_fields(). 135 $sanitary_values = []; 144 public function sanitize( $input ): array { 145 if ( ! is_array( $input ) ) { 146 $input = array(); 147 } 148 149 $sanitary_values = array(); 136 150 137 151 if ( isset( $input['new_threshold'] ) ) { … … 183 197 esc_html__( 'px', 'disable-thumbnails-and-threshold' ) 184 198 ); 185 186 // Check if plugin disables threshold 199 200 // Check if plugin disables threshold. 187 201 $plugin_disables_threshold = false; 188 202 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) ) { 189 $plugin_disables_threshold = ( $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold');190 } 191 192 // Show yellow warning message if plugin disables threshold 203 $plugin_disables_threshold = ( 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ); 204 } 205 206 // Show yellow warning message if plugin disables threshold. 193 207 if ( $plugin_disables_threshold ) { 194 printf( '<br><small class="description dtat-notice-caution">%s %s</small>', 208 printf( 209 '<br><small class="description dtat-notice-caution">%s %s</small>', 195 210 esc_html( '⚠️' ), 196 211 esc_html__( 'Disabled by plugin', 'disable-thumbnails-and-threshold' ) … … 207 222 208 223 if ( $plugin_threshold && $plugin_threshold !== $wp_default_threshold ) { 209 printf( '<br><small class="description dtat-notice-warning">%s %s</small>', 224 printf( 225 '<br><small class="description dtat-notice-warning">%s %s</small>', 210 226 esc_html( '⚠️' ), 211 / / translators: %1$d: Plugin threshold value in pixels, %2$d: WordPress default threshold value in pixels227 /* translators: %1$d: Plugin threshold value in pixels, %2$d: WordPress default threshold value in pixels */ 212 228 esc_html( sprintf( __( 'Plugin threshold (%1$dpx) differs from WordPress default (%2$dpx)', 'disable-thumbnails-and-threshold' ), $plugin_threshold, $wp_default_threshold ) ) 213 229 ); 214 230 } else { 215 / / translators: %d: WordPress default big image threshold value in pixels231 /* translators: %d: WordPress default big image threshold value in pixels */ 216 232 printf( '<br><small class="description dtat-notice-info">%s</small>', esc_html( sprintf( __( 'WordPress default big image threshold: %dpx', 'disable-thumbnails-and-threshold' ), $wp_default_threshold ) ) ); 217 233 } … … 229 245 '<label class="switch"><input type="checkbox" name="%s[disable_threshold]" id="disable_threshold" value="disable_threshold" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 230 246 esc_attr( DTAT_THRESHOLD_OPTION ), 231 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) && $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold') ? 'checked' : '',247 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) && 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ) ? 'checked' : '', 232 248 esc_html__( 'Disable Threshold', 'disable-thumbnails-and-threshold' ) 233 249 ); 234 250 235 251 // Show informational status based on plugin's stored setting. 236 252 // We avoid calling apply_filters('big_image_size_threshold') here because it expects … … 238 254 $plugin_intends_to_disable = false; 239 255 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) ) { 240 $plugin_intends_to_disable = ( $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold');256 $plugin_intends_to_disable = ( 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ); 241 257 } 242 258 243 259 if ( $plugin_intends_to_disable ) { 244 printf( '<br><small class="description dtat-notice-info">%s</small>', 260 printf( 261 '<br><small class="description dtat-notice-info">%s</small>', 245 262 esc_html__( 'Threshold is disabled by this plugin.', 'disable-thumbnails-and-threshold' ) 246 263 ); … … 258 275 '<label class="switch"><input type="checkbox" name="%s[disable_image_rotation_exif]" id="disable_image_rotation_exif" value="disable_image_rotation_exif" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 259 276 esc_attr( DTAT_THRESHOLD_OPTION ), 260 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) && $this->dtat_disablethreshold_options['disable_image_rotation_exif'] === 'disable_image_rotation_exif') ? 'checked' : '',277 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) && 'disable_image_rotation_exif' === $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) ? 'checked' : '', 261 278 esc_html__( 'Disable Image Rotation by EXIF', 'disable-thumbnails-and-threshold' ) 262 279 ); 263 280 264 281 // Show informational status based on plugin's stored setting. 265 282 // We avoid calling apply_filters('wp_image_maybe_exif_rotate') here because it expects … … 267 284 $plugin_exif_disabled = false; 268 285 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) ) { 269 $plugin_exif_disabled = ( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] === 'disable_image_rotation_exif');286 $plugin_exif_disabled = ( 'disable_image_rotation_exif' === $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ); 270 287 } 271 288 272 289 if ( $plugin_exif_disabled ) { 273 printf( '<br><small class="description dtat-notice-info">%s</small>', 290 printf( 291 '<br><small class="description dtat-notice-info">%s</small>', 274 292 esc_html__( 'EXIF rotation is disabled by this plugin.', 'disable-thumbnails-and-threshold' ) 275 293 ); 276 294 } 277 295 } 278 279 296 } 280 297 if ( is_admin() ) { 281 $ DTAT_Disable_Threshold = new DTAT_Disable_Threshold();298 $dtat_disable_threshold = new DTAT_Disable_Threshold(); 282 299 } -
disable-thumbnails-and-threshold/tags/0.8.0/includes/option-thumbnails.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Image Sizes settings page. 19 * 20 * @since 0.1 21 */ 17 22 class DTAT_Disable_Thumbnails { 18 private array|false $dtat_disablethumbnails_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_disablethumbnails_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 36 46 public function add_plugin_page() { 37 47 add_management_page( 38 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 39 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 40 'manage_options', 41 'kgmdisablethumbnails', 42 [ $this, 'create_admin_page' ]48 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 49 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 50 'manage_options', 51 'kgmdisablethumbnails', 52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Image Thumbnails', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Image Thumbnails', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <p><?php echo esc_html__( 'Flagged image sizes will be disabled.', 'disable-thumbnails-and-threshold' ); ?></p> 67 77 <?php settings_errors(); ?> … … 75 85 </form> 76 86 </div> 77 <?php } 87 <?php 88 } 78 89 79 90 /** … … 86 97 register_setting( 87 98 'kgmdisablethumbnails_option_group', 88 DTAT_THUMBNAILS_OPTION, 89 [ $this, 'sanitize' ]99 DTAT_THUMBNAILS_OPTION, 100 array( $this, 'sanitize' ) 90 101 ); 91 102 92 103 add_settings_section( 93 'kgmdisablethumbnails_setting_section', 94 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 95 [ $this, 'section_info' ],96 'kgmdisablethumbnails-admin' 104 'kgmdisablethumbnails_setting_section', 105 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 106 array( $this, 'section_info' ), 107 'kgmdisablethumbnails-admin' 97 108 ); 98 109 99 110 add_settings_field( 100 111 'thumbnail', 101 esc_html__( 'Thumbnail', 'disable-thumbnails-and-threshold' ), 102 [ $this, 'thumbnail_callback' ],103 'kgmdisablethumbnails-admin', 104 'kgmdisablethumbnails_setting_section' 112 esc_html__( 'Thumbnail', 'disable-thumbnails-and-threshold' ), 113 array( $this, 'thumbnail_callback' ), 114 'kgmdisablethumbnails-admin', 115 'kgmdisablethumbnails_setting_section' 105 116 ); 106 117 add_settings_field( 107 118 'medium', 108 esc_html__( 'Medium', 'disable-thumbnails-and-threshold' ), 109 [ $this, 'medium_callback' ],110 'kgmdisablethumbnails-admin', 111 'kgmdisablethumbnails_setting_section' 119 esc_html__( 'Medium', 'disable-thumbnails-and-threshold' ), 120 array( $this, 'medium_callback' ), 121 'kgmdisablethumbnails-admin', 122 'kgmdisablethumbnails_setting_section' 112 123 ); 113 124 add_settings_field( 114 125 'medium_large', 115 126 esc_html__( 'Medium Large', 'disable-thumbnails-and-threshold' ), 116 [ $this, 'medium_large_callback' ],117 'kgmdisablethumbnails-admin', 118 'kgmdisablethumbnails_setting_section' 119 ); 120 add_settings_field( 121 'large', 122 esc_html__( 'Large', 'disable-thumbnails-and-threshold' ), 123 [ $this, 'large_callback' ],124 'kgmdisablethumbnails-admin', 125 'kgmdisablethumbnails_setting_section' 127 array( $this, 'medium_large_callback' ), 128 'kgmdisablethumbnails-admin', 129 'kgmdisablethumbnails_setting_section' 130 ); 131 add_settings_field( 132 'large', 133 esc_html__( 'Large', 'disable-thumbnails-and-threshold' ), 134 array( $this, 'large_callback' ), 135 'kgmdisablethumbnails-admin', 136 'kgmdisablethumbnails_setting_section' 126 137 ); 127 138 128 139 $image_sizes = wp_get_additional_image_sizes(); 129 140 foreach ( $image_sizes as $key => $image_size ) { 130 if ( 1 === $image_size['crop']) {141 if ( ! empty( $image_size['crop'] ) ) { 131 142 $crop = esc_html__( 'cropped', 'disable-thumbnails-and-threshold' ); 132 143 } else { … … 135 146 add_settings_field( 136 147 $key, 137 esc_html( $key ) . '<br><small>(' . esc_attr( $image_size['width'] ) . 'x' . esc_attr( $image_size['height'] ) . ')</small><br><small>' . esc_html( $crop ) . '</small>',138 [ $this, 'ext_callback' ],148 esc_html( $key ) . '<br><small>(' . absint( $image_size['width'] ) . 'x' . absint( $image_size['height'] ) . ')</small><br><small>' . esc_html( $crop ) . '</small>', 149 array( $this, 'ext_callback' ), 139 150 'kgmdisablethumbnails-admin', 140 151 'kgmdisablethumbnails_setting_section', 141 [ 'name' => $key ]152 array( 'name' => $key ) 142 153 ); 143 154 } … … 147 158 * Sanitize and validate form input before saving. 148 159 * 149 * @since 0.1 150 * @param array $input Raw form input values. 160 * Runs on every update_option() of this option, not only on form submit, so it 161 * must not depend on the current user: options.php already enforces the nonce 162 * and the manage_options capability before saving. 163 * 164 * Each checkbox posts its own size name as value, so only "size => size" pairs 165 * for sizes registered on this site are kept. 166 * 167 * @since 0.1 168 * @param mixed $input Raw value; null when every checkbox is unchecked. 151 169 * @return array Sanitized values. 152 170 */ 153 public function sanitize( array $input ): array { 154 // Check user capabilities for security 155 if ( ! current_user_can( 'manage_options' ) ) { 156 return $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, [] ); 157 } 158 159 // Nonce is already verified by WordPress options.php handler via settings_fields(). 160 $sanitary_values = []; 161 162 if ( isset( $input['thumbnail'] ) ) { 163 $sanitary_values['thumbnail'] = sanitize_text_field( $input['thumbnail'] ); 164 } 165 if ( isset( $input['medium'] ) ) { 166 $sanitary_values['medium'] = sanitize_text_field( $input['medium'] ); 167 } 168 if ( isset( $input['medium_large'] ) ) { 169 $sanitary_values['medium_large'] = sanitize_text_field( $input['medium_large'] ); 170 } 171 if ( isset( $input['large'] ) ) { 172 $sanitary_values['large'] = sanitize_text_field( $input['large'] ); 173 } 174 175 $image_sizes = wp_get_additional_image_sizes(); 176 foreach ( $image_sizes as $key => $image_size ) { 177 if ( isset( $input[ $key ] ) ) { 178 $sanitary_values[ $key ] = sanitize_text_field( $input[ $key ] ); 171 public function sanitize( $input ): array { 172 if ( ! is_array( $input ) ) { 173 return array(); 174 } 175 176 $sanitary_values = array(); 177 $known_sizes = array_merge( 178 array( 'thumbnail', 'medium', 'medium_large', 'large' ), 179 array_keys( wp_get_additional_image_sizes() ) 180 ); 181 182 foreach ( $known_sizes as $size ) { 183 if ( isset( $input[ $size ] ) && sanitize_text_field( $input[ $size ] ) === (string) $size ) { 184 $sanitary_values[ $size ] = (string) $size; 179 185 } 180 186 } … … 190 196 */ 191 197 public function section_info() { 192 193 198 } 194 199 … … 203 208 '<label class="switch"><input type="checkbox" name="%s[thumbnail]" id="thumbnail" value="thumbnail" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 204 209 esc_attr( DTAT_THUMBNAILS_OPTION ), 205 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['thumbnail'] ) && $this->dtat_disablethumbnails_options['thumbnail'] === 'thumbnail') ? 'checked' : '',210 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['thumbnail'] ) && 'thumbnail' === $this->dtat_disablethumbnails_options['thumbnail'] ) ? 'checked' : '', 206 211 esc_html__( 'Disable Thumbnail size', 'disable-thumbnails-and-threshold' ) 207 212 ); … … 218 223 '<label class="switch"><input type="checkbox" name="%s[medium]" id="medium" value="medium" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 219 224 esc_attr( DTAT_THUMBNAILS_OPTION ), 220 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium'] ) && $this->dtat_disablethumbnails_options['medium'] === 'medium') ? 'checked' : '',225 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium'] ) && 'medium' === $this->dtat_disablethumbnails_options['medium'] ) ? 'checked' : '', 221 226 esc_html__( 'Disable Medium size', 'disable-thumbnails-and-threshold' ) 222 227 ); … … 233 238 '<label class="switch"><input type="checkbox" name="%s[medium_large]" id="medium_large" value="medium_large" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 234 239 esc_attr( DTAT_THUMBNAILS_OPTION ), 235 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium_large'] ) && $this->dtat_disablethumbnails_options['medium_large'] === 'medium_large') ? 'checked' : '',240 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium_large'] ) && 'medium_large' === $this->dtat_disablethumbnails_options['medium_large'] ) ? 'checked' : '', 236 241 esc_html__( 'Disable Medium Large size', 'disable-thumbnails-and-threshold' ) 237 242 ); … … 248 253 '<label class="switch"><input type="checkbox" name="%s[large]" id="large" value="large" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 249 254 esc_attr( DTAT_THUMBNAILS_OPTION ), 250 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['large'] ) && $this->dtat_disablethumbnails_options['large'] === 'large') ? 'checked' : '',255 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['large'] ) && 'large' === $this->dtat_disablethumbnails_options['large'] ) ? 'checked' : '', 251 256 esc_html__( 'Disable Large size', 'disable-thumbnails-and-threshold' ) 252 257 ); … … 268 273 esc_attr( $name ), 269 274 esc_attr( $name ), 270 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options[ $name] ) && $this->dtat_disablethumbnails_options[$name] === $name) ? 'checked' : '',275 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options[ $name ] ) && $name === $this->dtat_disablethumbnails_options[ $name ] ) ? 'checked' : '', 271 276 /* translators: %s: Image size name */ 272 277 esc_html( sprintf( __( 'Disable %s size', 'disable-thumbnails-and-threshold' ), $name ) ) 273 278 ); 274 279 } 275 276 280 } 277 281 if ( is_admin() ) { 278 $ DTAT_Disable_Thumbnails = new DTAT_Disable_Thumbnails();282 $dtat_disable_thumbnails = new DTAT_Disable_Thumbnails(); 279 283 } -
disable-thumbnails-and-threshold/tags/0.8.0/readme.txt
r3504636 r3789337 3 3 Donate link: https://kgmservizi.com 4 4 Tags: thumbnails, disable thumbnails, disable threshold, disable images, image options 5 Requires at least: 5. 46 Tested up to: 6.87 Requires PHP: 7.48 Stable tag: 0. 7.05 Requires at least: 5.6 6 Tested up to: 7.1 7 Requires PHP: 8.0 8 Stable tag: 0.8.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 76 76 == Changelog == 77 77 78 = 0.8.0 = 79 * Requirements: minimum PHP raised to 8.0 and minimum WordPress to 5.6 (the first release with PHP 8.0 support). 80 * Fix: saving the Image Sizes page with every size unchecked caused a fatal error. 81 * Fix: settings saved through WP-CLI were silently discarded. 82 * Fix: the "cropped" label now appears for custom image sizes registered with cropping. 83 * Fix: no fatal error when another plugin hooks `jpeg_quality` or `big_image_size_threshold` with required extra arguments. 84 * Coding standards cleanup. 85 78 86 = 0.7.0 = 79 87 * Improved accessibility: toggle switches are now fully keyboard-navigable with visible focus indicators and screen-reader labels. … … 98 106 == Upgrade Notice == 99 107 108 = 0.8.0 = 109 Requires PHP 8.0+ and WordPress 5.6+. Fixes a fatal error when unchecking every image size. 110 100 111 = 0.7.0 = 101 112 Accessibility, compatibility and performance improvements. No breaking changes — all settings and URLs are preserved. Recommended update for all users. -
disable-thumbnails-and-threshold/trunk/disable-thumbnails-and-thresold.php
r3504636 r3789337 1 1 <?php 2 /* 3 Plugin Name: Disable Thumbnails, Threshold and Image Options 4 Version: 0.7.0 5 Description: Disable Thumbnails, Threshold and Image Options 6 Author: KGM Servizi 7 Author URI: https://kgmservizi.com 8 License: GPLv2 or later 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 Text Domain: disable-thumbnails-and-threshold 11 Requires at least: 5.4 12 Requires PHP: 7.4 13 */ 2 /** 3 * Plugin Name: Disable Thumbnails, Threshold and Image Options 4 * Version: 0.8.0 5 * Description: Disable Thumbnails, Threshold and Image Options 6 * Author: KGM Servizi 7 * Author URI: https://kgmservizi.com 8 * License: GPLv2 or later 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 * Text Domain: disable-thumbnails-and-threshold 11 * Requires at least: 5.6 12 * Requires PHP: 8.0 13 * 14 * @package Disable_Thumbnails_Threshold 15 */ 14 16 15 17 if ( ! defined( 'ABSPATH' ) ) { 16 exit; // Exit if accessed directly 17 } 18 19 // Define plugin constants for better maintainability 18 exit; // Exit if accessed directly. 19 } 20 21 // Define plugin constants for better maintainability. 20 22 define( 'DTAT_QUALITY_OPTION', 'dtat_imgquality_option_name' ); 21 23 define( 'DTAT_THRESHOLD_OPTION', 'dtat_disablethreshold_option_name' ); 22 24 define( 'DTAT_THUMBNAILS_OPTION', 'dtat_disablethumbnails_option_name' ); 23 25 define( 'DTAT_MIGRATION_OPTION', 'dtat_migration_done' ); 24 define( 'DTAT_VERSION', '0.7.0' ); 25 26 /** 27 * PHPCS Suppressions 28 * 29 * This file contains phpcs:ignore comments for the following cases: 30 * - Line 151, 131 (option-quality.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 31 * Reason: Using WordPress core hook (jpeg_quality) which doesn't require plugin prefix 32 * - Line 174, 172 (option-threshold-exif.php), 206 (option-threshold-exif.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 33 * Reason: Using WordPress core hook (big_image_size_threshold) which doesn't require plugin prefix 34 * - Line 241 (option-threshold-exif.php): WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound 35 * Reason: Using WordPress core hook (wp_image_maybe_exif_rotate) which doesn't require plugin prefix 36 */ 37 38 // Check WordPress version compatibility - requires WordPress 5.4+ for PHP 7.4+ support 39 // Use admin_init hook to ensure WordPress is fully loaded 26 define( 'DTAT_VERSION', '0.8.0' ); 27 define( 'DTAT_MIN_WP_VERSION', '5.6' ); 28 define( 'DTAT_MIN_PHP_VERSION', '8.0' ); 29 30 // Check WordPress version compatibility - WordPress 5.6 is the first release that supports PHP 8.0. 31 // Use admin_init hook to ensure WordPress is fully loaded. 40 32 add_action( 'admin_init', 'dtat_check_wordpress_version' ); 41 33 … … 50 42 51 43 /** 52 * 44 * 53 45 * Retrieve options for quality and threshold 54 46 * Cache options globally to avoid multiple database calls 55 *56 47 */ 57 48 $GLOBALS['dtat_imgquality_options'] = get_option( DTAT_QUALITY_OPTION ); … … 77 68 $processed = true; 78 69 70 // admin_init also fires for logged-out admin-ajax.php/admin-post.php requests. 71 if ( ! current_user_can( 'manage_options' ) ) { 72 return; 73 } 74 79 75 // Skip migration if already completed for this plugin version. 80 76 if ( get_option( DTAT_MIGRATION_OPTION ) === DTAT_VERSION ) { … … 82 78 } 83 79 84 $option_map = [85 DTAT_QUALITY_OPTION => 'kgmimgquality_option_name',86 DTAT_THRESHOLD_OPTION => 'kgmdisablethreshold_option_name',87 DTAT_THUMBNAILS_OPTION => 'kgmdisablethumbnails_option_name',88 ];80 $option_map = array( 81 DTAT_QUALITY_OPTION => 'kgmimgquality_option_name', 82 DTAT_THRESHOLD_OPTION => 'kgmdisablethreshold_option_name', 83 DTAT_THUMBNAILS_OPTION => 'kgmdisablethumbnails_option_name', 84 ); 89 85 90 86 foreach ( $option_map as $new_option => $legacy_option ) { … … 105 101 } 106 102 103 /* 104 * The globals were cached at load time, before the migration. Without a refresh, 105 * dtat_initialize_options() (same hook, later) sees them empty and overwrites the 106 * migrated values with defaults, after the legacy rows are already deleted. 107 */ 108 $GLOBALS['dtat_imgquality_options'] = get_option( DTAT_QUALITY_OPTION ); 109 $GLOBALS['dtat_disablethreshold_options'] = get_option( DTAT_THRESHOLD_OPTION ); 110 $GLOBALS['dtat_disablethumbnails_options'] = get_option( DTAT_THUMBNAILS_OPTION ); 111 107 112 update_option( DTAT_MIGRATION_OPTION, DTAT_VERSION ); 108 113 } 109 114 110 115 111 // Initialize with current WordPress values if options don't exist 112 // This will be handled in the admin_init hook to ensure WordPress is fully loaded 116 // Initialize with current WordPress values if options don't exist. 117 // This will be handled in the admin_init hook to ensure WordPress is fully loaded. 113 118 add_action( 'admin_init', 'dtat_initialize_options' ); 114 119 115 // Hook to apply filters after themes are loaded to ensure priority 120 // Hook to apply filters after themes are loaded to ensure priority. 116 121 add_action( 'after_setup_theme', 'dtat_apply_filters', 20 ); 117 122 … … 126 131 */ 127 132 function dtat_check_wordpress_version(): void { 128 // Only run in admin 133 // Only run in admin. 129 134 if ( ! is_admin() ) { 130 135 return; 131 136 } 132 133 // Check if WordPress version is compatible 134 if ( version_compare( get_bloginfo( 'version' ), '5.4', '<' ) ) {137 138 // Check if WordPress version is compatible. 139 if ( version_compare( get_bloginfo( 'version' ), DTAT_MIN_WP_VERSION, '<' ) ) { 135 140 add_action( 'admin_notices', 'dtat_wordpress_version_notice' ); 136 141 } … … 146 151 function dtat_wordpress_version_notice(): void { 147 152 printf( 148 '<div class="notice notice-error"><p><strong>%s</strong> %s</p></div>', 149 esc_html__( 'Disable Thumbnails, Threshold and Image Options', 'disable-thumbnails-and-threshold' ), 150 esc_html__( 'requires WordPress 5.4 or higher (PHP 7.4+). Please update WordPress.', 'disable-thumbnails-and-threshold' ) 153 '<div class="notice notice-error"><p>%s</p></div>', 154 esc_html( 155 sprintf( 156 /* translators: 1: Plugin name, 2: Minimum WordPress version, 3: Minimum PHP version. */ 157 __( '%1$s requires WordPress %2$s or higher and PHP %3$s or higher. Please update.', 'disable-thumbnails-and-threshold' ), 158 'Disable Thumbnails, Threshold and Image Options', 159 DTAT_MIN_WP_VERSION, 160 DTAT_MIN_PHP_VERSION 161 ) 162 ) 151 163 ); 152 164 } … … 162 174 */ 163 175 function dtat_initialize_options(): void { 164 // Only run in admin and if user has proper capabilities 176 // Only run in admin and if user has proper capabilities. 165 177 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { 166 178 return; 167 179 } 168 169 // Initialize JPEG quality option if it doesn't exist or is invalid 170 if ( ! $GLOBALS['dtat_imgquality_options'] || 171 ! is_array( $GLOBALS['dtat_imgquality_options'] ) || 172 ! isset( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 173 ! is_numeric( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 174 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) < 1 || 175 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) > 100 ) { 176 177 // Get current WordPress JPEG quality (respects existing filters/plugins) 178 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 179 $current_quality = apply_filters( 'jpeg_quality', 82 ); 180 181 // Validate the quality value from filters 180 181 // Initialize JPEG quality option if it doesn't exist or is invalid. 182 if ( ! $GLOBALS['dtat_imgquality_options'] || 183 ! is_array( $GLOBALS['dtat_imgquality_options'] ) || 184 ! isset( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 185 ! is_numeric( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) || 186 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) < 1 || 187 intval( $GLOBALS['dtat_imgquality_options']['jpeg_quality'] ) > 100 ) { 188 /* 189 * Get current WordPress JPEG quality (respects existing filters/plugins). 190 * Pass every argument core passes: on PHP 8 a third-party callback with a 191 * required $context would otherwise throw ArgumentCountError here. 192 */ 193 try { 194 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 195 $current_quality = apply_filters( 'jpeg_quality', 82, 'image_resize' ); 196 } catch ( Throwable $e ) { 197 $current_quality = 82; 198 } 199 200 // Validate the quality value from filters. 182 201 if ( ! is_numeric( $current_quality ) || $current_quality < 1 || $current_quality > 100 ) { 183 $current_quality = 82; // Fallback to WordPress default 184 } 185 186 // Preserve existing options and only update jpeg_quality 202 $current_quality = 82; // Fallback to WordPress default. 203 } 204 205 // Preserve existing options and only update jpeg_quality. 187 206 if ( ! is_array( $GLOBALS['dtat_imgquality_options'] ) ) { 188 $GLOBALS['dtat_imgquality_options'] = [];207 $GLOBALS['dtat_imgquality_options'] = array(); 189 208 } 190 209 $GLOBALS['dtat_imgquality_options']['jpeg_quality'] = intval( $current_quality ); 191 210 update_option( DTAT_QUALITY_OPTION, $GLOBALS['dtat_imgquality_options'] ); 192 211 } 193 194 // Initialize threshold option if it doesn't exist or is invalid 195 if ( ! $GLOBALS['dtat_disablethreshold_options'] || 196 ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) || 197 ! isset( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 198 ! is_numeric( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 199 intval( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) <= 0 ) { 200 201 // Get current WordPress big image threshold (respects existing filters/plugins) 202 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 203 $current_threshold = apply_filters( 'big_image_size_threshold', 2560 ); 204 205 // Validate the threshold value from filters 212 213 // Initialize threshold option if it doesn't exist or is invalid. 214 if ( ! $GLOBALS['dtat_disablethreshold_options'] || 215 ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) || 216 ! isset( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 217 ! is_numeric( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) || 218 intval( $GLOBALS['dtat_disablethreshold_options']['new_threshold'] ) <= 0 ) { 219 /* 220 * Get current WordPress big image threshold (respects existing filters/plugins). 221 * Core passes $imagesize, $file and $attachment_id; there is no real image here, 222 * so neutral values are passed and any callback failure falls back to the default. 223 */ 224 try { 225 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WordPress core hook 226 $current_threshold = apply_filters( 'big_image_size_threshold', 2560, array( 0, 0 ), '', 0 ); 227 } catch ( Throwable $e ) { 228 $current_threshold = 2560; 229 } 230 231 // Validate the threshold value from filters. 206 232 if ( ! is_numeric( $current_threshold ) || $current_threshold <= 0 ) { 207 $current_threshold = 2560; // Fallback to WordPress default 208 } 209 210 // Preserve existing options and only update new_threshold 233 $current_threshold = 2560; // Fallback to WordPress default. 234 } 235 236 // Preserve existing options and only update new_threshold. 211 237 if ( ! is_array( $GLOBALS['dtat_disablethreshold_options'] ) ) { 212 $GLOBALS['dtat_disablethreshold_options'] = [];238 $GLOBALS['dtat_disablethreshold_options'] = array(); 213 239 } 214 240 $GLOBALS['dtat_disablethreshold_options']['new_threshold'] = intval( $current_threshold ); … … 225 251 */ 226 252 function dtat_jpeg_quality_filter(): int { 227 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);228 253 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 254 229 255 if ( ! is_array( $dtat_imgquality_options ) || ! isset( $dtat_imgquality_options['jpeg_quality'] ) ) { 230 return 82; // WordPress default 231 } 232 256 return 82; // WordPress default. 257 } 258 233 259 $quality = intval( $dtat_imgquality_options['jpeg_quality'] ); 234 235 // Validate quality range (0-100)236 if ( $quality < 0|| $quality > 100 ) {237 return 82; // WordPress default 238 } 239 260 261 // Same 1-100 range accepted by the settings page. 262 if ( $quality < 1 || $quality > 100 ) { 263 return 82; // WordPress default. 264 } 265 240 266 return $quality; 241 267 } … … 249 275 */ 250 276 function dtat_big_image_threshold_filter(): int { 251 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, []);252 277 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, array() ); 278 253 279 if ( ! is_array( $dtat_disablethreshold_options ) || ! isset( $dtat_disablethreshold_options['new_threshold'] ) ) { 254 return 2560; // WordPress default 255 } 256 280 return 2560; // WordPress default. 281 } 282 257 283 $threshold = intval( $dtat_disablethreshold_options['new_threshold'] ); 258 259 // Validate threshold is positive 284 285 // Validate threshold is positive. 260 286 if ( $threshold <= 0 ) { 261 return 2560; // WordPress default 262 } 263 287 return 2560; // WordPress default. 288 } 289 264 290 return $threshold; 265 291 } … … 270 296 * @since 0.1 271 297 * @package Disable_Thumbnails_Threshold 272 * @param array $sizes Registered intermediate image sizes. 273 * @return array Filtered image sizes with disabled ones removed. 274 */ 275 function dtat_thumbnail_sizes_filter( array $sizes ): array { 276 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, [] ); 277 298 * @param mixed $sizes Registered intermediate image sizes (an array, unless another filter broke it). 299 * @return mixed Filtered image sizes with disabled ones removed. 300 */ 301 function dtat_thumbnail_sizes_filter( $sizes ) { 302 // Untyped on purpose: a TypeError here would break every media upload. 303 if ( ! is_array( $sizes ) ) { 304 return $sizes; 305 } 306 307 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, array() ); 308 278 309 if ( ! is_array( $dtat_disablethumbnails_options ) || empty( $dtat_disablethumbnails_options ) ) { 279 310 return $sizes; 280 311 } 281 282 // Validate that all values in the array are strings (security check) 312 313 // Validate that all values in the array are strings (security check). 283 314 $valid_options = array_filter( $dtat_disablethumbnails_options, 'is_string' ); 284 315 285 316 return array_diff( $sizes, $valid_options ); 286 317 } … … 294 325 */ 295 326 function dtat_apply_filters(): void { 296 // Prevent multiple applications 327 // Prevent multiple applications. 297 328 static $applied = false; 298 329 if ( $applied ) { … … 300 331 } 301 332 $applied = true; 302 303 // Remove any existing filters to prevent accumulation 333 334 // Remove any existing filters to prevent accumulation. 304 335 remove_filter( 'jpeg_quality', 'dtat_jpeg_quality_filter' ); 305 336 remove_filter( 'big_image_size_threshold', 'dtat_big_image_threshold_filter' ); 306 337 remove_filter( 'intermediate_image_sizes', 'dtat_thumbnail_sizes_filter' ); 307 308 // Safely get options with fallback 309 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);310 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, []);311 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, []);312 313 // Apply JPEG quality filter 338 339 // Safely get options with fallback. 340 $dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 341 $dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, array() ); 342 $dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, array() ); 343 344 // Apply JPEG quality filter. 314 345 $jpeg_quality = null; 315 346 if ( is_array( $dtat_imgquality_options ) ) { 316 347 $jpeg_quality = $dtat_imgquality_options['jpeg_quality'] ?? null; 317 348 } 318 349 319 350 $quality = $jpeg_quality ? intval( $jpeg_quality ) : 0; 320 351 if ( $jpeg_quality && is_numeric( $jpeg_quality ) && $quality > 0 && $quality <= 100 ) { … … 322 353 } 323 354 324 // Apply threshold filters 355 // Apply threshold filters. 325 356 if ( is_array( $dtat_disablethreshold_options ) ) { 326 // Set new threshold 357 // Set new threshold. 327 358 if ( ! empty( $dtat_disablethreshold_options['new_threshold'] ) 328 359 && is_numeric( $dtat_disablethreshold_options['new_threshold'] ) ) { … … 333 364 } 334 365 335 // Disable threshold 366 // Disable threshold. 336 367 if ( 'disable_threshold' === ( $dtat_disablethreshold_options['disable_threshold'] ?? null ) ) { 337 368 add_filter( 'big_image_size_threshold', '__return_false', 100 ); 338 369 } 339 370 340 // Disable EXIF rotation 371 // Disable EXIF rotation. 341 372 if ( 'disable_image_rotation_exif' === ( $dtat_disablethreshold_options['disable_image_rotation_exif'] ?? null ) ) { 342 373 add_filter( 'wp_image_maybe_exif_rotate', '__return_zero', 100, 2 ); … … 344 375 } 345 376 346 // Apply thumbnail size filters 377 // Apply thumbnail size filters. 347 378 if ( ! empty( $dtat_disablethumbnails_options ) ) { 348 379 add_filter( 'intermediate_image_sizes', 'dtat_thumbnail_sizes_filter', 100 ); … … 350 381 } 351 382 352 // All filters are now applied in dtat_apply_filters() function after themes are loaded 383 // All filters are now applied in dtat_apply_filters() function after themes are loaded. 353 384 354 385 /** … … 361 392 */ 362 393 function dtat_action_links( array $actions ): array { 363 // Check if user has proper capabilities before showing action links 394 // Check if user has proper capabilities before showing action links. 364 395 if ( ! current_user_can( 'manage_options' ) ) { 365 396 return $actions; 366 397 } 367 368 $mylinks = [398 399 $mylinks = array( 369 400 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmdisablethumbnails' ) ) . '">' . esc_html__( 'Image sizes', 'disable-thumbnails-and-threshold' ) . '</a>', 370 401 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmimgquality' ) ) . '">' . esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ) . '</a>', 371 402 '<a href="' . esc_url( get_admin_url( null, 'tools.php?page=kgmdisablethreshold' ) ) . '">' . esc_html__( 'Threshold & EXIF', 'disable-thumbnails-and-threshold' ) . '</a>', 372 ];403 ); 373 404 return array_merge( $mylinks, $actions ); 374 405 } … … 383 414 */ 384 415 function dtat_admin_styles( string $hook ): void { 385 /**386 * Check if in plugin options page and user has proper capabilities387 */388 416 if ( ! current_user_can( 'manage_options' ) ) { 389 417 return; 390 418 } 391 392 $screen = get_current_screen(); 393 if ( ! $screen ) { 394 return; 395 } 396 397 if ( 'tools_page_kgmdisablethumbnails' === $screen->base || 'tools_page_kgmdisablethreshold' === $screen->base ) { 398 wp_enqueue_style( 'dtat-admin-css', plugins_url( 'includes/admin.css', __FILE__ ), [], DTAT_VERSION ); 399 } 400 } 419 420 $plugin_pages = array( 'tools_page_kgmdisablethumbnails', 'tools_page_kgmdisablethreshold', 'tools_page_kgmimgquality' ); 421 if ( in_array( $hook, $plugin_pages, true ) ) { 422 wp_enqueue_style( 'dtat-admin-css', plugins_url( 'includes/admin.css', __FILE__ ), array(), DTAT_VERSION ); 423 } 424 } 425 426 register_uninstall_hook( __FILE__, 'dtat_plugin_uninstall' ); 401 427 402 428 /** 403 429 * Clean up plugin options on uninstall. 404 430 * 405 * @since 0.1 406 * @package Disable_Thumbnails_Threshold 407 * @return void 408 */ 409 register_uninstall_hook( __FILE__, 'dtat_plugin_uninstall' ); 431 * Also removes the pre-0.6.5 `kgm*` options, which survive when the migration never ran. 432 * 433 * @since 0.1 434 * @package Disable_Thumbnails_Threshold 435 * @return void 436 */ 410 437 function dtat_plugin_uninstall(): void { 411 438 delete_option( DTAT_THUMBNAILS_OPTION ); … … 413 440 delete_option( DTAT_QUALITY_OPTION ); 414 441 delete_option( DTAT_MIGRATION_OPTION ); 415 } 442 delete_option( 'kgmimgquality_option_name' ); 443 delete_option( 'kgmdisablethreshold_option_name' ); 444 delete_option( 'kgmdisablethumbnails_option_name' ); 445 } -
disable-thumbnails-and-threshold/trunk/includes/admin.css
r3504636 r3789337 1 1 .switch { position: relative; display: inline-block; width: 33px; height: 17px; margin-right: 0.4em; } 2 2 .switch input { position: absolute; opacity: 0; width: 1px; height: 1px; clip: rect(0 0 0 0); overflow: hidden; } 3 .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 18px; display:inline; } 3 /* Inset border #757575: 4.05:1 on the form-table background #f0f0f1 (SC 1.4.11 needs 3:1). */ 4 .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; box-shadow: inset 0 0 0 1px #757575; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 18px; display:inline; } 4 5 .slider::before { position: absolute; content: ""; height: 10px; width: 10px; left: 4px; bottom: 4px; background-color: #fff; -webkit-transition: 0.5s; transition: 0.5s; border-radius: 50%; } 5 6 input:checked + .screen-reader-text + .slider, 6 7 input:checked + .slider { background-color: #b12222; } 8 /* Transparent outline: box-shadow is dropped in forced-colors mode, the outline is not. */ 7 9 input:focus + .screen-reader-text + .slider, 8 input:focus + .slider { box-shadow:0 0 0 3px #005fcc; }10 input:focus + .slider { outline: 2px solid transparent; outline-offset: 2px; box-shadow: inset 0 0 0 1px #757575, 0 0 0 3px #005fcc; } 9 11 input:checked + .screen-reader-text + .slider::before, 10 12 input:checked + .slider::before { -webkit-transform: translateX(16px); -ms-transform: translateX(16px); transform: translateX(16px); } 11 .dtat-notice-warning { color: #d63638; } 12 .dtat-notice-caution { color: #dba617; } 13 @media (forced-colors: active) { 14 .slider { border: 1px solid ButtonText; } 15 .slider::before { background-color: ButtonText; } 16 input:checked + .screen-reader-text + .slider, 17 input:checked + .slider { background-color: Highlight; } 18 } 19 /* Ratios on #f0f0f1: warning 5.53:1, caution 4.86:1, info 5.04:1 (SC 1.4.3 needs 4.5:1). */ 20 .dtat-notice-warning { color: #b32d2e; } 21 .dtat-notice-caution { color: #8a6100; } 13 22 .dtat-notice-info { color: #666; } -
disable-thumbnails-and-threshold/trunk/includes/option-quality.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Image Quality settings page. 19 * 20 * @since 0.2 21 */ 17 22 class DTAT_Img_Quality { 18 private array|false $dtat_imgquality_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_imgquality_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 40 50 'manage_options', 41 51 'kgmimgquality', 42 [ $this, 'create_admin_page' ]52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_imgquality_options = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Image Quality', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <?php settings_errors(); ?> 67 77 … … 74 84 </form> 75 85 </div> 76 <?php } 86 <?php 87 } 77 88 78 89 /** … … 86 97 'kgmimgquality_option_group', 87 98 DTAT_QUALITY_OPTION, 88 [ $this, 'sanitize' ]99 array( $this, 'sanitize' ) 89 100 ); 90 101 91 102 add_settings_section( 92 103 'kgmimgquality_setting_section', 93 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 94 [ $this, 'section_info' ],95 'kgmimgquality-admin' 104 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 105 array( $this, 'section_info' ), 106 'kgmimgquality-admin' 96 107 ); 97 108 … … 99 110 'jpeg_quality', 100 111 esc_html__( 'JPEG Quality', 'disable-thumbnails-and-threshold' ) . ' <br> <small>' . esc_html__( 'Default WordPress: 82%', 'disable-thumbnails-and-threshold' ) . '</small>', 101 [ $this, 'jpeg_quality_callback' ],112 array( $this, 'jpeg_quality_callback' ), 102 113 'kgmimgquality-admin', 103 'kgmimgquality_setting_section' 114 'kgmimgquality_setting_section', 115 array( 'label_for' => 'jpeg_quality' ) 104 116 ); 105 117 } … … 108 120 * Sanitize and validate form input before saving. 109 121 * 110 * @since 0.2 111 * @param array $input Raw form input values. 122 * Runs on every update_option() of this option, not only on form submit, so it 123 * must not depend on the current user: options.php already enforces the nonce 124 * and the manage_options capability before saving. 125 * 126 * @since 0.2 127 * @param mixed $input Raw value; null when the field is missing from the request. 112 128 * @return array Sanitized values. 113 129 */ 114 public function sanitize( array $input ): array { 115 // Check user capabilities for security 116 if ( ! current_user_can( 'manage_options' ) ) { 117 return $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, [] ); 118 } 119 120 // Nonce is already verified by WordPress options.php handler via settings_fields(). 121 $sanitary_values = []; 130 public function sanitize( $input ): array { 131 if ( ! is_array( $input ) ) { 132 $input = array(); 133 } 134 135 $sanitary_values = array(); 122 136 123 137 if ( isset( $input['jpeg_quality'] ) ) { 124 $quality = sanitize_text_field( $input['jpeg_quality'] );138 $quality = sanitize_text_field( $input['jpeg_quality'] ); 125 139 $quality_int = intval( $quality ); 126 140 if ( is_numeric( $quality ) && $quality_int >= 1 && $quality_int <= 100 ) { … … 128 142 } else { 129 143 add_settings_error( 'kgmimgquality_option_notice', 'invalid_quality', esc_html__( 'JPEG quality must be a number between 1 and 100.', 'disable-thumbnails-and-threshold' ) ); 130 $existing = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, []);144 $existing = $GLOBALS['dtat_imgquality_options'] ?? get_option( DTAT_QUALITY_OPTION, array() ); 131 145 if ( is_array( $existing ) && isset( $existing['jpeg_quality'] ) ) { 132 return [ 'jpeg_quality' => absint( $existing['jpeg_quality'] ) ];146 return array( 'jpeg_quality' => absint( $existing['jpeg_quality'] ) ); 133 147 } 134 return [];148 return array(); 135 149 } 136 150 } … … 162 176 esc_html__( '%', 'disable-thumbnails-and-threshold' ) 163 177 ); 164 178 165 179 // Compare plugin value against WordPress default. 166 180 // We avoid calling apply_filters() here because the jpeg_quality filter expects … … 173 187 174 188 if ( $plugin_quality && $plugin_quality !== $wp_default_quality ) { 175 printf( '<br><small class="description dtat-notice-warning">%s %s</small>', 189 printf( 190 '<br><small class="description dtat-notice-warning">%s %s</small>', 176 191 esc_html( '⚠️' ), 177 / / translators: %1$d: Plugin quality percentage, %2$d: WordPress default quality percentage192 /* translators: %1$d: Plugin quality percentage, %2$d: WordPress default quality percentage */ 178 193 esc_html( sprintf( __( 'Plugin quality (%1$d%%) differs from WordPress default (%2$d%%)', 'disable-thumbnails-and-threshold' ), $plugin_quality, $wp_default_quality ) ) 179 194 ); 180 195 } else { 181 printf( '<br><small class="description dtat-notice-info">%s</small>', 182 // translators: %d: WordPress default JPEG quality percentage 196 printf( 197 '<br><small class="description dtat-notice-info">%s</small>', 198 /* translators: %d: WordPress default JPEG quality percentage */ 183 199 esc_html( sprintf( __( 'WordPress default JPEG quality: %d%%', 'disable-thumbnails-and-threshold' ), $wp_default_quality ) ) 184 200 ); 185 201 } 186 202 } 187 188 203 } 189 204 if ( is_admin() ) { 190 $ DTAT_Img_Quality = new DTAT_Img_Quality();205 $dtat_img_quality = new DTAT_Img_Quality(); 191 206 } -
disable-thumbnails-and-threshold/trunk/includes/option-threshold-exif.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Threshold & EXIF settings page. 19 * 20 * @since 0.1 21 */ 17 22 class DTAT_Disable_Threshold { 18 private array|false $dtat_disablethreshold_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_disablethreshold_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 40 50 'manage_options', 41 51 'kgmdisablethreshold', 42 [ $this, 'create_admin_page' ]52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_disablethreshold_options = $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Disable Threshold&EXIF', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Disable Threshold&EXIF', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <?php settings_errors(); ?> 67 77 … … 74 84 </form> 75 85 </div> 76 <?php } 86 <?php 87 } 77 88 78 89 /** … … 86 97 'kgmdisablethreshold_option_group', 87 98 DTAT_THRESHOLD_OPTION, 88 [ $this, 'sanitize' ]99 array( $this, 'sanitize' ) 89 100 ); 90 101 91 102 add_settings_section( 92 103 'kgmdisablethreshold_setting_section', 93 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 94 [ $this, 'section_info' ],95 'kgmdisablethreshold-admin' 104 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 105 array( $this, 'section_info' ), 106 'kgmdisablethreshold-admin' 96 107 ); 97 108 … … 99 110 'new_threshold', 100 111 esc_html__( 'New Size Threshold', 'disable-thumbnails-and-threshold' ) . ' <br> <small>' . esc_html__( 'Default WordPress: 2560px', 'disable-thumbnails-and-threshold' ) . '</small>', 101 [ $this, 'new_threshold_callback' ],112 array( $this, 'new_threshold_callback' ), 102 113 'kgmdisablethreshold-admin', 103 'kgmdisablethreshold_setting_section' 114 'kgmdisablethreshold_setting_section', 115 array( 'label_for' => 'new_threshold' ) 104 116 ); 105 117 add_settings_field( 106 118 'disable_threshold', 107 119 esc_html__( 'Disable Threshold', 'disable-thumbnails-and-threshold' ), 108 [ $this, 'disable_threshold_callback' ],120 array( $this, 'disable_threshold_callback' ), 109 121 'kgmdisablethreshold-admin', 110 122 'kgmdisablethreshold_setting_section' … … 113 125 'disable_image_rotation_exif', 114 126 esc_html__( 'Disable Image Rotation by EXIF', 'disable-thumbnails-and-threshold' ), 115 [ $this, 'disable_image_rotation_exif_callback' ],127 array( $this, 'disable_image_rotation_exif_callback' ), 116 128 'kgmdisablethreshold-admin', 117 129 'kgmdisablethreshold_setting_section' … … 122 134 * Sanitize and validate form input before saving. 123 135 * 124 * @since 0.1 125 * @param array $input Raw form input values. 136 * Runs on every update_option() of this option, not only on form submit, so it 137 * must not depend on the current user: options.php already enforces the nonce 138 * and the manage_options capability before saving. 139 * 140 * @since 0.1 141 * @param mixed $input Raw value; null when no field is present in the request. 126 142 * @return array Sanitized values. 127 143 */ 128 public function sanitize( array $input ): array { 129 // Check user capabilities for security 130 if ( ! current_user_can( 'manage_options' ) ) { 131 return $GLOBALS['dtat_disablethreshold_options'] ?? get_option( DTAT_THRESHOLD_OPTION, [] ); 132 } 133 134 // Nonce is already verified by WordPress options.php handler via settings_fields(). 135 $sanitary_values = []; 144 public function sanitize( $input ): array { 145 if ( ! is_array( $input ) ) { 146 $input = array(); 147 } 148 149 $sanitary_values = array(); 136 150 137 151 if ( isset( $input['new_threshold'] ) ) { … … 183 197 esc_html__( 'px', 'disable-thumbnails-and-threshold' ) 184 198 ); 185 186 // Check if plugin disables threshold 199 200 // Check if plugin disables threshold. 187 201 $plugin_disables_threshold = false; 188 202 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) ) { 189 $plugin_disables_threshold = ( $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold');190 } 191 192 // Show yellow warning message if plugin disables threshold 203 $plugin_disables_threshold = ( 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ); 204 } 205 206 // Show yellow warning message if plugin disables threshold. 193 207 if ( $plugin_disables_threshold ) { 194 printf( '<br><small class="description dtat-notice-caution">%s %s</small>', 208 printf( 209 '<br><small class="description dtat-notice-caution">%s %s</small>', 195 210 esc_html( '⚠️' ), 196 211 esc_html__( 'Disabled by plugin', 'disable-thumbnails-and-threshold' ) … … 207 222 208 223 if ( $plugin_threshold && $plugin_threshold !== $wp_default_threshold ) { 209 printf( '<br><small class="description dtat-notice-warning">%s %s</small>', 224 printf( 225 '<br><small class="description dtat-notice-warning">%s %s</small>', 210 226 esc_html( '⚠️' ), 211 / / translators: %1$d: Plugin threshold value in pixels, %2$d: WordPress default threshold value in pixels227 /* translators: %1$d: Plugin threshold value in pixels, %2$d: WordPress default threshold value in pixels */ 212 228 esc_html( sprintf( __( 'Plugin threshold (%1$dpx) differs from WordPress default (%2$dpx)', 'disable-thumbnails-and-threshold' ), $plugin_threshold, $wp_default_threshold ) ) 213 229 ); 214 230 } else { 215 / / translators: %d: WordPress default big image threshold value in pixels231 /* translators: %d: WordPress default big image threshold value in pixels */ 216 232 printf( '<br><small class="description dtat-notice-info">%s</small>', esc_html( sprintf( __( 'WordPress default big image threshold: %dpx', 'disable-thumbnails-and-threshold' ), $wp_default_threshold ) ) ); 217 233 } … … 229 245 '<label class="switch"><input type="checkbox" name="%s[disable_threshold]" id="disable_threshold" value="disable_threshold" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 230 246 esc_attr( DTAT_THRESHOLD_OPTION ), 231 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) && $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold') ? 'checked' : '',247 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) && 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ) ? 'checked' : '', 232 248 esc_html__( 'Disable Threshold', 'disable-thumbnails-and-threshold' ) 233 249 ); 234 250 235 251 // Show informational status based on plugin's stored setting. 236 252 // We avoid calling apply_filters('big_image_size_threshold') here because it expects … … 238 254 $plugin_intends_to_disable = false; 239 255 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_threshold'] ) ) { 240 $plugin_intends_to_disable = ( $this->dtat_disablethreshold_options['disable_threshold'] === 'disable_threshold');256 $plugin_intends_to_disable = ( 'disable_threshold' === $this->dtat_disablethreshold_options['disable_threshold'] ); 241 257 } 242 258 243 259 if ( $plugin_intends_to_disable ) { 244 printf( '<br><small class="description dtat-notice-info">%s</small>', 260 printf( 261 '<br><small class="description dtat-notice-info">%s</small>', 245 262 esc_html__( 'Threshold is disabled by this plugin.', 'disable-thumbnails-and-threshold' ) 246 263 ); … … 258 275 '<label class="switch"><input type="checkbox" name="%s[disable_image_rotation_exif]" id="disable_image_rotation_exif" value="disable_image_rotation_exif" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 259 276 esc_attr( DTAT_THRESHOLD_OPTION ), 260 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) && $this->dtat_disablethreshold_options['disable_image_rotation_exif'] === 'disable_image_rotation_exif') ? 'checked' : '',277 ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) && 'disable_image_rotation_exif' === $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) ? 'checked' : '', 261 278 esc_html__( 'Disable Image Rotation by EXIF', 'disable-thumbnails-and-threshold' ) 262 279 ); 263 280 264 281 // Show informational status based on plugin's stored setting. 265 282 // We avoid calling apply_filters('wp_image_maybe_exif_rotate') here because it expects … … 267 284 $plugin_exif_disabled = false; 268 285 if ( is_array( $this->dtat_disablethreshold_options ) && isset( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ) ) { 269 $plugin_exif_disabled = ( $this->dtat_disablethreshold_options['disable_image_rotation_exif'] === 'disable_image_rotation_exif');286 $plugin_exif_disabled = ( 'disable_image_rotation_exif' === $this->dtat_disablethreshold_options['disable_image_rotation_exif'] ); 270 287 } 271 288 272 289 if ( $plugin_exif_disabled ) { 273 printf( '<br><small class="description dtat-notice-info">%s</small>', 290 printf( 291 '<br><small class="description dtat-notice-info">%s</small>', 274 292 esc_html__( 'EXIF rotation is disabled by this plugin.', 'disable-thumbnails-and-threshold' ) 275 293 ); 276 294 } 277 295 } 278 279 296 } 280 297 if ( is_admin() ) { 281 $ DTAT_Disable_Threshold = new DTAT_Disable_Threshold();298 $dtat_disable_threshold = new DTAT_Disable_Threshold(); 282 299 } -
disable-thumbnails-and-threshold/trunk/includes/option-thumbnails.php
r3504636 r3789337 12 12 13 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; // Exit if accessed directly 14 exit; // Exit if accessed directly. 15 15 } 16 16 17 /** 18 * Image Sizes settings page. 19 * 20 * @since 0.1 21 */ 17 22 class DTAT_Disable_Thumbnails { 18 private array|false $dtat_disablethumbnails_options; 23 /** 24 * Stored option value. Untyped on purpose: whatever the database holds must not raise a TypeError. 25 * 26 * @var array|false 27 */ 28 private $dtat_disablethumbnails_options = false; 19 29 20 30 /** … … 24 34 */ 25 35 public function __construct() { 26 add_action( 'admin_menu', [ $this, 'add_plugin_page' ]);27 add_action( 'admin_init', [ $this, 'page_init' ]);36 add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); 37 add_action( 'admin_init', array( $this, 'page_init' ) ); 28 38 } 29 39 … … 36 46 public function add_plugin_page() { 37 47 add_management_page( 38 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 39 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 40 'manage_options', 41 'kgmdisablethumbnails', 42 [ $this, 'create_admin_page' ]48 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 49 esc_html__( 'Image Sizes', 'disable-thumbnails-and-threshold' ), 50 'manage_options', 51 'kgmdisablethumbnails', 52 array( $this, 'create_admin_page' ) 43 53 ); 44 54 } … … 51 61 */ 52 62 public function create_admin_page() { 53 // Check user capabilities for security 63 // Check user capabilities for security. 54 64 if ( ! current_user_can( 'manage_options' ) ) { 55 65 wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'disable-thumbnails-and-threshold' ) ); 56 66 } 57 58 // Use cached options to avoid database calls 67 68 // Use cached options to avoid database calls. 59 69 $this->dtat_disablethumbnails_options = $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION ); ?> 60 70 61 71 <div class="wrap"> 62 <h 2><?php echo esc_html__( 'Image Thumbnails', 'disable-thumbnails-and-threshold' ); ?></h2>72 <h1><?php echo esc_html__( 'Image Thumbnails', 'disable-thumbnails-and-threshold' ); ?></h1> 63 73 <p><strong><?php echo esc_html__( 'Remember you need to regenerate thumbnails for delete old thumbnails image already generated.', 'disable-thumbnails-and-threshold' ); ?></strong></p> 64 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/reg-thumb' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p>65 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https:// uskgm.it/WP-CLI-thumb-rgnrt' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p>74 <p><?php echo esc_html__( 'Plugin recommended for regenerate thumbnails', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://wordpress.org/plugins/regenerate-thumbnails/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Regenerate Thumbnails', 'disable-thumbnails-and-threshold' ); ?></a></p> 75 <p><?php echo esc_html__( 'WP-CLI media regeneration', 'disable-thumbnails-and-threshold' ); ?> -> <a href="<?php echo esc_url( 'https://developer.wordpress.org/cli/commands/media/regenerate/' ); ?>" target="_blank" rel="noopener"><?php echo esc_html__( 'Documentation', 'disable-thumbnails-and-threshold' ); ?></a></p> 66 76 <p><?php echo esc_html__( 'Flagged image sizes will be disabled.', 'disable-thumbnails-and-threshold' ); ?></p> 67 77 <?php settings_errors(); ?> … … 75 85 </form> 76 86 </div> 77 <?php } 87 <?php 88 } 78 89 79 90 /** … … 86 97 register_setting( 87 98 'kgmdisablethumbnails_option_group', 88 DTAT_THUMBNAILS_OPTION, 89 [ $this, 'sanitize' ]99 DTAT_THUMBNAILS_OPTION, 100 array( $this, 'sanitize' ) 90 101 ); 91 102 92 103 add_settings_section( 93 'kgmdisablethumbnails_setting_section', 94 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 95 [ $this, 'section_info' ],96 'kgmdisablethumbnails-admin' 104 'kgmdisablethumbnails_setting_section', 105 esc_html__( 'Settings', 'disable-thumbnails-and-threshold' ), 106 array( $this, 'section_info' ), 107 'kgmdisablethumbnails-admin' 97 108 ); 98 109 99 110 add_settings_field( 100 111 'thumbnail', 101 esc_html__( 'Thumbnail', 'disable-thumbnails-and-threshold' ), 102 [ $this, 'thumbnail_callback' ],103 'kgmdisablethumbnails-admin', 104 'kgmdisablethumbnails_setting_section' 112 esc_html__( 'Thumbnail', 'disable-thumbnails-and-threshold' ), 113 array( $this, 'thumbnail_callback' ), 114 'kgmdisablethumbnails-admin', 115 'kgmdisablethumbnails_setting_section' 105 116 ); 106 117 add_settings_field( 107 118 'medium', 108 esc_html__( 'Medium', 'disable-thumbnails-and-threshold' ), 109 [ $this, 'medium_callback' ],110 'kgmdisablethumbnails-admin', 111 'kgmdisablethumbnails_setting_section' 119 esc_html__( 'Medium', 'disable-thumbnails-and-threshold' ), 120 array( $this, 'medium_callback' ), 121 'kgmdisablethumbnails-admin', 122 'kgmdisablethumbnails_setting_section' 112 123 ); 113 124 add_settings_field( 114 125 'medium_large', 115 126 esc_html__( 'Medium Large', 'disable-thumbnails-and-threshold' ), 116 [ $this, 'medium_large_callback' ],117 'kgmdisablethumbnails-admin', 118 'kgmdisablethumbnails_setting_section' 119 ); 120 add_settings_field( 121 'large', 122 esc_html__( 'Large', 'disable-thumbnails-and-threshold' ), 123 [ $this, 'large_callback' ],124 'kgmdisablethumbnails-admin', 125 'kgmdisablethumbnails_setting_section' 127 array( $this, 'medium_large_callback' ), 128 'kgmdisablethumbnails-admin', 129 'kgmdisablethumbnails_setting_section' 130 ); 131 add_settings_field( 132 'large', 133 esc_html__( 'Large', 'disable-thumbnails-and-threshold' ), 134 array( $this, 'large_callback' ), 135 'kgmdisablethumbnails-admin', 136 'kgmdisablethumbnails_setting_section' 126 137 ); 127 138 128 139 $image_sizes = wp_get_additional_image_sizes(); 129 140 foreach ( $image_sizes as $key => $image_size ) { 130 if ( 1 === $image_size['crop']) {141 if ( ! empty( $image_size['crop'] ) ) { 131 142 $crop = esc_html__( 'cropped', 'disable-thumbnails-and-threshold' ); 132 143 } else { … … 135 146 add_settings_field( 136 147 $key, 137 esc_html( $key ) . '<br><small>(' . esc_attr( $image_size['width'] ) . 'x' . esc_attr( $image_size['height'] ) . ')</small><br><small>' . esc_html( $crop ) . '</small>',138 [ $this, 'ext_callback' ],148 esc_html( $key ) . '<br><small>(' . absint( $image_size['width'] ) . 'x' . absint( $image_size['height'] ) . ')</small><br><small>' . esc_html( $crop ) . '</small>', 149 array( $this, 'ext_callback' ), 139 150 'kgmdisablethumbnails-admin', 140 151 'kgmdisablethumbnails_setting_section', 141 [ 'name' => $key ]152 array( 'name' => $key ) 142 153 ); 143 154 } … … 147 158 * Sanitize and validate form input before saving. 148 159 * 149 * @since 0.1 150 * @param array $input Raw form input values. 160 * Runs on every update_option() of this option, not only on form submit, so it 161 * must not depend on the current user: options.php already enforces the nonce 162 * and the manage_options capability before saving. 163 * 164 * Each checkbox posts its own size name as value, so only "size => size" pairs 165 * for sizes registered on this site are kept. 166 * 167 * @since 0.1 168 * @param mixed $input Raw value; null when every checkbox is unchecked. 151 169 * @return array Sanitized values. 152 170 */ 153 public function sanitize( array $input ): array { 154 // Check user capabilities for security 155 if ( ! current_user_can( 'manage_options' ) ) { 156 return $GLOBALS['dtat_disablethumbnails_options'] ?? get_option( DTAT_THUMBNAILS_OPTION, [] ); 157 } 158 159 // Nonce is already verified by WordPress options.php handler via settings_fields(). 160 $sanitary_values = []; 161 162 if ( isset( $input['thumbnail'] ) ) { 163 $sanitary_values['thumbnail'] = sanitize_text_field( $input['thumbnail'] ); 164 } 165 if ( isset( $input['medium'] ) ) { 166 $sanitary_values['medium'] = sanitize_text_field( $input['medium'] ); 167 } 168 if ( isset( $input['medium_large'] ) ) { 169 $sanitary_values['medium_large'] = sanitize_text_field( $input['medium_large'] ); 170 } 171 if ( isset( $input['large'] ) ) { 172 $sanitary_values['large'] = sanitize_text_field( $input['large'] ); 173 } 174 175 $image_sizes = wp_get_additional_image_sizes(); 176 foreach ( $image_sizes as $key => $image_size ) { 177 if ( isset( $input[ $key ] ) ) { 178 $sanitary_values[ $key ] = sanitize_text_field( $input[ $key ] ); 171 public function sanitize( $input ): array { 172 if ( ! is_array( $input ) ) { 173 return array(); 174 } 175 176 $sanitary_values = array(); 177 $known_sizes = array_merge( 178 array( 'thumbnail', 'medium', 'medium_large', 'large' ), 179 array_keys( wp_get_additional_image_sizes() ) 180 ); 181 182 foreach ( $known_sizes as $size ) { 183 if ( isset( $input[ $size ] ) && sanitize_text_field( $input[ $size ] ) === (string) $size ) { 184 $sanitary_values[ $size ] = (string) $size; 179 185 } 180 186 } … … 190 196 */ 191 197 public function section_info() { 192 193 198 } 194 199 … … 203 208 '<label class="switch"><input type="checkbox" name="%s[thumbnail]" id="thumbnail" value="thumbnail" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 204 209 esc_attr( DTAT_THUMBNAILS_OPTION ), 205 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['thumbnail'] ) && $this->dtat_disablethumbnails_options['thumbnail'] === 'thumbnail') ? 'checked' : '',210 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['thumbnail'] ) && 'thumbnail' === $this->dtat_disablethumbnails_options['thumbnail'] ) ? 'checked' : '', 206 211 esc_html__( 'Disable Thumbnail size', 'disable-thumbnails-and-threshold' ) 207 212 ); … … 218 223 '<label class="switch"><input type="checkbox" name="%s[medium]" id="medium" value="medium" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 219 224 esc_attr( DTAT_THUMBNAILS_OPTION ), 220 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium'] ) && $this->dtat_disablethumbnails_options['medium'] === 'medium') ? 'checked' : '',225 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium'] ) && 'medium' === $this->dtat_disablethumbnails_options['medium'] ) ? 'checked' : '', 221 226 esc_html__( 'Disable Medium size', 'disable-thumbnails-and-threshold' ) 222 227 ); … … 233 238 '<label class="switch"><input type="checkbox" name="%s[medium_large]" id="medium_large" value="medium_large" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 234 239 esc_attr( DTAT_THUMBNAILS_OPTION ), 235 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium_large'] ) && $this->dtat_disablethumbnails_options['medium_large'] === 'medium_large') ? 'checked' : '',240 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['medium_large'] ) && 'medium_large' === $this->dtat_disablethumbnails_options['medium_large'] ) ? 'checked' : '', 236 241 esc_html__( 'Disable Medium Large size', 'disable-thumbnails-and-threshold' ) 237 242 ); … … 248 253 '<label class="switch"><input type="checkbox" name="%s[large]" id="large" value="large" %s><span class="screen-reader-text">%s</span><span class="slider" aria-hidden="true"></span></label>', 249 254 esc_attr( DTAT_THUMBNAILS_OPTION ), 250 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['large'] ) && $this->dtat_disablethumbnails_options['large'] === 'large') ? 'checked' : '',255 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options['large'] ) && 'large' === $this->dtat_disablethumbnails_options['large'] ) ? 'checked' : '', 251 256 esc_html__( 'Disable Large size', 'disable-thumbnails-and-threshold' ) 252 257 ); … … 268 273 esc_attr( $name ), 269 274 esc_attr( $name ), 270 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options[ $name] ) && $this->dtat_disablethumbnails_options[$name] === $name) ? 'checked' : '',275 ( is_array( $this->dtat_disablethumbnails_options ) && isset( $this->dtat_disablethumbnails_options[ $name ] ) && $name === $this->dtat_disablethumbnails_options[ $name ] ) ? 'checked' : '', 271 276 /* translators: %s: Image size name */ 272 277 esc_html( sprintf( __( 'Disable %s size', 'disable-thumbnails-and-threshold' ), $name ) ) 273 278 ); 274 279 } 275 276 280 } 277 281 if ( is_admin() ) { 278 $ DTAT_Disable_Thumbnails = new DTAT_Disable_Thumbnails();282 $dtat_disable_thumbnails = new DTAT_Disable_Thumbnails(); 279 283 } -
disable-thumbnails-and-threshold/trunk/readme.txt
r3504636 r3789337 3 3 Donate link: https://kgmservizi.com 4 4 Tags: thumbnails, disable thumbnails, disable threshold, disable images, image options 5 Requires at least: 5. 46 Tested up to: 6.87 Requires PHP: 7.48 Stable tag: 0. 7.05 Requires at least: 5.6 6 Tested up to: 7.1 7 Requires PHP: 8.0 8 Stable tag: 0.8.0 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 76 76 == Changelog == 77 77 78 = 0.8.0 = 79 * Requirements: minimum PHP raised to 8.0 and minimum WordPress to 5.6 (the first release with PHP 8.0 support). 80 * Fix: saving the Image Sizes page with every size unchecked caused a fatal error. 81 * Fix: settings saved through WP-CLI were silently discarded. 82 * Fix: the "cropped" label now appears for custom image sizes registered with cropping. 83 * Fix: no fatal error when another plugin hooks `jpeg_quality` or `big_image_size_threshold` with required extra arguments. 84 * Coding standards cleanup. 85 78 86 = 0.7.0 = 79 87 * Improved accessibility: toggle switches are now fully keyboard-navigable with visible focus indicators and screen-reader labels. … … 98 106 == Upgrade Notice == 99 107 108 = 0.8.0 = 109 Requires PHP 8.0+ and WordPress 5.6+. Fixes a fatal error when unchecking every image size. 110 100 111 = 0.7.0 = 101 112 Accessibility, compatibility and performance improvements. No breaking changes — all settings and URLs are preserved. Recommended update for all users.
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)