Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin notice improvements. #174

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,16 @@ public function __construct()
add_action('wp_ajax_mailgun-test', [&$this, 'ajax_send_test']);
}

/**
* Adds the default options during plugin activation.
*
* @return void
*
*/
public function activation() {
if (!$this->options) {
$this->options = $this->defaults;
add_option('mailgun', $this->options);
}
/**
* Adds the default options during plugin activation.
* @return void
*/
public function activation(): void
{
if (!$this->options) {
$this->options = $this->defaults;
add_option('mailgun', $this->options);
}
}


Expand All @@ -81,7 +80,7 @@ public function activation() {
* @return void
*
*/
public function init()
public function init(): void
{
$sitename = sanitize_text_field(strtolower($_SERVER['SERVER_NAME']));
if (substr($sitename, 0, 4) === 'www.') {
Expand Down Expand Up @@ -338,26 +337,25 @@ public function admin_notices(): void
$apiKeyUndefined = (!$this->get_option('apiKey') && (!defined('MAILGUN_APIKEY') || !MAILGUN_APIKEY));
$apiActiveNotConfigured = ($this->get_option('useAPI') === '1' && ($apiRegionUndefined || $apiKeyUndefined));

if ($apiActiveNotConfigured || $smtpActiveNotConfigured):
?>
if ($_SESSION['settings_turned_of'] === false && ($apiActiveNotConfigured || $smtpActiveNotConfigured) ) { ?>
<div id='mailgun-warning' class='notice notice-warning is-dismissible'>
<p>
<?php
printf(
__('Mailgun now supports multiple regions! The U.S. region will be used by default, but you can choose the EU region. You can configure your Mailgun settings in your wp-config.php file or <a href="%1$s">here</a>',
__('Use HTTP API is turned off or you do not have SMTP credentials. You can configure your Mailgun settings in your wp-config.php file or <a href="%1$s">here</a>',
'mailgun'),
menu_page_url('mailgun', false)
);
?>
</p>
</div>
<?php
endif;
<?php $_SESSION['settings_turned_of'] = true; ?>
<?php } ?>

<?php
if ($this->get_option('override-from') === '1' &&
(!$this->get_option('from-name') || !$this->get_option('from-address'))
):
?>
) { ?>
<div id='mailgun-warning' class='notice notice-warning is-dismissible'>
<p>
<strong>
Expand All @@ -372,8 +370,7 @@ public function admin_notices(): void
?>
</p>
</div>
<?php
endif;
<?php }
}

/**
Expand All @@ -384,7 +381,7 @@ public function admin_notices(): void
* @return array
*
*/
public function filter_plugin_actions($links): array
public function filter_plugin_actions(array $links): array
{
$settings_link = '<a href="' . menu_page_url('mailgun', false) . '">' . __('Settings', 'mailgun') . '</a>';
array_unshift($links, $settings_link);
Expand Down Expand Up @@ -462,9 +459,6 @@ public function ajax_send_test()
//Log purpose
}




if ($useAPI) {
if (!function_exists('mg_api_last_error')) {
if (!include __DIR__ . '/wp-mail-api.php') {
Expand Down
4 changes: 2 additions & 2 deletions includes/lists-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
$api_key = (defined('MAILGUN_APIKEY') && MAILGUN_APIKEY) ? MAILGUN_APIKEY : $this->get_option('apiKey');
$mailgun_domain = (defined('MAILGUN_DOMAIN') && MAILGUN_DOMAIN) ? MAILGUN_DOMAIN : $this->get_option('domain');

if ($api_key != '') {
if ($mailgun_domain == '') {
if ($api_key !== '') {
if ($mailgun_domain === '') {
$missing_error = '<strong style="color:red;">Missing or invalid Mailgun Domain</strong>. ';
}
} else {
Expand Down
52 changes: 24 additions & 28 deletions includes/mg-filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,19 @@ function mg_detect_from_name($from_name_header = null)
$from_name = $from_name_header;
} elseif (defined('MAILGUN_FROM_NAME') && MAILGUN_FROM_NAME) {
$from_name = MAILGUN_FROM_NAME;
} else {
if (empty($mg_from_name)) {
if (function_exists('get_current_site')) {
$from_name = get_current_site()->site_name;
} else {
$from_name = 'WordPress';
}
} else if (empty($mg_from_name)) {
if (function_exists('get_current_site')) {
$from_name = get_current_site()->site_name;
} else {
$from_name = $mg_from_name;
$from_name = 'WordPress';
}
} else {
$from_name = $mg_from_name;
}

$filter_from_name = null;

if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from_name')) {
if ((!isset($mg_override_from) || $mg_override_from === '0') && has_filter('wp_mail_from_name')) {
$filter_from_name = apply_filters(
'wp_mail_from_name',
$from_name
Expand Down Expand Up @@ -148,25 +146,23 @@ function mg_detect_from_address($from_addr_header = null): string
$from_addr = $from_addr_header;
} elseif (defined('MAILGUN_FROM_ADDRESS') && MAILGUN_FROM_ADDRESS) {
$from_addr = MAILGUN_FROM_ADDRESS;
} else {
if (empty($mg_from_addr)) {
if (function_exists('get_current_site')) {
$sitedomain = get_current_site()->domain;
} else {
$sitedomain = strtolower(sanitize_text_field($_SERVER['SERVER_NAME']));
if (substr($sitedomain, 0, 4) === 'www.') {
$sitedomain = substr($sitedomain, 4);
}
}

$from_addr = 'wordpress@' . $sitedomain;
} else if (empty($mg_from_addr)) {
if (function_exists('get_current_site')) {
$sitedomain = get_current_site()->domain;
} else {
$from_addr = $mg_from_addr;
$sitedomain = strtolower(sanitize_text_field($_SERVER['SERVER_NAME']));
if (substr($sitedomain, 0, 4) === 'www.') {
$sitedomain = substr($sitedomain, 4);
}
}

$from_addr = 'wordpress@' . $sitedomain;
} else {
$from_addr = $mg_from_addr;
}

$filter_from_addr = null;
if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from')) {
if ((!isset($mg_override_from) || $mg_override_from === '0') && has_filter('wp_mail_from')) {
$filter_from_addr = apply_filters(
'wp_mail_from',
$from_addr
Expand Down Expand Up @@ -214,7 +210,7 @@ function mg_parse_headers($headers = []): array
$tmp = $headers;
}

$new_headers = array();
$new_headers = [];
if (!empty($tmp)) {
$name = null;
$value = null;
Expand Down Expand Up @@ -242,14 +238,14 @@ function mg_parse_headers($headers = []): array
$value = trim($value);

if (!isset($new_headers[$name])) {
$new_headers[$name] = array();
$new_headers[$name] = [];
}

$new_headers[$name][] = array(
$new_headers[$name][] = [
'value' => $value,
'boundary' => $boundary,
'parts' => $parts,
);
];
}
}

Expand All @@ -268,7 +264,7 @@ function mg_parse_headers($headers = []): array
*/
function mg_dump_headers($headers = null): string
{
if (is_null($headers) || !is_array($headers)) {
if (!is_array($headers)) {
return '';
}

Expand Down
8 changes: 4 additions & 4 deletions includes/options-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
<div class="wrap">
<div id="icon-options-general" class="icon32"><br/></div>
<span class="alignright">
<a target="_blank" href="http://www.mailgun.com/">
<img src="<?php echo esc_attr($icon) ?>" alt="Mailgun" style="width:50px;"/>
</a>
</span>
<a target="_blank" href="http://www.mailgun.com/">
<img src="<?php echo esc_attr($icon) ?>" alt="Mailgun" style="width:50px;"/>
</a>
</span>
<h2><?php _e('Mailgun', 'mailgun'); ?></h2>

<p>
Expand Down
2 changes: 2 additions & 0 deletions includes/wp-mail-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ function mg_api_last_error(string $error = null): ?string
* @since 1.5.7
*/
add_filter('mg_mutate_to_rcpt_vars', 'mg_mutate_to_rcpt_vars_cb');

/**
* @param $to_addrs
* @return array
* @throws JsonException
*/
function mg_mutate_to_rcpt_vars_cb($to_addrs): array
{
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: 1.9.7
* Version: 1.9.8
* 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,7 @@ Mailgun for WordPress
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
Tags: mailgun, smtp, http, api, mail, email
Tested up to: 6.4
Stable tag: 1.9.7
Stable tag: 1.9.8
License: GPLv2 or later

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


== Changelog ==
= 1.9.8 (2024-02-25): =
- Improve admin notices about not fully configured plugin
- Small code cleaning

= 1.9.7 (2024-01-03): =
- Ensure defaults are always set to remove warnings in PHP 8.1+

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,7 @@ Mailgun for WordPress
Contributors: mailgun, sivel, lookahead.io, m35dev, alanfuller
Tags: mailgun, smtp, http, api, mail, email
Tested up to: 6.4
Stable tag: 1.9.7
Stable tag: 1.9.8
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 +128,10 @@ MAILGUN_TRACK_OPENS Type: string Choices: 'yes' or 'no'


== Changelog ==
= 1.9.8 (2024-02-25): =
- Improve admin notices about not fully configured plugin
- Small code cleaning

= 1.9.7 (2024-01-03): =
- Ensure defaults are always set to remove warnings in PHP 8.1+

Expand Down