Skip to content

Commit

Permalink
= 2.1.3 (2024-11-27): = (#195)
Browse files Browse the repository at this point in the history
-  Use password type for API Key field for hide it. Fix warning related co compact() method
  • Loading branch information
oleksandr-mykhailenko authored Nov 27, 2024
1 parent c18452f commit 1a9349d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changelog
=========

2.1.3 (2024-11-27)
- Use password type for API Key field for hide it. Fix warning related co compact() method

2.1.2 (2024-11-17)
- Fixed code. Removed line that try to connect not existing file. Fixed versions in the plugin

Expand Down
60 changes: 30 additions & 30 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public function admin_menu(): void
{
if (current_user_can('manage_options')) {
$this->hook_suffix = add_options_page(__('Mailgun', 'mailgun'), __('Mailgun', 'mailgun'),
'manage_options', 'mailgun', array(&$this, 'options_page'));
'manage_options', 'mailgun', [&$this, 'options_page']);
add_options_page(__('Mailgun Lists', 'mailgun'), __('Mailgun Lists', 'mailgun'), 'manage_options',
'mailgun-lists', array(&$this, 'lists_page'));
add_action("admin_print_scripts-{$this->hook_suffix}", array(&$this, 'admin_js'));
add_filter("plugin_action_links_{$this->plugin_basename}", array(&$this, 'filter_plugin_actions'));
add_action("admin_footer-{$this->hook_suffix}", array(&$this, 'admin_footer_js'));
'mailgun-lists', [&$this, 'lists_page']);
add_action("admin_print_scripts-{$this->hook_suffix}", [&$this, 'admin_js']);
add_filter("plugin_action_links_{$this->plugin_basename}", [&$this, 'filter_plugin_actions']);
add_action("admin_footer-{$this->hook_suffix}", [&$this, 'admin_footer_js']);
}
}

Expand All @@ -145,7 +145,7 @@ public function admin_js(): void
public function admin_footer_js(): void
{
?>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css" >
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<script type="text/javascript">

Expand Down Expand Up @@ -260,7 +260,7 @@ public function admin_init(): void
*/
public function register_settings(): void
{
register_setting('mailgun', 'mailgun', array(&$this, 'validation'));
register_setting('mailgun', 'mailgun', [&$this, 'validation']);
}

/**
Expand Down Expand Up @@ -337,7 +337,7 @@ public function admin_notices(): void
$apiKeyUndefined = (!$this->get_option('apiKey') && (!defined('MAILGUN_APIKEY') || !MAILGUN_APIKEY));
$apiActiveNotConfigured = ($this->get_option('useAPI') === '1' && ($apiRegionUndefined || $apiKeyUndefined));

if (isset($_SESSION) && (!isset($_SESSION['settings_turned_of']) || $_SESSION['settings_turned_of'] === false) && ($apiActiveNotConfigured || $smtpActiveNotConfigured) ) { ?>
if (isset($_SESSION) && (!isset($_SESSION['settings_turned_of']) || $_SESSION['settings_turned_of'] === false) && ($apiActiveNotConfigured || $smtpActiveNotConfigured)) { ?>
<div id='mailgun-warning' class='notice notice-warning is-dismissible'>
<p>
<?php
Expand All @@ -349,7 +349,7 @@ public function admin_notices(): void
?>
</p>
</div>
<?php $_SESSION['settings_turned_of'] = true; ?>
<?php $_SESSION['settings_turned_of'] = true; ?>
<?php } ?>

<?php
Expand Down Expand Up @@ -403,11 +403,11 @@ public function ajax_send_test()

if (!current_user_can('manage_options') || !wp_verify_nonce(sanitize_text_field($_GET['_wpnonce']))) {
die(
json_encode(array(
'message' => __('Unauthorized', 'mailgun'),
'method' => null,
'error' => __('Unauthorized', 'mailgun'),
), JSON_THROW_ON_ERROR)
json_encode([
'message' => __('Unauthorized', 'mailgun'),
'method' => null,
'error' => __('Unauthorized', 'mailgun'),
], JSON_THROW_ON_ERROR)
);
}

Expand Down Expand Up @@ -440,11 +440,11 @@ public function ajax_send_test()
$admin_email = get_option('admin_email');
if (!$admin_email) {
die(
json_encode(array(
'message' => __('Admin Email is empty', 'mailgun'),
'method' => $method,
'error' => __('Admin Email is empty', 'mailgun'),
), JSON_THROW_ON_ERROR)
json_encode([
'message' => __('Admin Email is empty', 'mailgun'),
'method' => $method,
'error' => __('Admin Email is empty', 'mailgun'),
], JSON_THROW_ON_ERROR)
);
}

Expand Down Expand Up @@ -482,7 +482,7 @@ public function ajax_send_test()
}

// Admin Email is used as 'to' parameter, but in case of 'Test Configuration' this message is not clear for the user, so replaced with more appropriate one
if (false !== strpos($error_msg, "'to'") && false !== strpos($error_msg, 'is not a valid')) {
if (str_contains($error_msg, "'to'") && str_contains($error_msg, 'is not a valid')) {
$error_msg = sprintf(
"Administration Email Address (%s) is not valid and can't be used for test, you can change it at General Setting page",
$admin_email
Expand All @@ -491,22 +491,22 @@ public function ajax_send_test()

if ($result) {
die(
json_encode(array(
'message' => __('Success', 'mailgun'),
'method' => $method,
'error' => __('Success', 'mailgun'),
), JSON_THROW_ON_ERROR)
json_encode([
'message' => __('Success', 'mailgun'),
'method' => $method,
'error' => __('Success', 'mailgun'),
], JSON_THROW_ON_ERROR)
);
}

// Error message will always be returned in case of failure, if not - connection wasn't successful
$error_msg = $error_msg ?: "Can't connect to Mailgun";
die(
json_encode(array(
'message' => __('Failure', 'mailgun'),
'method' => $method,
'error' => $error_msg,
), JSON_THROW_ON_ERROR)
json_encode([
'message' => __('Failure', 'mailgun'),
'method' => $method,
'error' => $error_msg,
], JSON_THROW_ON_ERROR)
);
}
}
6 changes: 2 additions & 4 deletions includes/mg-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ function mg_detect_from_address($from_addr_header = null): string
$mg_override_from = $mg_opts['override-from'] ?? null;
$mg_from_addr = $mg_opts['from-address'] ?? null;

$from_addr = null;

if ($mg_override_from && !is_null($mg_from_addr)) {
$from_addr = $mg_from_addr;
} elseif (!is_null($from_addr_header)) {
Expand Down Expand Up @@ -223,7 +221,7 @@ function mg_parse_headers($headers = []): array
// Does this header have a boundary?
if (false !== stripos($header, 'boundary=')) {
$parts = preg_split('/boundary=/i', trim($header));
$boundary = trim(str_replace(array('"', '\''), '', $parts[1]));
$boundary = trim(str_replace(['"', '\''], '', $parts[1]));
}
$value .= $header;

Expand Down Expand Up @@ -271,7 +269,7 @@ function mg_dump_headers($headers = null): string
$header_string = '';
foreach ($headers as $name => $values) {
$header_string .= sprintf("%s: ", $name);
$header_values = array();
$header_values = [];

foreach ($values as $content) {
// XXX - Is it actually okay to discard `parts` and `boundary`?
Expand Down
30 changes: 15 additions & 15 deletions includes/options-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@
$link = sprintf(
wp_kses(
__('A <a href="%1$s" target="%2$s">Mailgun</a> account is required to use this plugin and the Mailgun service.', 'mailgun'),
array('a' => array(
'href' => array(),
'target' => array()
)
)
['a' => [
'href' => [],
'target' => []
]
]
), esc_url($url), '_blank'
);
echo wp_kses_data($link);
Expand All @@ -93,11 +93,11 @@
$link = sprintf(
wp_kses(
__('If you need to register for an account, you can do so at <a href="%1$s" target="%2$s">Mailgun.com</a>.', 'mailgun'),
array('a' => array(
'href' => array(),
'target' => array()
)
)
['a' => [
'href' => [],
'target' => []
]
]
), esc_url($url), '_blank'
);
echo wp_kses_data($link);
Expand Down Expand Up @@ -172,7 +172,7 @@
<?php _e('API Key', 'mailgun'); ?>
</th>
<td>
<input type="text" class="regular-text" name="mailgun[apiKey]"
<input type="password" class="regular-text" name="mailgun[apiKey]"
value="<?php esc_attr_e($mailgun_api_key); ?>"
placeholder="key-3ax6xnjp29jd6fds4gc373sgvjxteol0"
<?php echo $mailgun_api_key_const ? 'readonly="readonly"' : '' ?>
Expand Down Expand Up @@ -451,10 +451,10 @@ class="regular-text"
$link = sprintf(
wp_kses(
__('<a href="%1$s" target="%2$s">View available lists</a>.', 'mailgun'),
array('a' => array(
'href' => array(),
)
)
['a' => [
'href' => [],
]
]
), esc_url($url)
);
echo wp_kses_data($link);
Expand Down
2 changes: 1 addition & 1 deletion includes/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()
// Widget name will appear in UI
__('Mailgun List Widget', 'wpb_widget_domain'),
// Widget description
array('description' => __('Mailgun list widget', 'wpb_widget_domain'))
['description' => __('Mailgun list widget', 'wpb_widget_domain')]
);
}

Expand Down
6 changes: 6 additions & 0 deletions includes/wp-mail-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ function mg_mutate_to_rcpt_vars_cb($to_addrs): array
*
*/
if (!function_exists('wp_mail')) {
/**
* @throws \PHPMailer\PHPMailer\Exception
*/
function wp_mail($to, $subject, $message, $headers = '', $attachments = [])
{
$mailgun = get_option('mailgun');
Expand Down Expand Up @@ -160,6 +163,9 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = [])
$attachments = explode("\n", str_replace("\r\n", "\n", $attachments));
}

$cc = [];
$bcc = [];

// Headers
if (empty($headers)) {
$headers = [];
Expand Down
4 changes: 2 additions & 2 deletions includes/wp-mail-smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function mg_smtp_mail_filter(array $args)

// $headers and $attachments are optional - make sure they exist
$headers = (!isset($headers)) ? '' : $headers;
$attachments = (!isset($attachments)) ? array() : $attachments;
$attachments = (!isset($attachments)) ? [] : $attachments;

$mg_opts = get_option('mailgun');
$mg_headers = mg_parse_headers($headers);
Expand Down Expand Up @@ -142,7 +142,7 @@ function mg_smtp_mail_filter(array $args)
$from_addr = mg_detect_from_address($from_addr);

$from_header['value'] = sprintf('%s <%s>', $from_name, $from_addr);
$mg_headers['From'] = array($from_header);
$mg_headers['From'] = [$from_header];

// Header compaction
$headers = mg_dump_headers($mg_headers);
Expand Down
2 changes: 1 addition & 1 deletion 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: 2.1.2
* Version: 2.1.3
* Requires PHP: 7.4
* Requires at least: 4.4
* Author: Mailgun
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Mailgun for WordPress
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
Tags: mailgun, smtp, http, api, mail, email
Tested up to: 6.7
Stable tag: 2.1.2
Stable tag: 2.1.3
Requires PHP: 7.4
License: GPLv2 or later

Easily send email from your WordPress site through Mailgun using the HTTP API or SMTP.
Expand Down Expand Up @@ -132,6 +133,9 @@ MAILGUN_REPLY_TO_ADDRESS Type: string

== Changelog ==

= 2.1.3 (2024-11-27): =
- Use password type for API Key field for hide it. Fix warning related co compact() method

= 2.1.2 (2024-11-17): =
- Fixed code. Removed line that try to connect not existing file. Fixed versions in the plugin

Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Mailgun for WordPress
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
Tags: mailgun, smtp, http, api, mail, email
Tested up to: 6.7
Stable tag: 2.1.2
Stable tag: 2.1.3
Requires PHP: 7.4
License: GPLv2 or later

Easily send email from your WordPress site through Mailgun using the HTTP API or SMTP.
Expand Down Expand Up @@ -128,6 +129,9 @@ MAILGUN_TRACK_OPENS Type: string Choices: 'yes' or 'no'

== Changelog ==

= 2.1.3 (2024-11-27): =
- Use password type for API Key field for hide it. Fix warning related co compact() method

= 2.1.2 (2024-11-17): =
- Fixed code. Removed line that try to connect not existing file. Fixed versions in the plugin

Expand Down

0 comments on commit 1a9349d

Please sign in to comment.