PluginProbe
Patchstack – WordPress & Plugins Security / 2.3.4
Patchstack – WordPress & Plugins Security v2.3.4
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/api.php +4 -39 trunk2.3.4 View file →
@@ -149,9 +149,8 @@
149 149 // We need to know when the token expires.
150 150 // Defer to 'expires' if it is provided instead.
151 151 if ( isset( $result->expires_in ) ) {
152 152 if ( ! is_numeric( $result->expires_in ) ) {
153 - $response_data->result = 'failed';
154 153 $response_data->message = 'expires_in value must be an integer';
155 154 return $response_data;
156 155 }
157 156 $response_data->expiresin = $result->expires_in != 0 ? time() + $result->expires_in : 0;
@@ -218,13 +217,8 @@
218 217
219 218 return wp_remote_retrieve_response_code( $response );
220 219 }
221 220
222 - // A 200 OK means we successfully communicated with the API for this sync
223 - // action (license verify, log/software upload, rule pull, ping, etc.), so
224 - // record it as the last successful sync time.
225 - $this->update_blog_option( $this->blog_id, 'patchstack_last_sync', time() );
226 -
227 221 return json_decode( wp_remote_retrieve_body( $response ), true );
228 222 }
229 223
230 224 /**
@@ -233,12 +227,8 @@
233 227 * @param integer $expiresin API token expiry.
234 228 * @return boolean If the token has expired.
235 229 */
236 230 public function has_expired( $expiresin ) {
237 - // A stored expiry of 0 means the token never expires.
238 - if ( $expiresin === 0 ) {
239 - return false;
240 - }
241 231 return ( $expiresin < ( time() + 30 ) );
242 232 }
243 233
244 234 /**
@@ -243,14 +233,13 @@
243 233
244 234 /**
245 235 * Retrieve the status of a license.
246 236 *
247 - * @param boolean $fetchPolicy Whether or not to fetch the policy settings.
248 237 * @return void|array
249 238 */
250 - public function update_license_status($fetchPolicy = false) {
239 + public function update_license_status() {
251 240 // Get current license status.
252 - $response = $this->send_request( '/api/license/verify' . ($fetchPolicy ? '?fetchPolicy=true' : ''), 'GET' );
241 + $response = $this->send_request( '/api/license/verify', 'GET' );
253 242
254 243 // Invalid license, or no longer active.
255 244 if ( ! is_array( $response ) && $response == 422 ) {
256 245 $this->update_blog_option( $this->blog_id, 'patchstack_clientid', '' );
@@ -260,14 +249,12 @@
260 249 return;
261 250 }
262 251
263 252 // Update the representing options.
264 - // Expiry date.
265 253 if ( isset( $response['expires_at'] ) ) {
266 254 $this->update_blog_option( $this->blog_id, 'patchstack_license_expiry', $response['expires_at'] );
267 255 }
268 256
269 - // Free vs Paid license.
270 257 if ( isset( $response['free'] ) ) {
271 258 $this->update_blog_option( $this->blog_id, 'patchstack_license_free', $response['free'] == false ? 0 : 1 );
272 259
273 260 if ( $response['free'] == true ) {
@@ -277,46 +264,24 @@
277 264 $this->send_header_request();
278 265 }
279 266 }
280 267
281 - // Active subscription.
282 268 if ( isset( $response['active'] ) ) {
283 - $this->update_blog_option( $this->blog_id, 'patchstack_license_activated', $response['active'] == true ? 1 : 0 );
269 + $this->update_blog_option( $this->blog_id, 'patchstack_license_activated', $response['active'] == true );
284 270 }
285 271
286 - // Subscription class.
287 272 if ( isset( $response['class'] ) ) {
288 273 $this->update_blog_option( $this->blog_id, 'patchstack_subscription_class', $response['class'] );
289 274 $this->update_blog_option( $this->blog_id, 'patchstack_last_license_check', time() );
290 275 }
291 276
292 - // Managed site status.
293 277 if ( isset( $response['managed'], $response['managed_string'] ) ) {
294 - $this->update_blog_option( $this->blog_id, 'patchstack_managed', $response['managed'] ? 1 : 0 );
278 + $this->update_blog_option( $this->blog_id, 'patchstack_managed', $response['managed'] );
295 279 $this->update_blog_option( $this->blog_id, 'patchstack_managed_text', $response['managed_string'] );
296 280 }
297 281
298 - // Site ID.
299 282 if ( isset( $response['site_id'] ) ) {
300 283 $this->update_blog_option( $this->blog_id, 'patchstack_site_id', $response['site_id'] );
301 - }
302 -
303 - // Policy settings.
304 - if ( isset( $response['policy'] ) && is_array( $response['policy'] ) && count( $response['policy'] ) > 0 ) {
305 - foreach ( $response['policy'] as $key => $value ) {
306 - // Make sure the option exists.
307 - if ( ! array_key_exists( $key, $this->plugin->admin_options->options ) ) {
308 - continue;
309 - }
310 -
311 - // Booleans would persist as '1' / '' otherwise, store them as 1/0 so type checks behave consistently.
312 - if ( is_bool( $value ) ) {
313 - $value = $value ? 1 : 0;
314 - }
315 -
316 - // Update the option.
317 - $this->update_blog_option( $this->blog_id, $key, $value );
318 - }
319 284 }
320 285
321 286 return $response;
322 287 }