summaryrefslogtreecommitdiff
path: root/Postman/Extensions/License
diff options
context:
space:
mode:
authoryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2020-08-11 20:24:30 +0000
committeryehudah <yehudah@b8457f37-d9ea-0310-8a92-e5e31aec5664>2020-08-11 20:24:30 +0000
commitdf4cdf1cbae42de7b279f474e2b27fa719a90429 (patch)
tree9bdf52d80241502ab7f7b1f81240eb83b8df0be4 /Postman/Extensions/License
parent53b2035def91dc0fe6d8f68e4a34aca2acc79ec8 (diff)
downloadPost-SMTP-df4cdf1cbae42de7b279f474e2b27fa719a90429.zip
* Fixed: WordPress 5.5 compatibility
* Fixed: Email log filtering * Fixed: Pushover notifications * New: Suggest solution for email delivery errors
Diffstat (limited to 'Postman/Extensions/License')
-rw-r--r--Postman/Extensions/License/PostmanLicenseHandler.php55
-rw-r--r--Postman/Extensions/License/PostmanLicenseManager.php4
2 files changed, 51 insertions, 8 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' );
}
diff --git a/Postman/Extensions/License/PostmanLicenseManager.php b/Postman/Extensions/License/PostmanLicenseManager.php
index cb10852..a25f092 100644
--- a/Postman/Extensions/License/PostmanLicenseManager.php
+++ b/Postman/Extensions/License/PostmanLicenseManager.php
@@ -3,7 +3,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
class PostmanLicenseManager {
- const ENDPOINT = 'https://postmansmtp.com';
+ const ENDPOINT = 'https://postmansmtpcom-staging.dxpsites.net';
const CORE_EXTENSIONS = [ 'gmail_api', 'sendgrid_api', 'mandrill_api', 'mailgun_api' ];
@@ -97,4 +97,4 @@ class PostmanLicenseManager {
public function get_extensions() {
return $this->extensions;
}
-}
+} \ No newline at end of file