PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.13
Boxzilla – WordPress Popup Builder v3.2.13
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / src / licensing / class-poller.php

class-poller.php in Boxzilla – WordPress Popup Builder 3.2.13, at src/licensing/class-poller.php

71 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Boxzilla\Licensing;
4
5 class Poller
6 {
7
8 /**
9 * @var API
10 */
11 protected $api;
12
13 /**
14 * @var License
15 */
16 protected $license;
17
18 /**
19 * Poller constructor.
20 *
21 * @param API $api
22 * @param License $license
23 */
24 public function __construct(API $api, License $license)
25 {
26 $this->api = $api;
27 $this->license = $license;
28 }
29
30 /**
31 * Add hooks.
32 */
33 public function hook()
34 {
35 if (! wp_next_scheduled('boxzilla_check_license_status')) {
36 wp_schedule_event(time(), 'daily', 'boxzilla_check_license_status');
37 };
38
39 add_action('boxzilla_check_license_status', array( $this, 'run' ));
40 }
41
42 /**
43 * Run!
44 */
45 public function run()
46 {
47 // don't run if license not active
48 if (! $this->license->activated) {
49 return;
50 }
51
52 // assume valid by default, in case of server errors on our side.
53 $license_still_valid = true;
54
55 try {
56 $remote_license = $this->api->get_license();
57 $license_still_valid = $remote_license->valid;
58 } catch (API_Exception $e) {
59 // license key wasn't found or expired
60 if (in_array($e->getApiCode(), array( 'license_invalid', 'license_expired' ))) {
61 $license_still_valid = false;
62 }
63 }
64
65 if (! $license_still_valid) {
66 $this->license->activated = false;
67 $this->license->save();
68 }
69 }
70 }
71