PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.2.9
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.2.9
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 2.2.9, at inc/classes/class-imagify-data.php

79 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Imagify\Traits\InstanceGetterTrait;
4
5 /**
6 * Class that handles the plugin data.
7 *
8 * @since 1.7
9 */
10 class Imagify_Data extends Imagify_Abstract_Options {
11 use InstanceGetterTrait;
12
13 /**
14 * Class version.
15 *
16 * @var string
17 * @since 1.7
18 */
19 const VERSION = '1.0';
20
21 /**
22 * Suffix used in the name of the option.
23 *
24 * @var string
25 * @since 1.7
26 * @access protected
27 */
28 protected $identifier = 'data';
29
30 /**
31 * The default values for the Imagify main options.
32 * These are the "zero state" values.
33 * Don't use null as value.
34 *
35 * @var array
36 * @since 1.7
37 * @access protected
38 */
39 protected $default_values = [
40 'total_size_images_library' => 0.0,
41 'average_size_images_per_month' => 0.0,
42 'previous_quota_percent' => 0.0,
43 ];
44
45 /** ----------------------------------------------------------------------------------------- */
46 /** SANITIZATION, VALIDATION ================================================================ */
47 /** ----------------------------------------------------------------------------------------- */
48
49 /**
50 * Sanitize and validate an option value. Basic casts have been made.
51 *
52 * @since 1.7
53 * @author Grégory Viguier
54 * @access public
55 *
56 * @param string $key The option key.
57 * @param mixed $value The value.
58 * @param mixed $default_value The default value.
59 * @return mixed
60 */
61 public function sanitize_and_validate_value( $key, $value, $default_value ) {
62 switch ( $key ) {
63 case 'total_size_images_library':
64 case 'average_size_images_per_month':
65 if ( $value <= 0 ) {
66 // Invalid.
67 return 0.0;
68 }
69 return $value;
70
71 case 'previous_quota_percent':
72 $value = round( $value, 1 );
73 return min( max( 0, $value ), 100 );
74 }
75
76 return false;
77 }
78 }
79