PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.11
Boxzilla – WordPress Popup Builder v3.4.11
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
← All changes | src/licensing/class-poller.php +29 -16 3.1.173.4.11 View file →
@@ -1,10 +1,16 @@
1 1 <?php
2 2
3 3 namespace Boxzilla\Licensing;
4 4
5 -class Poller {
5 +if (! defined('ABSPATH')) {
6 + exit;
7 +}
6 8
9 +class Poller
10 +{
11 + public const HOOK = 'boxzilla_check_license_status';
12 +
7 13 /**
8 14 * @var API
9 15 */
10 16 protected $api;
@@ -19,10 +25,11 @@
19 25 *
20 26 * @param API $api
21 27 * @param License $license
22 28 */
23 - public function __construct( API $api, License $license ) {
24 - $this->api = $api;
29 + public function __construct(API $api, License $license)
30 + {
31 + $this->api = $api;
25 32 $this->license = $license;
26 33 }
27 34
28 35 /**
@@ -27,22 +34,29 @@
27 34
28 35 /**
29 36 * Add hooks.
30 37 */
31 - public function hook() {
32 - if( ! wp_next_scheduled( 'boxzilla_check_license_status' ) ) {
33 - wp_schedule_event( time(), 'daily', 'boxzilla_check_license_status' );
34 - };
38 + public function init()
39 + {
40 + if (! wp_next_scheduled(self::HOOK)) {
41 + wp_schedule_event(time(), 'daily', self::HOOK);
42 + }
35 43
36 - add_action( 'boxzilla_check_license_status', array( $this, 'run' ) );
44 + add_action(self::HOOK, [ $this, 'run' ]);
37 45 }
38 46
47 + public static function deactivate()
48 + {
49 + wp_clear_scheduled_hook(self::HOOK);
50 + }
51 +
39 52 /**
40 53 * Run!
41 54 */
42 - public function run() {
55 + public function run()
56 + {
43 57 // don't run if license not active
44 - if( ! $this->license->activated ) {
58 + if (! $this->license->activated) {
45 59 return;
46 60 }
47 61
48 62 // assume valid by default, in case of server errors on our side.
@@ -48,20 +62,19 @@
48 62 // assume valid by default, in case of server errors on our side.
49 63 $license_still_valid = true;
50 64
51 65 try {
52 - $remote_license = $this->api->get_license();
66 + $remote_license = $this->api->get_license();
53 67 $license_still_valid = $remote_license->valid;
54 - } catch( API_Exception $e ) {
68 + } catch (API_Exception $e) {
55 69 // license key wasn't found or expired
56 - if( in_array( $e->getApiCode(), array( 'license_invalid', 'license_expired' ) ) ) {
70 + if (in_array($e->getApiCode(), [ 'license_invalid', 'license_expired' ], true)) {
57 71 $license_still_valid = false;
58 72 }
59 73 }
60 74
61 - if( ! $license_still_valid ) {
75 + if (! $license_still_valid) {
62 76 $this->license->activated = false;
63 77 $this->license->save();
64 78 }
65 -
66 79 }
67 -}
80 +}