diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ff2a63..3491c34 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +1.8.5 (2022-09-21) +- Make code changes to have more optimized way to use Mailgun object in the code + 1.8.3 (2022-08-30) - Plugin refactoring. Widget fixes for working with Legacy Widget Block. PHP8.0 support check diff --git a/includes/admin.php b/includes/admin.php index c465cb2..c0499f6 100755 --- a/includes/admin.php +++ b/includes/admin.php @@ -465,7 +465,7 @@ public function ajax_send_test() } // Error message will always be returned in case of failure, if not - connection wasn't successful - $error_msg = $error_msg ? $error_msg : "Can't connect to Mailgun"; + $error_msg = $error_msg ?: "Can't connect to Mailgun"; die( json_encode(array( 'message' => __('Failure', 'mailgun'), diff --git a/includes/lists-page.php b/includes/lists-page.php index 7062aa4..1ca4dea 100644 --- a/includes/lists-page.php +++ b/includes/lists-page.php @@ -19,7 +19,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -global $mailgun; +$mailgun = Mailgun::getInstance(); // check mailgun domain & api key $missing_error = ''; diff --git a/includes/options-page.php b/includes/options-page.php index 3f0c1fc..b6ee2fe 100755 --- a/includes/options-page.php +++ b/includes/options-page.php @@ -19,7 +19,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -global $mailgun; +$mailgun = Mailgun::getInstance(); $mailgun_domain_const = ((defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : null); $mailgun_domain = $mailgun_domain_const ?: $this->get_option('domain'); diff --git a/includes/widget.php b/includes/widget.php index c74bba7..af56dfa 100644 --- a/includes/widget.php +++ b/includes/widget.php @@ -37,7 +37,7 @@ public function __construct() // This is where the action happens public function widget($args, $instance) { - global $mailgun; + $mailgun = Mailgun::getInstance(); if (!isset($instance['list_address']) || !$instance['list_address']) { return; @@ -63,8 +63,6 @@ public function widget($args, $instance) // Widget Backend public function form($instance) { - global $mailgun; - if (isset($instance['list_address'])) { $list_address = $instance['list_address']; } else { @@ -77,8 +75,8 @@ public function form($instance) $collect_name = ''; } - $list_title = isset($instance['list_title']) ? $instance['list_title'] : null; - $list_description = isset($instance['list_description']) ? $instance['list_description'] : null; + $list_title = $instance['list_title'] ?? null; + $list_description = $instance['list_description'] ?? null; // Widget admin form ?> diff --git a/mailgun.php b/mailgun.php index 4621981..0aedbe3 100755 --- a/mailgun.php +++ b/mailgun.php @@ -3,7 +3,7 @@ * Plugin Name: Mailgun * Plugin URI: http://wordpress.org/extend/plugins/mailgun/ * Description: Mailgun integration for WordPress - * Version: 1.8.4 + * Version: 1.8.5 * Author: Mailgun * Author URI: http://www.mailgun.com/ * License: GPLv2 or later @@ -39,6 +39,11 @@ */ class Mailgun { + /** + * @var Mailgun $instance + */ + private static $instance; + /** * @var false|mixed|null */ @@ -93,6 +98,18 @@ public function __construct() } } + /** + * @return static + */ + public static function getInstance() + { + if (!isset(self::$instance)) { + self::$instance = new self(); + } + + return self::$instance; + } + /** * Get specific option from the options table. * @@ -506,7 +523,7 @@ public function getAssetsPath(): string } } -$mailgun = new Mailgun(); +$mailgun = Mailgun::getInstance(); if (@include __DIR__ . '/includes/widget.php') { add_action('widgets_init', [&$mailgun, 'load_list_widget']); diff --git a/readme.md b/readme.md index 6e41111..d04b635 100755 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 3.3 Tested up to: 6.0.1 -Stable tag: 1.8.4 +Stable tag: 1.8.5 License: GPLv2 or later diff --git a/readme.txt b/readme.txt index e6536e1..f2eafe5 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 3.3 Tested up to: 6.0.1 -Stable tag: 1.8.4 +Stable tag: 1.8.5 License: GPLv2 or later