PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.3.5.1
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.3.5.1
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-user.php

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

201 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 class Imagify_User {
5 /**
6 * The Imagify user ID
7 *
8 * @since 1.0
9 *
10 * @var string
11 * @access public
12 */
13 public $id;
14
15 /**
16 * The user email
17 *
18 * @since 1.0
19 *
20 * @var string
21 * @access public
22 */
23 public $email;
24
25 /**
26 * The plan ID
27 *
28 * @since 1.0
29 *
30 * @var int
31 * @access public
32 */
33 public $plan_id;
34
35 /**
36 * The plan label
37 *
38 * @since 1.2
39 *
40 * @var string
41 * @access public
42 */
43 public $plan_label;
44
45 /**
46 * The total quota
47 *
48 * @since 1.0
49 *
50 * @var int
51 * @access public
52 */
53 public $quota;
54
55 /**
56 * The total extra quota (Imagify Pack)
57 *
58 * @since 1.0
59 *
60 * @var int
61 * @access public
62 */
63 public $extra_quota;
64
65 /**
66 * The extra quota consumed
67 *
68 * @since 1.0
69 *
70 * @var int
71 * @access public
72 */
73 public $extra_quota_consumed;
74
75 /**
76 * The current month consumed quota
77 *
78 * @since 1.0
79 *
80 * @var int
81 * @access public
82 */
83 public $consumed_current_month_quota;
84
85 /**
86 * The next month date to credit the account
87 *
88 * @since 1.1.1
89 *
90 * @var date
91 * @access public
92 */
93 public $next_date_update;
94
95 /**
96 * If the account is activate or not
97 *
98 * @since 1.0.1
99 *
100 * @var bool
101 * @access public
102 */
103 public $is_active;
104
105 /**
106 * The constructor
107 *
108 * @since 1.0
109 *
110 * @return void
111 **/
112 public function __construct() {
113 $user = get_imagify_user();
114
115 if ( ! is_wp_error( $user ) ) {
116 $this->id = $user->id;
117 $this->email = $user->email;
118 $this->plan_id = $user->plan_id;
119 $this->plan_label = ucfirst( $user->plan_label );
120 $this->quota = $user->quota;
121 $this->extra_quota = $user->extra_quota;
122 $this->extra_quota_consumed = $user->extra_quota_consumed;
123 $this->consumed_current_month_quota = $user->consumed_current_month_quota;
124 $this->next_date_update = $user->next_date_update;
125 $this->is_active = $user->is_active;
126 }
127 }
128
129 /**
130 * Count percent of consumed quota.
131 *
132 * @since 1.0
133 *
134 * @access public
135 * @return int
136 */
137 public function get_percent_consumed_quota() {
138 $percent = 0;
139 $quota = $this->quota;
140 $consumed_quota = $this->consumed_current_month_quota;
141
142 if ( ( $this->quota + $this->extra_quota ) - ( $this->consumed_current_month_quota + $this->extra_quota_consumed ) <= 0 ) {
143 return 100;
144 }
145
146 if( imagify_round_half_five( $this->extra_quota_consumed ) < $this->extra_quota ) {
147 $quota = $this->extra_quota + $quota;
148 $consumed_quota = $consumed_quota + $this->extra_quota_consumed;
149 }
150
151 $percent = 100 - ( ( $quota - $consumed_quota ) / $quota ) * 100;
152 $percent = min ( round( $percent, 1 ), 100 );
153
154 return $percent;
155 }
156
157 /**
158 * Count percent of unconsumed quota.
159 *
160 * @since 1.0
161 *
162 * @access public
163 * @return int
164 */
165 public function get_percent_unconsumed_quota() {
166 $percent = 100 - $this->get_percent_consumed_quota();
167 return $percent;
168 }
169
170 /**
171 * Check if the user has a free account.
172 *
173 * @since 1.1.1
174 *
175 * @access public
176 * @return bool
177 */
178 public function is_free() {
179 if ( 1 == $this->plan_id ) {
180 return true;
181 }
182
183 return false;
184 }
185
186 /**
187 * Check if the user has consumed its quota.
188 *
189 * @since 1.1.1
190 *
191 * @access public
192 * @return bool
193 */
194 public function is_over_quota() {
195 if ( $this->is_free() && 100 == $this->get_percent_consumed_quota() ) {
196 return true;
197 }
198
199 return false;
200 }
201 }