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