PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
← All changes | inc/classes/class-imagify-abstract-options.php +36 -61 1.10 → trunk View file →
@@ -1,6 +1,5 @@
1 1 <?php
2 -defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3 2
4 3 /**
5 4 * Abstract class to handle a part of the plugin options.
6 5 *
@@ -6,9 +5,8 @@
6 5 *
7 6 * @since 1.7
8 7 */
9 8 abstract class Imagify_Abstract_Options {
10 -
11 9 /**
12 10 * Class version.
13 11 *
14 12 * @var string
@@ -43,9 +41,9 @@
43 41 * @var array
44 42 * @since 1.7
45 43 * @access protected
46 44 */
47 - protected $reset_values = array();
45 + protected $reset_values = [];
48 46
49 47 /**
50 48 * Tell if the option should be autoloaded by WP.
51 49 * Possible values are 'yes' and 'no'.
@@ -74,17 +72,8 @@
74 72 */
75 73 private $hook_identifier;
76 74
77 75 /**
78 - * The single instance of the class.
79 - *
80 - * @var object
81 - * @since 1.7
82 - * @access protected
83 - */
84 - protected static $_instance;
85 -
86 - /**
87 76 * The constructor.
88 77 *
89 78 * @since 1.7
90 79 * @author Grégory Viguier
@@ -96,31 +85,17 @@
96 85 if ( ! is_string( $this->autoload ) ) {
97 86 $this->autoload = $this->autoload ? 'yes' : 'no';
98 87 }
99 88
100 - $this->default_values = array_merge( array(
101 - 'version' => '',
102 - ), $this->default_values );
89 + $this->default_values = array_merge(
90 + [
91 + 'version' => '',
92 + ],
93 + $this->default_values
94 + );
103 95 }
104 96
105 97 /**
106 - * Get the main Instance.
107 - *
108 - * @since 1.7
109 - * @author Grégory Viguier
110 - * @access public
111 - *
112 - * @return object Main instance.
113 - */
114 - public static function get_instance() {
115 - if ( ! isset( self::$_instance ) ) {
116 - self::$_instance = new self();
117 - }
118 -
119 - return self::$_instance;
120 - }
121 -
122 - /**
123 98 * Launch the hooks.
124 99 *
125 100 * @since 1.7
126 101 * @author Grégory Viguier
@@ -126,9 +101,9 @@
126 101 * @author Grégory Viguier
127 102 * @access public
128 103 */
129 104 public function init() {
130 - add_filter( 'sanitize_option_' . $this->get_option_name(), array( $this, 'sanitize_and_validate_on_update' ), 50 );
105 + add_filter( 'sanitize_option_' . $this->get_option_name(), [ $this, 'sanitize_and_validate_on_update' ], 50 );
131 106 }
132 107
133 108
134 109 /** ----------------------------------------------------------------------------------------- */
@@ -216,9 +191,9 @@
216 191 public function set( $values ) {
217 192 $args = func_get_args();
218 193
219 194 if ( isset( $args[1] ) && is_string( $args[0] ) ) {
220 - $values = array( $args[0] => $args[1] );
195 + $values = [ $args[0] => $args[1] ];
221 196 }
222 197
223 198 if ( ! is_array( $values ) ) {
224 199 // PABKAC.
@@ -339,9 +314,9 @@
339 314 public function get_raw() {
340 315 $values = $this->is_network_option() ? get_site_option( $this->get_option_name() ) : get_option( $this->get_option_name() );
341 316
342 317 if ( false !== $values && ! is_array( $values ) ) {
343 - return array();
318 + return [];
344 319 }
345 320
346 321 return $values;
347 322 }
@@ -414,10 +389,10 @@
414 389 *
415 390 * @param array $new_values New default option values.
416 391 * @param array $default_values Plugin default option values.
417 392 */
418 - $new_values = apply_filters( 'imagify_default_' . $this->get_hook_identifier() . '_values', array(), $default_values );
419 - $new_values = is_array( $new_values ) ? $new_values : array();
393 + $new_values = apply_filters( 'imagify_default_' . $this->get_hook_identifier() . '_values', [], $default_values );
394 + $new_values = is_array( $new_values ) ? $new_values : [];
420 395
421 396 if ( $new_values ) {
422 397 // Don't allow new values to overwrite the plugin values.
423 398 $new_values = array_diff_key( $new_values, $default_values );
@@ -466,9 +441,9 @@
466 441 if ( $new_values && is_array( $new_values ) ) {
467 442 $reset_values = array_merge( $reset_values, $new_values );
468 443 }
469 444
470 - $this->reset_values = $reset_values;
445 + $this->reset_values = $reset_values;
471 446 $this->reset_values['cached'] = 1;
472 447
473 448 return $reset_values;
474 449 }
@@ -486,21 +461,21 @@
486 461 * @access public
487 462 *
488 463 * @param string $key The option key.
489 464 * @param mixed $value The value.
490 - * @param mixed $default The default value.
465 + * @param mixed $default_value The default value.
491 466 * @return mixed
492 467 */
493 - public function sanitize_and_validate( $key, $value, $default = null ) {
494 - if ( ! isset( $default ) ) {
468 + public function sanitize_and_validate( $key, $value, $default_value = null ) {
469 + if ( ! isset( $default_value ) ) {
495 470 $default_values = $this->get_default_values();
496 - $default = $default_values[ $key ];
471 + $default_value = $default_values[ $key ];
497 472 }
498 473
499 474 // Cast the value.
500 - $value = self::cast( $value, $default );
475 + $value = self::cast( $value, $default_value );
501 476
502 - if ( $value === $default ) {
477 + if ( $value === $default_value ) {
503 478 return $value;
504 479 }
505 480
506 481 // Version.
@@ -507,9 +482,9 @@
507 482 if ( 'version' === $key ) {
508 483 return sanitize_text_field( $value );
509 484 }
510 485
511 - return $this->sanitize_and_validate_value( $key, $value, $default );
486 + return $this->sanitize_and_validate_value( $key, $value, $default_value );
512 487 }
513 488
514 489 /**
515 490 * Sanitize and validate an option value. Basic casts have been made.
@@ -517,14 +492,14 @@
517 492 * @since 1.7
518 493 * @author Grégory Viguier
519 494 * @access public
520 495 *
521 - * @param string $key The option key.
522 - * @param mixed $value The value.
523 - * @param mixed $default The default value.
496 + * @param string $key The option key.
497 + * @param mixed $value The value.
498 + * @param mixed $default_value The default value.
524 499 * @return mixed
525 500 */
526 - abstract public function sanitize_and_validate_value( $key, $value, $default );
501 + abstract public function sanitize_and_validate_value( $key, $value, $default_value );
527 502
528 503 /**
529 504 * Sanitize and validate Imagify's options before storing them.
530 505 *
@@ -535,9 +510,9 @@
535 510 * @param string $values The option value.
536 511 * @return array
537 512 */
538 513 public function sanitize_and_validate_on_update( $values ) {
539 - $values = is_array( $values ) ? $values : array();
514 + $values = is_array( $values ) ? $values : [];
540 515 $default_values = $this->get_default_values();
541 516
542 517 if ( $values ) {
543 518 foreach ( $default_values as $key => $default ) {
@@ -582,26 +557,26 @@
582 557 * @since 1.7
583 558 * @author Grégory Viguier
584 559 * @access public
585 560 *
586 - * @param mixed $value The value to cast.
587 - * @param mixed $default The default value.
561 + * @param mixed $value The value to cast.
562 + * @param mixed $default_value The default value.
588 563 * @return mixed
589 564 */
590 - public static function cast( $value, $default ) {
591 - if ( is_array( $default ) ) {
592 - return is_array( $value ) ? $value : array();
565 + public static function cast( $value, $default_value ) {
566 + if ( is_array( $default_value ) ) {
567 + return is_array( $value ) ? $value : [];
593 568 }
594 569
595 - if ( is_int( $default ) ) {
570 + if ( is_int( $default_value ) ) {
596 571 return (int) $value;
597 572 }
598 573
599 - if ( is_bool( $default ) ) {
574 + if ( is_bool( $default_value ) ) {
600 575 return (bool) $value;
601 576 }
602 577
603 - if ( is_float( $default ) ) {
578 + if ( is_float( $default_value ) ) {
604 579 return round( (float) $value, 3 );
605 580 }
606 581
607 582 return $value;
@@ -613,11 +588,11 @@
613 588 * @since 1.7
614 589 * @author Grégory Viguier
615 590 * @access public
616 591 *
617 - * @param float $float The float.
592 + * @param float $value The value.
618 593 * @return float|int
619 594 */
620 - public static function maybe_cast_float_as_int( $float ) {
621 - return ( $float / (int) $float ) === (float) 1 ? (int) $float : $float;
595 + public static function maybe_cast_float_as_int( $value ) {
596 + return ( $value / (int) $value ) === (float) 1 ? (int) $value : $value;
622 597 }
623 598 }