PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.13
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.13
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
imagify / inc / classes / class-imagify-data.php

class-imagify-data.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.9.13, at inc/classes/class-imagify-data.php

104 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
3
4 /**
5 * Class that handles the plugin data.
6 *
7 * @since 1.7
8 */
9 class Imagify_Data extends Imagify_Abstract_Options {
10
11 /**
12 * Class version.
13 *
14 * @var string
15 * @since 1.7
16 */
17 const VERSION = '1.0';
18
19 /**
20 * Suffix used in the name of the option.
21 *
22 * @var string
23 * @since 1.7
24 * @access protected
25 */
26 protected $identifier = 'data';
27
28 /**
29 * The default values for the Imagify main options.
30 * These are the "zero state" values.
31 * Don't use null as value.
32 *
33 * @var array
34 * @since 1.7
35 * @access protected
36 */
37 protected $default_values = array(
38 'total_size_images_library' => 0.0,
39 'average_size_images_per_month' => 0.0,
40 'previous_quota_percent' => 0.0,
41 );
42
43 /**
44 * The single instance of the class.
45 *
46 * @var object
47 * @since 1.7
48 * @access protected
49 */
50 protected static $_instance;
51
52 /**
53 * Get the main Instance.
54 *
55 * @since 1.7
56 * @author Grégory Viguier
57 * @access public
58 *
59 * @return object Main instance.
60 */
61 public static function get_instance() {
62 if ( ! isset( self::$_instance ) ) {
63 self::$_instance = new self();
64 }
65
66 return self::$_instance;
67 }
68
69
70 /** ----------------------------------------------------------------------------------------- */
71 /** SANITIZATION, VALIDATION ================================================================ */
72 /** ----------------------------------------------------------------------------------------- */
73
74 /**
75 * Sanitize and validate an option value. Basic casts have been made.
76 *
77 * @since 1.7
78 * @author Grégory Viguier
79 * @access public
80 *
81 * @param string $key The option key.
82 * @param mixed $value The value.
83 * @param mixed $default The default value.
84 * @return mixed
85 */
86 public function sanitize_and_validate_value( $key, $value, $default ) {
87 switch ( $key ) {
88 case 'total_size_images_library':
89 case 'average_size_images_per_month':
90 if ( $value <= 0 ) {
91 // Invalid.
92 return 0.0;
93 }
94 return $value;
95
96 case 'previous_quota_percent':
97 $value = round( $value, 1 );
98 return min( max( 0, $value ), 100 );
99 }
100
101 return false;
102 }
103 }
104