Skip to content

Commit

Permalink
Make some optimization in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-mykhailenko committed Sep 21, 2022
1 parent 095851a commit ca9c568
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion includes/lists-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
2 changes: 1 addition & 1 deletion includes/options-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 3 additions & 5 deletions includes/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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
?>
Expand Down
21 changes: 19 additions & 2 deletions mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,6 +39,11 @@
*/
class Mailgun
{
/**
* @var Mailgun $instance
*/
private static $instance;

/**
* @var false|mixed|null
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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']);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ca9c568

Please sign in to comment.