summaryrefslogtreecommitdiff
path: root/Postman/Extensions/License/PostmanLicenseHandler.php
diff options
context:
space:
mode:
Diffstat (limited to 'Postman/Extensions/License/PostmanLicenseHandler.php')
-rw-r--r--Postman/Extensions/License/PostmanLicenseHandler.php55
1 files changed, 49 insertions, 6 deletions
diff --git a/Postman/Extensions/License/PostmanLicenseHandler.php b/Postman/Extensions/License/PostmanLicenseHandler.php
index b24aa14..e144951 100644
--- a/Postman/Extensions/License/PostmanLicenseHandler.php
+++ b/Postman/Extensions/License/PostmanLicenseHandler.php
@@ -7,6 +7,9 @@ if ( ! class_exists( 'PostmanLicenseHandler' ) ) :
class PostmanLicenseHandler {
+
+ const DAYS_TO_ALERT = array( 30, 14, 7, 1);
+
private $file;
private $license;
private $license_data;
@@ -81,7 +84,6 @@ class PostmanLicenseHandler {
add_action( 'init', array( $this, 'cron' ), 20 );
- // Check that license is valid once per week
add_action( 'admin_init', array( $this, 'validate_license' ) );
// Updater
@@ -241,9 +243,9 @@ class PostmanLicenseHandler {
set_site_transient( 'update_plugins', null );
// Decode license data
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
- update_option( $this->item_shortname . '_license_active', $license_data );
+ update_option( $this->item_shortname . '_license_active', $this->license_data );
update_option( $this->item_shortname . '_license_key', $license );
$slug = plugin_basename($this->file);
@@ -307,7 +309,7 @@ class PostmanLicenseHandler {
}
// Decode the license data
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
delete_option( $this->item_shortname . '_license_active' );
delete_option( $this->item_shortname . '_license_key' );
@@ -323,6 +325,39 @@ class PostmanLicenseHandler {
set_transient( $this->item_shortname . '_cron', true, rand( 12, 48 ) * HOUR_IN_SECONDS );
}
+
+ $license_data = $this->license_data;
+
+ $datetime1 = new DateTime();
+ $datetime2 = new DateTime( $license_data->expires );
+
+ foreach ( self::DAYS_TO_ALERT as $day_to_alert ) {
+
+ $interval = $datetime1->diff($datetime2);
+ if( $interval->days == $day_to_alert ){
+ add_action( 'admin_notices', function () use ( $day_to_alert, $license_data ) {
+ echo $this->item_name . ' is about to expire in ' . $day_to_alert . ' days: ' . $license_data->expires;
+ });
+
+ return;
+ }
+
+ if ( $interval->days == 0 ) {
+ add_action( 'admin_notices', function () use ( $license_data ) {
+ echo $this->item_name . ' license expire today at: ' . $license_data->expires;
+ });
+
+ return;
+ }
+ }
+
+ if ( $license_data->activations_left == 0 ) {
+ add_action( 'admin_notices', function () use ( $license_data ) {
+ echo $this->item_name . ' has no activations';
+ });
+
+ return;
+ }
}
@@ -357,10 +392,18 @@ class PostmanLicenseHandler {
return false;
}
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
+ if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
+ return false;
+ }
+
+ $this->license_data = json_decode( wp_remote_retrieve_body( $response ) );
- update_option( $this->item_shortname . '_license_active', $license_data );
+ update_option( $this->item_shortname . '_license_active', $this->license_data );
+
+ }
+ private function get_license_data() {
+ return get_option( $this->item_shortname . '_license_active' );
}