From df4cdf1cbae42de7b279f474e2b27fa719a90429 Mon Sep 17 00:00:00 2001 From: yehudah Date: Tue, 11 Aug 2020 20:24:30 +0000 Subject: * Fixed: WordPress 5.5 compatibility * Fixed: Email log filtering * Fixed: Pushover notifications * New: Suggest solution for email delivery errors --- Postman/Extensions/Admin/PostmanAdminView.php | 4 + .../Core/Notifications/PostmanPushoverNotify.php | 2 +- .../Core/Notifications/PostmanSlackNotify.php | 2 +- .../Extensions/License/PostmanLicenseHandler.php | 55 ++++++++-- .../Extensions/License/PostmanLicenseManager.php | 4 +- Postman/Phpmailer/PostsmtpMailer.php | 9 +- .../PostmanWelcomeController.php | 5 - .../PostmanEmailLogController.php | 6 ++ Postman/Postman-Mail/PostmanWooCommerce.php | 118 +++------------------ .../symfony/options-resolver/OptionsResolver.php | 6 +- Postman/PostmanInstaller.php | 3 +- postman-smtp.php | 4 +- readme.txt | 10 +- 13 files changed, 100 insertions(+), 128 deletions(-) diff --git a/Postman/Extensions/Admin/PostmanAdminView.php b/Postman/Extensions/Admin/PostmanAdminView.php index af66fcb..428ee17 100644 --- a/Postman/Extensions/Admin/PostmanAdminView.php +++ b/Postman/Extensions/Admin/PostmanAdminView.php @@ -75,6 +75,10 @@ + license === 'expired' ) : ?> + Renew License + + diff --git a/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php b/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php index c1f2661..bc1e95d 100644 --- a/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php +++ b/Postman/Extensions/Core/Notifications/PostmanPushoverNotify.php @@ -31,4 +31,4 @@ class PostmanPushoverNotify implements Postman_Notify { error_log( __CLASS__ . ': ' . print_r( $body, true ) ); } } -} +} \ No newline at end of file diff --git a/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php b/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php index 3e482a8..1da009a 100644 --- a/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php +++ b/Postman/Extensions/Core/Notifications/PostmanSlackNotify.php @@ -37,4 +37,4 @@ class PostmanSlackNotify implements Postman_Notify { error_log( __CLASS__ . ': ' . $message ); } } -} \ No newline at end of file +} 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 diff --git a/Postman/Phpmailer/PostsmtpMailer.php b/Postman/Phpmailer/PostsmtpMailer.php index c7587bb..91f5122 100644 --- a/Postman/Phpmailer/PostsmtpMailer.php +++ b/Postman/Phpmailer/PostsmtpMailer.php @@ -4,9 +4,14 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( ! class_exists( 'PHPMailer', false ) ) { - require_once ABSPATH . WPINC . '/class-phpmailer.php'; + require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; + require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; + require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; } +use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\Exception; + add_action('plugins_loaded', function() { global $phpmailer; @@ -120,7 +125,7 @@ class PostsmtpMailer extends PHPMailer { return $result; - } catch (phpmailerException $exc) { + } catch (Exception $exc) { $this->error = $exc; diff --git a/Postman/Postman-Controller/PostmanWelcomeController.php b/Postman/Postman-Controller/PostmanWelcomeController.php index e37d3e8..a7c62bf 100644 --- a/Postman/Postman-Controller/PostmanWelcomeController.php +++ b/Postman/Postman-Controller/PostmanWelcomeController.php @@ -189,11 +189,6 @@ class PostmanWelcomeController {