updated plugin WP Mail SMTP version 2.3.1

This commit is contained in:
2020-08-24 15:45:02 +00:00
committed by Gitium
parent be08bbbabd
commit fd5eaaad6c
66 changed files with 3703 additions and 1342 deletions

View File

@ -0,0 +1,153 @@
<?php
namespace WPMailSMTP\Admin;
use WPMailSMTP\Debug;
/**
* WP Mail SMTP admin bar menu.
*
* @since 2.3.0
*/
class AdminBarMenu {
/**
* Initialize class.
*
* @since 2.3.0
*/
public function init() {
$this->hooks();
}
/**
* Register hooks.
*
* @since 2.3.0
*/
public function hooks() {
add_action( 'wp_enqueue_scripts', [ $this, 'enqueues' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] );
add_action( 'admin_bar_menu', [ $this, 'register' ], 999 );
}
/**
* Check if current user has access to see admin bar menu.
*
* @since 2.3.0
*
* @return bool
*/
public function has_access() {
$access = false;
if (
is_user_logged_in() &&
current_user_can( 'manage_options' )
) {
$access = true;
}
return apply_filters( 'wp_mail_smtp_admin_adminbarmenu_has_access', $access );
}
/**
* Check if new notifications are available.
*
* @since 2.3.0
*
* @return bool
*/
public function has_notifications() {
return wp_mail_smtp()->get_notifications()->get_count();
}
/**
* Enqueue styles.
*
* @since 2.3.0
*/
public function enqueues() {
if ( ! $this->has_access() ) {
return;
}
wp_enqueue_style(
'wp-mail-smtp-admin-bar',
wp_mail_smtp()->assets_url . '/css/admin-bar.min.css',
[],
WPMS_PLUGIN_VER
);
}
/**
* Register and render admin menu bar.
*
* @since 2.3.0
*
* @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object.
*/
public function register( \WP_Admin_Bar $wp_admin_bar ) {
if (
! $this->has_access() ||
(
empty( Debug::get_last() ) &&
empty( $this->has_notifications() )
)
) {
return;
}
$items = apply_filters(
'wp_mail_smtp_admin_adminbarmenu_register',
[
'main_menu',
],
$wp_admin_bar
);
foreach ( $items as $item ) {
$this->{ $item }( $wp_admin_bar );
do_action( "wp_mail_smtp_admin_adminbarmenu_register_{$item}_after", $wp_admin_bar );
}
}
/**
* Render primary top-level admin menu bar item.
*
* @since 2.3.0
*
* @param \WP_Admin_Bar $wp_admin_bar WordPress Admin Bar object.
*/
public function main_menu( \WP_Admin_Bar $wp_admin_bar ) {
if ( ! empty( Debug::get_last() ) ) {
$indicator = ' <span class="wp-mail-smtp-admin-bar-menu-error">!</span>';
} elseif ( ! empty( $this->has_notifications() ) ) {
$count = $this->has_notifications() < 10 ? $this->has_notifications() : '!';
$indicator = ' <div class="wp-mail-smtp-admin-bar-menu-notification-counter"><span>' . $count . '</span></div>';
}
if ( ! isset( $indicator ) ) {
return;
}
$wp_admin_bar->add_menu(
[
'id' => 'wp-mail-smtp-menu',
'title' => 'WP Mail SMTP' . $indicator,
'href' => apply_filters(
'wp_mail_smtp_admin_adminbarmenu_main_menu_href',
wp_mail_smtp()->get_admin()->get_admin_page_url()
),
]
);
}
}

View File

@ -99,6 +99,7 @@ class Area {
add_action( 'wp_ajax_wp_mail_smtp_ajax', [ $this, 'process_ajax' ] );
( new Review() )->hooks();
( new Education() )->hooks();
}
/**
@ -128,7 +129,6 @@ class Area {
break;
case 'google_no_code_scope':
case 'microsoft_no_code':
WP::add_admin_notice(
esc_html__( 'There was an error while processing the authentication request. Please try again.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_ERROR
@ -150,12 +150,6 @@ class Area {
WP::ADMIN_NOTICE_SUCCESS
);
break;
case 'microsoft_site_linked':
WP::add_admin_notice(
esc_html__( 'You have successfully linked the current site with your Microsoft API project. Now you can start sending emails through Outlook.', 'wp-mail-smtp' ),
WP::ADMIN_NOTICE_SUCCESS
);
break;
}
}
@ -316,7 +310,7 @@ class Area {
'upgrade_icon_lock' => '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lock" class="svg-inline--fa fa-lock fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"></path></svg>',
'upgrade_title' => esc_html__( '%name% is a PRO Feature', 'wp-mail-smtp' ),
'upgrade_button' => esc_html__( 'Upgrade to Pro', 'wp-mail-smtp' ),
'upgrade_url' => 'https://wpmailsmtp.com/lite-upgrade/?discount=SMTPLITEUPGRADE&utm_source=WordPress&utm_medium=plugin-settings&utm_campaign=liteplugin',
'upgrade_url' => add_query_arg( 'discount', 'SMTPLITEUPGRADE', wp_mail_smtp()->get_upgrade_link( '' ) ),
'upgrade_bonus' => '<p>' .
wp_kses(
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span>$50 off</span> regular price,<br>applied at checkout.', 'wp-mail-smtp' ),
@ -331,6 +325,8 @@ class Area {
' . esc_html__( 'Already purchased?', 'wp-mail-smtp' ) . '
</a>',
),
'all_mailers_supports' => wp_mail_smtp()->get_providers()->get_supports_all(),
'nonce' => wp_create_nonce( 'wp-mail-smtp-admin' ),
)
);
@ -435,6 +431,8 @@ class Area {
if ( ! $this->is_admin_page() ) {
return;
}
do_action( 'wp_mail_smtp_admin_header_before' );
?>
<div id="wp-mail-smtp-header-temp"></div>
@ -590,6 +588,8 @@ class Area {
<?php echo esc_html( $this->get_current_tab_title() ); ?>
</h1>
<?php do_action( 'wp_mail_smtp_admin_pages_before_content' ); ?>
<?php $this->display_current_tab_content(); ?>
</div>

View File

@ -0,0 +1,102 @@
<?php
namespace WPMailSMTP\Admin;
/**
* WP Mail SMTP enhancements to admin pages to educate Lite users on what is available in WP Mail SMTP Pro.
*
* @since 2.3.0
*/
class Education {
/**
* The dismissed notice bar user meta key.
*
* @since 2.3.0
*/
const DISMISS_NOTICE_BAR_KEY = 'wp_mail_smtp_edu_notice_bar_dismissed';
/**
* Hooks.
*
* @since 2.3.0
*/
public function hooks() {
if ( apply_filters( 'wp_mail_smtp_admin_education_notice_bar', true ) ) {
add_action( 'admin_init', [ $this, 'notice_bar_init' ] );
}
}
/**
* Notice bar init.
*
* @since 2.3.0
*/
public function notice_bar_init() {
add_action( 'wp_mail_smtp_admin_header_before', [ $this, 'notice_bar_display' ] );
add_action( 'wp_ajax_wp_mail_smtp_notice_bar_dismiss', [ $this, 'notice_bar_ajax_dismiss' ] );
}
/**
* Notice bar display message.
*
* @since 2.3.0
*/
public function notice_bar_display() {
// Bail if we're not on a plugin admin page.
if ( ! wp_mail_smtp()->get_admin()->is_admin_page() ) {
return;
}
$dismissed = get_user_meta( get_current_user_id(), self::DISMISS_NOTICE_BAR_KEY, true );
if ( ! empty( $dismissed ) ) {
return;
}
printf(
'<div id="wp-mail-smtp-notice-bar">
<div class="wp-amil-smtp-notice-bar-container">
<span class="wp-mail-smtp-notice-bar-message">%s</span>
<button type="button" class="dismiss" title="%s" />
</div>
</div>',
wp_kses(
sprintf( /* translators: %s - WPMailSMTP.com Upgrade page URL. */
__( 'Youre using WP Mail SMTP Lite. To unlock more features consider <a href="%s" target="_blank" rel="noopener noreferrer">upgrading to Pro</a>.', 'wp-mail-smtp' ),
wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'notice-bar' ] )
),
[
'a' => [
'href' => [],
'rel' => [],
'target' => [],
],
]
),
esc_attr__( 'Dismiss this message.', 'wp-mail-smtp' )
);
}
/**
* Ajax handler for dismissing notices.
*
* @since 2.3.0
*/
public function notice_bar_ajax_dismiss() {
// Run a security check.
check_ajax_referer( 'wp-mail-smtp-admin', 'nonce' );
// Check for permissions.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error();
}
update_user_meta( get_current_user_id(), self::DISMISS_NOTICE_BAR_KEY, time() );
wp_send_json_success();
}
}

View File

@ -0,0 +1,491 @@
<?php
namespace WPMailSMTP\Admin;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Notifications.
*
* @since 2.3.0
*/
class Notifications {
/**
* Source of notifications content.
*
* @since 2.3.0
*
* @var string
*/
const SOURCE_URL = 'https://plugin-cdn.wpmailsmtp.com/wp-content/notifications.json';
/**
* The WP option key for storing the notification options.
*
* @since 2.3.0
*
* @var string
*/
const OPTION_KEY = 'wp_mail_smtp_notifications';
/**
* Option value.
*
* @since 2.3.0
*
* @var bool|array
*/
public $option = false;
/**
* Initialize class.
*
* @since 2.3.0
*/
public function init() {
$this->hooks();
}
/**
* Register hooks.
*
* @since 2.3.0
*/
public function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
add_action( 'wp_mail_smtp_admin_pages_before_content', [ $this, 'output' ] );
add_action( 'wp_mail_smtp_admin_notifications_update', [ $this, 'update' ] );
add_action( 'wp_ajax_wp_mail_smtp_notification_dismiss', [ $this, 'dismiss' ] );
}
/**
* Check if user has access and is enabled.
*
* @since 2.3.0
*
* @return bool
*/
public function has_access() {
$access = false;
if (
current_user_can( 'manage_options' ) &&
! ( new Options() )->get( 'general', 'am_notifications_hidden' )
) {
$access = true;
}
return apply_filters( 'wp_mail_smtp_admin_notifications_has_access', $access );
}
/**
* Get option value.
*
* @since 2.3.0
*
* @param bool $cache Reference property cache if available.
*
* @return array
*/
public function get_option( $cache = true ) {
if ( $this->option && $cache ) {
return $this->option;
}
$option = get_option( self::OPTION_KEY, [] );
$this->option = [
'update' => ! empty( $option['update'] ) ? $option['update'] : 0,
'events' => ! empty( $option['events'] ) ? $option['events'] : [],
'feed' => ! empty( $option['feed'] ) ? $option['feed'] : [],
'dismissed' => ! empty( $option['dismissed'] ) ? $option['dismissed'] : [],
];
return $this->option;
}
/**
* Fetch notifications from feed.
*
* @since 2.3.0
*
* @return array
*/
protected function fetch_feed() {
$response = wp_remote_get( self::SOURCE_URL );
if ( is_wp_error( $response ) ) {
return [];
}
$body = wp_remote_retrieve_body( $response );
if ( empty( $body ) ) {
return [];
}
return $this->verify( json_decode( $body, true ) );
}
/**
* Verify notification data before it is saved.
*
* @since 2.3.0
*
* @param array $notifications Array of notification items to verify.
*
* @return array
*/
protected function verify( $notifications ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$data = [];
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
return $data;
}
$option = $this->get_option();
foreach ( $notifications as $notification ) {
// The message and license should never be empty, if they are, ignore.
if ( empty( $notification['content'] ) || empty( $notification['type'] ) ) {
continue;
}
// Ignore if license type does not match.
if ( ! in_array( wp_mail_smtp()->get_license_type(), $notification['type'], true ) ) {
continue;
}
// Ignore if expired.
if ( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) ) {
continue;
}
// Ignore if notification has already been dismissed.
if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
continue;
}
// Ignore if notification existed before installing WPForms.
// Prevents bombarding the user with notifications after activation.
$activated = get_option( 'wp_mail_smtp_activated_time' );
if (
! empty( $activated ) &&
! empty( $notification['start'] ) &&
$activated > strtotime( $notification['start'] )
) {
continue;
}
$data[] = $notification;
}
return $data;
}
/**
* Verify saved notification data for active notifications.
*
* @since 2.3.0
*
* @param array $notifications Array of notification items to verify.
*
* @return array
*/
protected function verify_active( $notifications ) {
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
return [];
}
// Remove notifications that are not active.
foreach ( $notifications as $key => $notification ) {
if (
( ! empty( $notification['start'] ) && time() < strtotime( $notification['start'] ) ) ||
( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) )
) {
unset( $notifications[ $key ] );
}
}
return $notifications;
}
/**
* Get notification data.
*
* @since 2.3.0
*
* @return array
*/
public function get() {
if ( ! $this->has_access() ) {
return [];
}
$option = $this->get_option();
// Update notifications using async task.
if ( empty( $option['update'] ) || time() > $option['update'] + DAY_IN_SECONDS ) {
if ( empty( wp_mail_smtp()->get_tasks()->is_scheduled( 'wp_mail_smtp_admin_notifications_update' ) ) ) {
wp_mail_smtp()->get_tasks()
->create( 'wp_mail_smtp_admin_notifications_update' )
->async()
->params()
->register();
}
}
$events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : [];
$feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : [];
return array_merge( $events, $feed );
}
/**
* Get notification count.
*
* @since 2.3.0
*
* @return int
*/
public function get_count() {
return count( $this->get() );
}
/**
* Add a manual notification event.
*
* @since 2.3.0
*
* @param array $notification Notification data.
*/
public function add( $notification ) {
if ( empty( $notification['id'] ) ) {
return;
}
$option = $this->get_option();
if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
return;
}
foreach ( $option['events'] as $item ) {
if ( $item['id'] === $notification['id'] ) {
return;
}
}
$notification = $this->verify( [ $notification ] );
update_option(
self::OPTION_KEY,
[
'update' => $option['update'],
'feed' => $option['feed'],
'events' => array_merge( $notification, $option['events'] ),
'dismissed' => $option['dismissed'],
]
);
}
/**
* Update notification data from feed.
*
* @since 2.3.0
*/
public function update() {
$feed = $this->fetch_feed();
$option = $this->get_option();
update_option(
self::OPTION_KEY,
[
'update' => time(),
'feed' => $feed,
'events' => $option['events'],
'dismissed' => $option['dismissed'],
]
);
}
/**
* Admin area assets.
*
* @since 2.3.0
*
* @param string $hook Hook suffix for the current admin page.
*/
public function enqueue_assets( $hook ) {
if ( strpos( $hook, Area::SLUG ) === false ) {
return;
}
if ( ! $this->has_access() ) {
return;
}
$notifications = $this->get();
if ( empty( $notifications ) ) {
return;
}
wp_enqueue_style(
'wp-mail-smtp-admin-notifications',
wp_mail_smtp()->assets_url . '/css/admin-notifications.min.css',
[],
WPMS_PLUGIN_VER
);
wp_enqueue_script(
'wp-mail-smtp-admin-notifications',
wp_mail_smtp()->assets_url . '/js/smtp-notifications' . WP::asset_min() . '.js',
[ 'jquery' ],
WPMS_PLUGIN_VER,
true
);
}
/**
* Output notifications.
*
* @since 2.3.0
*/
public function output() { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded
$notifications = $this->get();
if ( empty( $notifications ) ) {
return;
}
$notifications_html = '';
$current_class = ' current';
$content_allowed_tags = [
'em' => [],
'i' => [],
'strong' => [],
'span' => [
'style' => [],
],
'a' => [
'href' => [],
'target' => [],
'rel' => [],
],
];
foreach ( $notifications as $notification ) {
// Buttons HTML.
$buttons_html = '';
if ( ! empty( $notification['btns'] ) && is_array( $notification['btns'] ) ) {
foreach ( $notification['btns'] as $btn_type => $btn ) {
if ( empty( $btn['text'] ) ) {
continue;
}
$buttons_html .= sprintf(
'<a href="%1$s" class="button button-%2$s"%3$s>%4$s</a>',
! empty( $btn['url'] ) ? esc_url( $btn['url'] ) : '',
$btn_type === 'main' ? 'primary' : 'secondary',
! empty( $btn['target'] ) && $btn['target'] === '_blank' ? ' target="_blank" rel="noopener noreferrer"' : '',
sanitize_text_field( $btn['text'] )
);
}
$buttons_html = ! empty( $buttons_html ) ? '<div class="buttons">' . $buttons_html . '</div>' : '';
}
// Notification HTML.
$notifications_html .= sprintf(
'<div class="message%5$s" data-message-id="%4$s">
<h3 class="title">%1$s</h3>
<p class="content">%2$s</p>
%3$s
</div>',
! empty( $notification['title'] ) ? sanitize_text_field( $notification['title'] ) : '',
! empty( $notification['content'] ) ? wp_kses( $notification['content'], $content_allowed_tags ) : '',
$buttons_html,
! empty( $notification['id'] ) ? esc_attr( sanitize_text_field( $notification['id'] ) ) : 0,
$current_class
);
// Only first notification is current.
$current_class = '';
}
?>
<div id="wp-mail-smtp-notifications">
<div class="bell">
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="48" viewBox="0 0 42 48"><defs><style>.a{fill:#777;}.b{fill:#ca4a1f;}</style></defs><path class="a" d="M23-79a6.005,6.005,0,0,1-6-6h10.06a12.066,12.066,0,0,0,1.791,1.308,6.021,6.021,0,0,1-2.077,3.352A6.008,6.008,0,0,1,23-79Zm1.605-9H5.009a2.955,2.955,0,0,1-2.173-.923A3.088,3.088,0,0,1,2-91a2.919,2.919,0,0,1,.807-2.036c.111-.12.229-.243.351-.371a14.936,14.936,0,0,0,3.126-4.409A23.283,23.283,0,0,0,8.007-107.5a14.846,14.846,0,0,1,.906-5.145,14.5,14.5,0,0,1,2.509-4.324A15.279,15.279,0,0,1,20-122.046V-124a3,3,0,0,1,3-3,3,3,0,0,1,3,3v1.954a15.28,15.28,0,0,1,8.58,5.078,14.5,14.5,0,0,1,2.509,4.324,14.846,14.846,0,0,1,.906,5.145c0,.645.016,1.281.047,1.888A12.036,12.036,0,0,0,35-106a11.921,11.921,0,0,0-8.485,3.515A11.923,11.923,0,0,0,23-94a12,12,0,0,0,1.6,6Z" transform="translate(-2 127)"/><circle class="b" cx="9" cy="9" r="9" transform="translate(24 24)"/></svg>
</div>
<a class="dismiss" title="<?php echo esc_attr__( 'Dismiss this message', 'wp-mail-smtp' ); ?>"><span class="dashicons dashicons-dismiss"></span></a>
<div class="navigation">
<a class="prev disabled" title="<?php echo esc_attr__( 'Previous message', 'wp-mail-smtp' ); ?>"><span class="dashicons dashicons-arrow-left-alt2"></span></a>
<a class="next disabled" title="<?php echo esc_attr__( 'Next message', 'wp-mail-smtp' ); ?>"><span class="dashicons dashicons-arrow-right-alt2"></span></a>
</div>
<div class="messages">
<?php echo $notifications_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
</div>
<?php
}
/**
* Dismiss notification via AJAX.
*
* @since 2.3.0
*/
public function dismiss() {
// Run a security check.
check_ajax_referer( 'wp-mail-smtp-admin', 'nonce' );
// Check for access and required param.
if ( ! current_user_can( 'manage_options' ) || empty( $_POST['id'] ) ) {
wp_send_json_error();
}
$id = sanitize_text_field( wp_unslash( $_POST['id'] ) );
$option = $this->get_option();
$type = is_numeric( $id ) ? 'feed' : 'events';
$option['dismissed'][] = $id;
$option['dismissed'] = array_unique( $option['dismissed'] );
// Remove notification.
if ( is_array( $option[ $type ] ) && ! empty( $option[ $type ] ) ) {
foreach ( $option[ $type ] as $key => $notification ) {
if ( $notification['id'] == $id ) { // phpcs:ignore WordPress.PHP.StrictComparisons
unset( $option[ $type ][ $key ] );
break;
}
}
}
update_option( self::OPTION_KEY, $option );
wp_send_json_success();
}
}

View File

@ -142,6 +142,8 @@ class About extends PageAbstract {
<?php echo \esc_html( $this->get_label( $this->get_current_tab() ) ); ?>
</h1>
<?php do_action( 'wp_mail_smtp_admin_pages_before_content' ); ?>
<?php
$callback = 'display_' . $this->get_current_tab();

View File

@ -114,7 +114,7 @@ class ControlTab extends PageAbstract {
</div>
<div class="wp-mail-smtp-page-upsell-button">
<a href="https://wpmailsmtp.com/lite-upgrade/?discount=LITEUPGRADE&amp;utm_source=WordPress&amp;utm_medium=logs&amp;utm_campaign=liteplugin"
<a href="<?php echo esc_url( add_query_arg( 'discount', 'LITEUPGRADE', wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'logs', 'content' => '' ] ) ) ); // phpcs:ignore ?>"
class="wp-mail-smtp-btn wp-mail-smtp-btn-lg wp-mail-smtp-btn-orange" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Upgrade to WP Mail SMTP Pro', 'wp-mail-smtp' ); ?>
</a>

View File

@ -63,7 +63,8 @@ class LogsTab extends PageAbstract {
</div>
<div class="wp-mail-smtp-page-upsell-button">
<a href="https://wpmailsmtp.com/lite-upgrade/?discount=LITEUPGRADE&amp;utm_source=WordPress&amp;utm_medium=logs&amp;utm_campaign=liteplugin" class="wp-mail-smtp-btn wp-mail-smtp-btn-lg wp-mail-smtp-btn-orange wp-mail-smtp-upgrade-modal" target="_blank" rel="noopener noreferrer">
<a href="<?php echo esc_url( add_query_arg( 'discount', 'LITEUPGRADE', wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'logs', 'content' => '' ] ) ) ); // phpcs:ignore ?>"
class="wp-mail-smtp-btn wp-mail-smtp-btn-lg wp-mail-smtp-btn-orange wp-mail-smtp-upgrade-modal" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Upgrade to WP Mail SMTP Pro', 'wp-mail-smtp' ); ?>
</a>
</div>

View File

@ -4,6 +4,7 @@ namespace WPMailSMTP\Admin\Pages;
use WPMailSMTP\Admin\PageAbstract;
use WPMailSMTP\Options;
use WPMailSMTP\UsageTracking\UsageTracking;
use WPMailSMTP\WP;
/**
@ -190,6 +191,25 @@ class MiscTab extends PageAbstract {
</div>
</div>
<?php if ( apply_filters( 'wp_mail_smtp_admin_pages_misc_tab_show_usage_tracking_setting', true ) ) : ?>
<!-- Usage Tracking -->
<div id="wp-mail-smtp-setting-row-usage-tracking" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-usage-tracking">
<?php esc_html_e( 'Allow Usage Tracking', 'wp-mail-smtp' ); ?>
</label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[general][<?php echo esc_attr( UsageTracking::SETTINGS_SLUG ); ?>]" type="checkbox"
value="true" <?php checked( true, $options->get( 'general', UsageTracking::SETTINGS_SLUG ) ); ?>
id="wp-mail-smtp-setting-usage-tracking">
<label for="wp-mail-smtp-setting-usage-tracking">
<?php esc_html_e( 'By allowing us to track usage data we can better help you because we know with which WordPress configurations, themes and plugins we should test.', 'wp-mail-smtp' ); ?>
</label>
</div>
</div>
<?php endif; ?>
<?php $this->display_save_btn(); ?>
</form>
@ -224,6 +244,9 @@ class MiscTab extends PageAbstract {
if ( empty( $data['general']['uninstall'] ) ) {
$data['general']['uninstall'] = false;
}
if ( empty( $data['general'][ UsageTracking::SETTINGS_SLUG ] ) ) {
$data['general'][ UsageTracking::SETTINGS_SLUG ] = false;
}
$to_save = Options::array_merge_recursive( $options->get_all(), $data );

View File

@ -52,8 +52,14 @@ class SettingsTab extends PageAbstract {
$options = new Options();
$mailer = $options->get( 'mail', 'mailer' );
$disabled_email = 'gmail' === $mailer || 'outlook' === $mailer ? 'disabled' : '';
$disabled_email = in_array( $mailer, [ 'gmail', 'outlook', 'zoho' ], true ) ? 'disabled' : '';
$disabled_name = 'outlook' === $mailer ? 'disabled' : '';
if ( empty( $mailer ) ) {
$mailer = 'mail';
}
$mailer_supported_settings = wp_mail_smtp()->get_providers()->get_options( $mailer )->get_supports();
?>
<form method="POST" action="" autocomplete="off">
@ -95,76 +101,79 @@ class SettingsTab extends PageAbstract {
<label for="wp-mail-smtp-setting-from_email"><?php esc_html_e( 'From Email', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php if ( 'gmail' !== $mailer ) : ?>
<input name="wp-mail-smtp[mail][from_email]" type="email"
value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_email' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_email() ); ?>">
<?php else : ?>
<?php
// Gmail mailer From Email selector.
$gmail_auth = new Auth();
$gmail_aliases = $gmail_auth->is_clients_saved() ? $gmail_auth->get_user_possible_send_from_addresses() : [];
?>
<?php if ( empty( $gmail_aliases ) ) : ?>
<select name="wp-mail-smtp[mail][from_email]" id="wp-mail-smtp-setting-from_email" disabled>
<option value=""><?php esc_html_e( 'Please first authorize the Gmail mailer below', 'wp-mail-smtp' ); ?></option>
</select>
<div class="js-wp-mail-smtp-setting-from_email" style="display: <?php echo empty( $mailer_supported_settings['from_email'] ) ? 'none' : 'block'; ?>;">
<?php if ( 'gmail' !== $mailer ) : ?>
<input name="wp-mail-smtp[mail][from_email]" type="email"
value="<?php echo esc_attr( $options->get( 'mail', 'from_email' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_email' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_email() ); ?>">
<?php else : ?>
<select name="wp-mail-smtp[mail][from_email]" id="wp-mail-smtp-setting-from_email">
<?php foreach ( $gmail_aliases as $gmail_email_address ) : ?>
<option value="<?php echo esc_attr( $gmail_email_address ); ?>" <?php selected( $options->get( 'mail', 'from_email' ), $gmail_email_address ); ?>><?php echo esc_html( $gmail_email_address ); ?></option>
<?php endforeach; ?>
</select>
<?php
// Gmail mailer From Email selector.
$gmail_auth = new Auth();
$gmail_aliases = $gmail_auth->is_clients_saved() ? $gmail_auth->get_user_possible_send_from_addresses() : [];
?>
<?php if ( empty( $gmail_aliases ) ) : ?>
<select name="wp-mail-smtp[mail][from_email]" id="wp-mail-smtp-setting-from_email" disabled>
<option value=""><?php esc_html_e( 'Please first authorize the Gmail mailer below', 'wp-mail-smtp' ); ?></option>
</select>
<?php else : ?>
<select name="wp-mail-smtp[mail][from_email]" id="wp-mail-smtp-setting-from_email">
<?php foreach ( $gmail_aliases as $gmail_email_address ) : ?>
<option value="<?php echo esc_attr( $gmail_email_address ); ?>" <?php selected( $options->get( 'mail', 'from_email' ), $gmail_email_address ); ?>><?php echo esc_html( $gmail_email_address ); ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if ( empty( $disabled_email ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The email address which emails are sent from.', 'wp-mail-smtp' ); ?><br/>
<?php esc_html_e( 'If you\'re using an email provider (Yahoo, Outlook.com, etc) this should be your email address for that account.', 'wp-mail-smtp' ); ?>
</p>
<p class="desc">
<?php esc_html_e( 'Please note that other plugins can change this, to prevent this use the setting below.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
<?php if ( empty( $disabled_email ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The email address which emails are sent from.', 'wp-mail-smtp' ); ?><br/>
<?php esc_html_e( 'If you\'re using an email provider (Yahoo, Outlook.com, etc) this should be your email address for that account.', 'wp-mail-smtp' ); ?>
</p>
<p class="desc">
<?php esc_html_e( 'Please note that other plugins can change this, to prevent this use the setting below.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<hr class="wp-mail-smtp-setting-mid-row-sep" style="display: <?php echo ( ! empty( $mailer_supported_settings['from_email'] ) && ! empty( $mailer_supported_settings['from_email_force'] ) ) ? 'block' : 'none'; ?>;">
<hr class="wp-mail-smtp-setting-mid-row-sep">
<div class="js-wp-mail-smtp-setting-from_email_force" style="display: <?php echo empty( $mailer_supported_settings['from_email_force'] ) ? 'none' : 'block'; ?>;">
<?php if ( 'gmail' !== $mailer ) : ?>
<input name="wp-mail-smtp[mail][from_email_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_email_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_email_force' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email_force">
<?php else : ?>
<input name="wp-mail-smtp[mail][from_email_force]" type="checkbox"
value="true" checked="checked" disabled
id="wp-mail-smtp-setting-from_email_force">
<?php endif; ?>
<?php if ( 'gmail' !== $mailer ) : ?>
<input name="wp-mail-smtp[mail][from_email_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_email_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_email_force' ) || ! empty( $disabled_email ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_email_force">
<?php else : ?>
<input name="wp-mail-smtp[mail][from_email_force]" type="checkbox"
value="true" checked="checked" disabled
id="wp-mail-smtp-setting-from_email_force">
<?php endif; ?>
<label for="wp-mail-smtp-setting-from_email_force">
<?php esc_html_e( 'Force From Email', 'wp-mail-smtp' ); ?>
</label>
<?php if ( ! empty( $disabled_email ) ) : ?>
<p class="desc">
<?php
if ( 'gmail' !== $mailer ) :
esc_html_e( 'Current provider will automatically force From Email to be the email address that you use to set up the connection below.', 'wp-mail-smtp' );
else :
esc_html_e( 'Gmail mailer will automatically force From Email to be the email address that you selected above.', 'wp-mail-smtp' );
endif;
?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Email setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<label for="wp-mail-smtp-setting-from_email_force">
<?php esc_html_e( 'Force From Email', 'wp-mail-smtp' ); ?>
</label>
<?php if ( ! empty( $disabled_email ) ) : ?>
<p class="desc">
<?php
if ( 'gmail' !== $mailer ) :
esc_html_e( 'Current provider will automatically force From Email to be the email address that you use to set up the connection below.', 'wp-mail-smtp' );
else :
esc_html_e( 'Gmail mailer will automatically force From Email to be the email address that you selected above.', 'wp-mail-smtp' );
endif;
?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Email setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
</div>
</div>
@ -174,43 +183,47 @@ class SettingsTab extends PageAbstract {
<label for="wp-mail-smtp-setting-from_name"><?php esc_html_e( 'From Name', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input name="wp-mail-smtp[mail][from_name]" type="text"
value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_name' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_name() ); ?>">
<div class="js-wp-mail-smtp-setting-from_name" style="display: <?php echo empty( $mailer_supported_settings['from_name'] ) ? 'none' : 'block'; ?>;">
<input name="wp-mail-smtp[mail][from_name]" type="text"
value="<?php echo esc_attr( $options->get( 'mail', 'from_name' ) ); ?>"
<?php echo $options->is_const_defined( 'mail', 'from_name' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name" spellcheck="false"
placeholder="<?php echo esc_attr( wp_mail_smtp()->get_processor()->get_default_name() ); ?>">
<?php if ( empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The name which emails are sent from.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<?php if ( empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'The name which emails are sent from.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
<hr class="wp-mail-smtp-setting-mid-row-sep">
<hr class="wp-mail-smtp-setting-mid-row-sep" style="display: <?php echo ( ! empty( $mailer_supported_settings['from_name'] ) && ! empty( $mailer_supported_settings['from_name_force'] ) ) ? 'block' : 'none'; ?>;">
<input name="wp-mail-smtp[mail][from_name_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_name_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_name_force' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name_force">
<div class="js-wp-mail-smtp-setting-from_name_force" style="display: <?php echo empty( $mailer_supported_settings['from_name_force'] ) ? 'none' : 'block'; ?>;">
<input name="wp-mail-smtp[mail][from_name_force]" type="checkbox"
value="true" <?php checked( true, (bool) $options->get( 'mail', 'from_name_force' ) ); ?>
<?php echo $options->is_const_defined( 'mail', 'from_name_force' ) || ! empty( $disabled_name ) ? 'disabled' : ''; ?>
id="wp-mail-smtp-setting-from_name_force">
<label for="wp-mail-smtp-setting-from_name_force">
<?php esc_html_e( 'Force From Name', 'wp-mail-smtp' ); ?>
</label>
<label for="wp-mail-smtp-setting-from_name_force">
<?php esc_html_e( 'Force From Name', 'wp-mail-smtp' ); ?>
</label>
<?php if ( ! empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'Current provider doesn\'t support setting and forcing From Name. Emails will be sent on behalf of the account name used to setup the connection below.', 'wp-mail-smtp' ); ?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Name setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
<?php if ( ! empty( $disabled_name ) ) : ?>
<p class="desc">
<?php esc_html_e( 'Current provider doesn\'t support setting and forcing From Name. Emails will be sent on behalf of the account name used to setup the connection below.', 'wp-mail-smtp' ); ?>
</p>
<?php else : ?>
<p class="desc">
<?php esc_html_e( 'If checked, the From Name setting above will be used for all emails, ignoring values set by other plugins.', 'wp-mail-smtp' ); ?>
</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- Return Path -->
<div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear">
<div id="wp-mail-smtp-setting-row-return_path" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox wp-mail-smtp-clear js-wp-mail-smtp-setting-return_path" style="display: <?php echo empty( $mailer_supported_settings['return_path'] ) ? 'none' : 'block'; ?>;">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-return_path"><?php esc_html_e( 'Return Path', 'wp-mail-smtp' ); ?></label>
</div>
@ -250,7 +263,8 @@ class SettingsTab extends PageAbstract {
<div class="wp-mail-smtp-mailer-text">
<?php if ( $provider->is_disabled() ) : ?>
<input type="radio" name="wp-mail-smtp[mail][mailer]" disabled class="educate"
<input type="radio" name="wp-mail-smtp[mail][mailer]" disabled
class="js-wp-mail-smtp-setting-mailer-radio-input educate"
id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
value="<?php echo esc_attr( $provider->get_slug() ); ?>"
/>
@ -258,9 +272,9 @@ class SettingsTab extends PageAbstract {
<input id="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>"
type="radio" name="wp-mail-smtp[mail][mailer]"
value="<?php echo esc_attr( $provider->get_slug() ); ?>"
class="js-wp-mail-smtp-setting-mailer-radio-input<?php echo $provider->is_disabled() ? ' educate' : ''; ?>"
<?php checked( $provider->get_slug(), $mailer ); ?>
<?php echo $options->is_const_defined( 'mail', 'mailer' ) || $provider->is_disabled() ? 'disabled' : ''; ?>
<?php echo $provider->is_disabled() ? 'class="educate"' : ''; ?>
/>
<?php endif; ?>
<label for="wp-mail-smtp-setting-mailer-<?php echo esc_attr( $provider->get_slug() ); ?>">

View File

@ -270,25 +270,30 @@ class PluginsInstallUpgrader extends \Plugin_Upgrader {
* Download a package.
*
* @since 2.8.0
* @since 5.5.0 Added the `$hook_extra` parameter.
*
* @param string $package The URI of the package. If this is the full path to an
* existing local file, it will be returned untouched.
* @param bool $check_signatures Whether to validate file signatures. Default false.
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array.
*
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
*/
public function download_package( $package, $check_signatures = false ) {
public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {
/**
* Filters whether to return the package.
*
* @since 3.7.0
* @since 5.5.0 Added the `$hook_extra` parameter.
*
* @param bool $reply Whether to bail without returning the package.
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $this The WP_Upgrader instance.
* @param bool $reply Whether to bail without returning the package.
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $this The WP_Upgrader instance.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
if ( false !== $reply ) {
return $reply;
}

View File

@ -88,8 +88,8 @@ class Review {
// Get the currently selected mailer.
$mailer = Options::init()->get( 'mail', 'mailer' );
// Skip if the default mailer is selected.
if ( $mailer === 'mail' ) {
// Skip if no or the default mailer is selected.
if ( empty( $mailer ) || $mailer === 'mail' ) {
return;
}

View File

@ -2,6 +2,10 @@
namespace WPMailSMTP;
use WPMailSMTP\Admin\AdminBarMenu;
use WPMailSMTP\Admin\Notifications;
use WPMailSMTP\UsageTracking\UsageTracking;
/**
* Class Core to handle all plugin initialization.
*
@ -105,24 +109,27 @@ class Core {
}
// Action Scheduler requires a special early loading procedure.
add_action( 'plugins_loaded', array( $this, 'load_action_scheduler' ), - 10 );
add_action( 'plugins_loaded', [ $this, 'load_action_scheduler' ], - 10 );
// Activation hook.
register_activation_hook( WPMS_PLUGIN_FILE, array( $this, 'activate' ) );
register_activation_hook( WPMS_PLUGIN_FILE, [ $this, 'activate' ] );
// Redefine PHPMailer.
add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
add_action( 'plugins_loaded', array( $this, 'replace_phpmailer' ) );
add_action( 'plugins_loaded', [ $this, 'get_processor' ] );
add_action( 'plugins_loaded', [ $this, 'replace_phpmailer' ] );
// Various notifications.
add_action( 'admin_init', array( $this, 'init_notifications' ) );
add_action( 'admin_init', [ $this, 'init_notifications' ] );
add_action( 'init', array( $this, 'init' ) );
add_action( 'init', [ $this, 'init' ] );
// Initialize Action Scheduler tasks.
add_action( 'init', array( $this, 'get_tasks' ), 5 );
add_action( 'init', [ $this, 'get_tasks' ], 5 );
add_action( 'plugins_loaded', array( $this, 'get_pro' ) );
add_action( 'plugins_loaded', [ $this, 'get_pro' ] );
add_action( 'plugins_loaded', [ $this, 'get_usage_tracking' ] );
add_action( 'plugins_loaded', [ $this, 'get_admin_bar_menu' ] );
add_action( 'plugins_loaded', [ $this, 'get_notifications' ] );
}
/**
@ -264,6 +271,10 @@ class Core {
if ( ! isset( $processor ) ) {
$processor = apply_filters( 'wp_mail_smtp_core_get_processor', new Processor() );
if ( method_exists( $processor, 'hooks' ) ) {
$processor->hooks();
}
}
return $processor;
@ -469,7 +480,20 @@ class Core {
}
if ( wp_mail_smtp()->get_admin()->is_error_delivery_notice_enabled() ) {
$notice = Debug::get_last();
$screen = get_current_screen();
// Skip the error notice if not on plugin page.
if (
is_object( $screen ) &&
strpos( $screen->id, 'page_wp-mail-smtp' ) === false
) {
return;
}
$notice = apply_filters(
'wp_mail_smtp_core_display_general_notices_email_delivery_error_notice',
Debug::get_last()
);
if ( ! empty( $notice ) ) {
?>
@ -618,6 +642,19 @@ class Core {
* @since 2.1.0
*/
add_option( 'wp_mail_smtp_activated_time', time(), '', false );
/**
* Store the timestamp of the first plugin activation by license type.
*
* @since 2.3.0
*/
$license_type = is_readable( $this->plugin_path . '/src/Pro/Pro.php' ) ? 'pro' : 'lite';
$activated = get_option( 'wp_mail_smtp_activated', [] );
if ( empty( $activated[ $license_type ] ) ) {
$activated[ $license_type ] = time();
update_option( 'wp_mail_smtp_activated', $activated );
}
}
/**
@ -703,10 +740,13 @@ class Core {
$content = $utm;
}
return apply_filters(
'wp_mail_smtp_core_get_upgrade_link',
'https://wpmailsmtp.com/lite-upgrade/?utm_source=' . esc_attr( $source ) . '&utm_medium=' . esc_attr( $medium ) . '&utm_campaign=' . esc_attr( $campaign ) . '&utm_content=' . esc_attr( $content )
);
$url = 'https://wpmailsmtp.com/lite-upgrade/?utm_source=' . esc_attr( $source ) . '&utm_medium=' . esc_attr( $medium ) . '&utm_campaign=' . esc_attr( $campaign );
if ( ! empty( $content ) ) {
$url .= '&utm_content=' . esc_attr( $content );
}
return apply_filters( 'wp_mail_smtp_core_get_upgrade_link', $url );
}
/**
@ -841,4 +881,76 @@ class Core {
return $value;
}
/**
* Load the plugin admin bar menu and initialize it.
*
* @since 2.3.0
*
* @return AdminBarMenu
*/
public function get_admin_bar_menu() {
static $admin_bar_menu;
if ( ! isset( $admin_bar_menu ) ) {
$admin_bar_menu = apply_filters(
'wp_mail_smtp_core_get_admin_bar_menu',
new AdminBarMenu()
);
if ( method_exists( $admin_bar_menu, 'init' ) ) {
$admin_bar_menu->init();
}
}
return $admin_bar_menu;
}
/**
* Load the plugin usage tracking.
*
* @since 2.3.0
*
* @return UsageTracking
*/
public function get_usage_tracking() {
static $usage_tracking;
if ( ! isset( $usage_tracking ) ) {
$usage_tracking = apply_filters( 'wp_mail_smtp_core_get_usage_tracking', new UsageTracking() );
if ( method_exists( $usage_tracking, 'load' ) ) {
$usage_tracking->load();
}
}
return $usage_tracking;
}
/**
* Load the plugin admin notifications functionality and initializes it.
*
* @since 2.3.0
*
* @return Notifications
*/
public function get_notifications() {
static $notifications;
if ( ! isset( $notifications ) ) {
$notifications = apply_filters(
'wp_mail_smtp_core_get_notifications',
new Notifications()
);
if ( method_exists( $notifications, 'init' ) ) {
$notifications->init();
}
}
return $notifications;
}
}

View File

@ -2,6 +2,8 @@
namespace WPMailSMTP;
use WPMailSMTP\UsageTracking\UsageTracking;
/**
* Class Options to handle all options management.
* WordPress does all the heavy work for caching get_option() data,
@ -51,6 +53,11 @@ class Options {
'client_id',
'client_secret',
],
'zoho' => [
'domain',
'client_id',
'client_secret',
],
'amazonses' => [
'client_id',
'client_secret',
@ -463,6 +470,24 @@ class Options {
break;
case 'zoho':
switch ( $key ) {
case 'domain':
/** No inspection comment @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_ZOHO_DOMAIN : $value;
break;
case 'client_id':
/** No inspection comment @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_ZOHO_CLIENT_ID : $value;
break;
case 'client_secret':
/** No inspection comment @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_ZOHO_CLIENT_SECRET : $value;
break;
}
break;
case 'amazonses':
switch ( $key ) {
case 'client_id':
@ -689,6 +714,21 @@ class Options {
break;
case 'zoho':
switch ( $key ) {
case 'domain':
$return = defined( 'WPMS_ZOHO_DOMAIN' ) && WPMS_ZOHO_DOMAIN;
break;
case 'client_id':
$return = defined( 'WPMS_ZOHO_CLIENT_ID' ) && WPMS_ZOHO_CLIENT_ID;
break;
case 'client_secret':
$return = defined( 'WPMS_ZOHO_CLIENT_SECRET' ) && WPMS_ZOHO_CLIENT_SECRET;
break;
}
break;
case 'amazonses':
switch ( $key ) {
case 'client_id':
@ -828,6 +868,7 @@ class Options {
case 'am_notifications_hidden':
case 'email_delivery_errors_hidden':
case 'uninstall':
case UsageTracking::SETTINGS_SLUG:
$options[ $group ][ $option_name ] = (bool) $option_value;
break;
}
@ -841,7 +882,7 @@ class Options {
if (
! empty( $options['mail']['mailer'] ) &&
isset( $options[ $options['mail']['mailer'] ] ) &&
in_array( $options['mail']['mailer'], array( 'pepipost', 'pepipostapi', 'smtp', 'sendgrid', 'smtpcom', 'sendinblue', 'mailgun', 'gmail', 'outlook' ), true )
in_array( $options['mail']['mailer'], [ 'pepipost', 'pepipostapi', 'smtp', 'sendgrid', 'smtpcom', 'sendinblue', 'mailgun', 'gmail', 'outlook', 'zoho' ], true )
) {
$mailer = $options['mail']['mailer'];
@ -870,16 +911,16 @@ class Options {
break;
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom.
case 'domain': // mailgun.
case 'client_id': // gmail/outlook/amazonses.
case 'client_secret': // gmail/outlook/amazonses.
case 'domain': // mailgun/zoho.
case 'client_id': // gmail/outlook/amazonses/zoho.
case 'client_secret': // gmail/outlook/amazonses/zoho.
case 'auth_code': // gmail/outlook.
case 'channel': // smtpcom.
$options[ $mailer ][ $option_name ] = $this->is_const_defined( $mailer, $option_name ) ? '' : sanitize_text_field( $option_value );
break;
case 'access_token': // gmail/outlook, array().
case 'user_details': // outlook, array().
case 'access_token': // gmail/outlook/zoho, is an array.
case 'user_details': // outlook/zoho, is an array.
case 'emails_pending': // amazonses, array().
// These options don't support constants.
$options[ $mailer ][ $option_name ] = $option_value;
@ -899,6 +940,8 @@ class Options {
// Now we need to re-cache values.
$this->populate_options();
do_action( 'wp_mail_smtp_options_set_after', $options );
}
/**
@ -961,6 +1004,25 @@ class Options {
return apply_filters( 'wp_mail_smtp_options_is_pepipost_active', $this->get( 'mail', 'mailer' ) === 'pepipost' );
}
/**
* Check whether the site is using provided mailer or not.
*
* @since 2.3.0
*
* @param string $mailer The mailer slug.
*
* @return bool
*/
public function is_mailer_active( $mailer ) {
$mailer = sanitize_key( $mailer );
return apply_filters(
"wp_mail_smtp_options_is_mailer_active_{$mailer}",
$this->get( 'mail', 'mailer' ) === $mailer
);
}
/**
* Check whether the site is using Pepipost/SMTP as a mailer or not.
*

View File

@ -21,15 +21,6 @@ class Processor {
*/
protected $wp_mail_from;
/**
* Processor constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->hooks();
}
/**
* Assign all hooks to proper places.
*
@ -152,8 +143,8 @@ class Processor {
if ( $mailer === 'gmail' ) {
$forced = true;
} elseif ( $mailer === 'outlook' ) {
$sender = $options->get( 'outlook', 'user_details' );
} elseif ( in_array( $mailer, [ 'outlook', 'zoho' ], true ) ) {
$sender = $options->get( $mailer, 'user_details' );
$from_email = ! empty( $sender['email'] ) ? $sender['email'] : '';
$forced = true;
}

View File

@ -22,33 +22,41 @@ class Options extends OptionsAbstract {
* Gmail Options constructor.
*
* @since 1.0.0
* @since 2.3.0 Added supports parameter.
*/
public function __construct() {
parent::__construct(
array(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/google.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'Gmail', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses( /* translators: %s - URL to our Gmail doc. */
__( 'Send emails using your Gmail or G Suite (formerly Google Apps) account, all while keeping your login credentials safe. Other Google SMTP methods require enabling less secure apps in your account and entering your password. However, this integration uses the Google API to improve email delivery issues while keeping your site secure.<br><br>Read our <a href="%s" target="_blank" rel="noopener noreferrer">Gmail documentation</a> to learn how to configure Gmail or G Suite.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
[
'br' => [],
'a' => [
'href' => [],
'rel' => [],
'target' => [],
],
]
),
'https://wpmailsmtp.com/docs/how-to-set-up-the-gmail-mailer-in-wp-mail-smtp/'
),
'notices' => array(
'notices' => [
'educational' => esc_html__( 'The Gmail mailer works well for sites that send low numbers of emails. However, Gmail\'s API has rate limitations and a number of additional restrictions that can lead to challenges during setup. If you expect to send a high volume of emails, or if you find that your web host is not compatible with the Gmail API restrictions, then we recommend considering a different mailer option.', 'wp-mail-smtp' ),
),
],
'php' => '5.5',
)
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
]
);
}
@ -109,7 +117,7 @@ class Options extends OptionsAbstract {
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"><?php esc_html_e( 'Authorized redirect URI', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<input type="text" readonly="readonly"
<input type="text" readonly="readonly" onfocus="this.select();"
value="<?php echo esc_attr( Auth::get_plugin_auth_url() ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_redirect"
/>

View File

@ -32,6 +32,7 @@ class Loader {
'amazonses' => 'WPMailSMTP\Providers\AmazonSES\\',
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
'outlook' => 'WPMailSMTP\Providers\Outlook\\',
'zoho' => 'WPMailSMTP\Providers\Zoho\\',
'smtp' => 'WPMailSMTP\Providers\SMTP\\',
'pepipost' => 'WPMailSMTP\Providers\Pepipost\\',
);
@ -56,6 +57,10 @@ class Loader {
unset( $this->providers['pepipost'] );
}
if ( ! Options::init()->is_mailer_active( 'pepipostapi' ) ) {
unset( $this->providers['pepipostapi'] );
}
return apply_filters( 'wp_mail_smtp_providers_loader_get_providers', $this->providers );
}
@ -200,4 +205,35 @@ class Loader {
return apply_filters( 'wp_mail_smtp_providers_loader_get_entity', $entity, $provider, $request );
}
/**
* Get supports options for all mailers.
*
* @since 2.3.0
*
* @return array
*/
public function get_supports_all() {
$supports = [];
foreach ( $this->get_providers() as $provider => $path ) {
$option = $this->get_options( $provider );
if ( ! $option instanceof OptionsAbstract ) {
continue;
}
$mailer_slug = $option->get_slug();
$mailer_supports = $option->get_supports();
if ( empty( $mailer_slug ) || empty( $mailer_supports ) ) {
continue;
}
$supports[ $mailer_slug ] = $mailer_supports;
}
return apply_filters( 'wp_mail_smtp_providers_loader_get_supports_all', $supports );
}
}

View File

@ -54,12 +54,22 @@ abstract class OptionsAbstract implements OptionsInterface {
*/
protected $options;
/**
* An array with mailer supported setting fields.
*
* @since 2.3.0
*
* @var array
*/
protected $supports;
/**
* ProviderAbstract constructor.
*
* @since 1.0.0
* @since 2.3.0 Added supports parameter.
*
* @param array $params
* @param array $params The mailer options parameters.
*/
public function __construct( $params ) {
@ -120,6 +130,8 @@ abstract class OptionsAbstract implements OptionsInterface {
$this->logo_url = esc_url_raw( $params['logo_url'] );
}
$this->supports = ( ! empty( $params['supports'] ) ) ? $params['supports'] : $this->get_supports_defaults();
$this->options = new Options();
}
@ -474,4 +486,33 @@ abstract class OptionsAbstract implements OptionsInterface {
<?php
}
/**
* Return the defaults for the mailer supported settings.
*
* @since 2.3.0
*
* @return array
*/
public function get_supports_defaults() {
return [
'from_email' => true,
'from_name' => true,
'return_path' => true,
'from_email_force' => true,
'from_name_force' => true,
];
}
/**
* Get the mailer supported settings.
*
* @since 2.3.0
*
* @return array
*/
public function get_supports() {
return apply_filters( 'wp_mail_smtp_providers_provider_get_supports', $this->supports, $this );
}
}

View File

@ -1,64 +1,71 @@
<?php
namespace WPMailSMTP\Providers;
/**
* Interface ProviderInterface, shared between all current and future providers.
* Defines required methods across all providers.
*
* @since 1.0.0
*/
interface OptionsInterface {
/**
* Get the mailer provider slug.
*
* @since 1.0.0
*
* @return string
*/
public function get_slug();
/**
* Get the mailer provider title (or name).
*
* @since 1.0.0
*
* @return string
*/
public function get_title();
/**
* Get the mailer provider description.
*
* @since 1.0.0
*
* @return string
*/
public function get_description();
/**
* Get the mailer provider minimum PHP version.
*
* @since 1.0.0
*
* @return string
*/
public function get_php_version();
/**
* Get the mailer provider logo URL.
*
* @since 1.0.0
*
* @return string
*/
public function get_logo_url();
/**
* Output the mailer provider options.
*
* @since 1.0.0
*/
public function display_options();
}
<?php
namespace WPMailSMTP\Providers;
/**
* Interface ProviderInterface, shared between all current and future providers.
* Defines required methods across all providers.
*
* @since 1.0.0
*/
interface OptionsInterface {
/**
* Get the mailer provider slug.
*
* @since 1.0.0
*
* @return string
*/
public function get_slug();
/**
* Get the mailer provider title (or name).
*
* @since 1.0.0
*
* @return string
*/
public function get_title();
/**
* Get the mailer provider description.
*
* @since 1.0.0
*
* @return string
*/
public function get_description();
/**
* Get the mailer provider minimum PHP version.
*
* @since 1.0.0
*
* @return string
*/
public function get_php_version();
/**
* Get the mailer provider logo URL.
*
* @since 1.0.0
*
* @return string
*/
public function get_logo_url();
/**
* Output the mailer provider options.
*
* @since 1.0.0
*/
public function display_options();
/**
* Get the mailer supported settings.
*
* @since 2.3.0
*/
public function get_supports();
}

View File

@ -23,19 +23,19 @@ class Options extends OptionsAbstract {
* Options constructor.
*
* @since 1.8.0
* @since 2.3.0 Added 'supports' parameter.
*/
public function __construct() {
$description = sprintf(
wp_kses( /* translators: %1$s - URL to pepipost.com site. */
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">Pepipost</a> is a recommended transactional email service.</strong> Every month Pepipost delivers over 8 billion emails from 20,000+ customers. Their mission is to reliably send emails in the most efficient way and at the most disruptive pricing ever. Pepipost provides users 30,000 free emails the first 30 days.', 'wp-mail-smtp' ) .
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Pepipost</a> is a transactional email service. Every month Pepipost delivers over 8 billion emails from 20,000+ customers. Their mission is to reliably send emails in the most efficient way and at the most disruptive pricing ever. Pepipost provides users 30,000 free emails the first 30 days.', 'wp-mail-smtp' ) .
'<br><br>' .
/* translators: %1$s - URL to wpmailsmtp.com doc. */
__( 'Read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Pepipost documentation</a> to learn how to configure Pepipost and improve your email deliverability.', 'wp-mail-smtp' ),
array(
'br' => true,
'strong' => true,
'a' => array(
'br' => true,
'a' => array(
'href' => true,
'rel' => true,
'target' => true,
@ -55,14 +55,20 @@ class Options extends OptionsAbstract {
}
parent::__construct(
array(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/pepipost.png',
'slug' => self::SLUG,
'title' => esc_html__( 'Pepipost', 'wp-mail-smtp' ),
'description' => $description,
'recommended' => true,
'php' => '5.3',
)
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
]
);
}

View File

@ -23,6 +23,7 @@ class Options extends OptionsAbstract {
* Options constructor.
*
* @since 2.0.0
* @since 2.3.0 Added supports parameter.
*/
public function __construct() {
@ -61,13 +62,20 @@ class Options extends OptionsAbstract {
}
parent::__construct(
array(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp-com.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'SMTP.com', 'wp-mail-smtp' ),
'description' => $description,
'recommended' => true,
)
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
]
);
}

View File

@ -1,96 +1,104 @@
<?php
namespace WPMailSMTP\Providers\Sendgrid;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Options constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendgrid.svg',
'slug' => 'sendgrid',
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses(
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
__( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per day.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
array(
'br' => array(),
'a' => array(
'href' => array(),
'rel' => array(),
'target' => array(),
),
)
),
'<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
'</a>',
'<a href="https://wpmailsmtp.com/docs/how-to-set-up-the-sendgrid-mailer-in-wp-mail-smtp/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<!-- API Key -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
<input type="text" disabled value="****************************************"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php $this->display_const_set_message( 'WPMS_SENDGRID_API_KEY' ); ?>
<?php else : ?>
<input type="password" spellcheck="false"
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php endif; ?>
<p class="desc">
<?php
printf(
/* translators: %s - API key link. */
esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
'<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
'</a>'
);
?>
<br/>
<?php
printf(
/* translators: %s - SendGrid access level. */
esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
'<code>Mail Send</code>'
);
?>
</p>
</div>
</div>
<?php
}
}
<?php
namespace WPMailSMTP\Providers\Sendgrid;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Options constructor.
*
* @since 1.0.0
* @since 2.3.0 Added supports parameter.
*/
public function __construct() {
parent::__construct(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendgrid.svg',
'slug' => 'sendgrid',
'title' => esc_html__( 'SendGrid', 'wp-mail-smtp' ),
'description' => sprintf(
wp_kses(
/* translators: %1$s - opening link tag; %2$s - closing link tag; %3$s - opening link tag; %4$s - closing link tag. */
__( '%1$sSendGrid%2$s is one of the leading transactional email services, sending over 35 billion emails every month. They provide users 100 free emails per day.<br><br>Read our %3$sSendGrid documentation%4$s to learn how to set up SendGrid and improve your email deliverability.', 'wp-mail-smtp' ),
[
'br' => [],
'a' => [
'href' => [],
'rel' => [],
'target' => [],
],
]
),
'<a href="https://sendgrid.com" target="_blank" rel="noopener noreferrer">',
'</a>',
'<a href="https://wpmailsmtp.com/docs/how-to-set-up-the-sendgrid-mailer-in-wp-mail-smtp/" target="_blank" rel="noopener noreferrer">',
'</a>'
),
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
]
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<!-- API Key -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-api_key" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear">
<div class="wp-mail-smtp-setting-label">
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'API Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
<input type="text" disabled value="****************************************"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php $this->display_const_set_message( 'WPMS_SENDGRID_API_KEY' ); ?>
<?php else : ?>
<input type="password" spellcheck="false"
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php endif; ?>
<p class="desc">
<?php
printf(
/* translators: %s - API key link. */
esc_html__( 'Follow this link to get an API Key from SendGrid: %s.', 'wp-mail-smtp' ),
'<a href="https://app.sendgrid.com/settings/api_keys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Create API Key', 'wp-mail-smtp' ) .
'</a>'
);
?>
<br/>
<?php
printf(
/* translators: %s - SendGrid access level. */
esc_html__( 'To send emails you will need only a %s access level for this API key.', 'wp-mail-smtp' ),
'<code>Mail Send</code>'
);
?>
</p>
</div>
</div>
<?php
}
}

View File

@ -23,11 +23,12 @@ class Options extends OptionsAbstract {
* Options constructor.
*
* @since 1.6.0
* @since 2.3.0 Added supports parameter.
*/
public function __construct() {
parent::__construct(
array(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendinblue.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'Sendinblue', 'wp-mail-smtp' ),
@ -38,19 +39,26 @@ class Options extends OptionsAbstract {
'<br><br>' .
/* translators: %2$s - URL to wpmailsmtp.com doc. */
__( 'Read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Sendinblue documentation</a> to learn how to configure Sendinblue and improve your email deliverability.', 'wp-mail-smtp' ),
array(
[
'br' => true,
'a' => array(
'a' => [
'href' => true,
'rel' => true,
'target' => true,
),
)
],
]
),
'https://wpmailsmtp.com/go/sendinblue/',
'https://wpmailsmtp.com/docs/how-to-set-up-the-sendinblue-mailer-in-wp-mail-smtp'
),
)
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
]
);
}

View File

@ -0,0 +1,46 @@
<?php
namespace WPMailSMTP\Providers\Zoho;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 2.3.0
*/
class Options extends OptionsAbstract {
/**
* Zoho Options constructor.
*
* @since 2.3.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/zoho.svg',
'slug' => 'zoho',
'title' => esc_html__( 'Zoho Mail', 'wp-mail-smtp' ),
'disabled' => true,
)
);
}
/**
* {@inheritdoc}
*
* @since 2.3.0
*/
public function display_options() {
?>
<p>
<?php esc_html_e( 'We\'re sorry, the Zoho Mail mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
</p>
<?php
}
}

View File

@ -114,6 +114,17 @@ class SiteHealth {
],
];
// Install date.
$activated = get_option( 'wp_mail_smtp_activated', [] );
if ( ! empty( $activated['lite'] ) ) {
$date = $activated['lite'] + ( get_option( 'gmt_offset' ) * 3600 );
$debug_info[ self::DEBUG_INFO_SLUG ]['fields']['lite_install_date'] = [
'label' => esc_html__( 'Lite install date', 'wp-mail-smtp' ),
'value' => date_i18n( esc_html__( 'M j, Y @ g:ia' ), $date ),
];
}
return $debug_info;
}
@ -125,12 +136,19 @@ class SiteHealth {
public function mailer_setup_complete_test() {
$mailer = Options::init()->get( 'mail', 'mailer' );
$mailer_complete = wp_mail_smtp()
->get_providers()
->get_mailer(
$mailer,
wp_mail_smtp()->get_processor()->get_phpmailer()
)->is_mailer_complete();
$mailer_complete = false;
$mailer_title = esc_html__( 'None selected', 'wp-mail-smtp' );
if ( ! empty( $mailer ) ) {
$mailer_complete = wp_mail_smtp()
->get_providers()
->get_mailer(
$mailer,
wp_mail_smtp()->get_processor()->get_phpmailer()
)->is_mailer_complete();
$mailer_title = wp_mail_smtp()->get_providers()->get_options( $mailer )->get_title();
}
// The default mailer should be considered as a non-complete mailer.
if ( $mailer === 'mail' ) {
@ -140,7 +158,7 @@ class SiteHealth {
$mailer_text = sprintf(
'%s: <strong>%s</strong>',
esc_html__( 'Current mailer', 'wp-mail-smtp' ),
esc_html( wp_mail_smtp()->get_providers()->get_options( $mailer )->get_title() )
esc_html( $mailer_title )
);
$result = array(
@ -250,7 +268,9 @@ class SiteHealth {
$existing_tables = [];
foreach ( $tables as $table ) {
if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) !== $table ) { // phpcs:ignore
$db_result = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ); // phpcs:ignore
if ( strtolower( $db_result ) !== strtolower( $table ) ) {
$missing_tables[] = $table;
} else {
$existing_tables[] = $table;

View File

@ -385,7 +385,9 @@ class Meta {
}
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
return $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table;
$db_result = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) );
return strtolower( $db_result ) === strtolower( $table );
}
/**

View File

@ -203,18 +203,23 @@ class Task {
return $action_id;
}
switch ( $this->type ) {
case self::TYPE_ASYNC:
$action_id = $this->register_async();
break;
// Prevent 500 errors when Action Scheduler tables don't exist.
try {
switch ( $this->type ) {
case self::TYPE_ASYNC:
$action_id = $this->register_async();
break;
case self::TYPE_RECURRING:
$action_id = $this->register_recurring();
break;
case self::TYPE_RECURRING:
$action_id = $this->register_recurring();
break;
case self::TYPE_ONCE:
$action_id = $this->register_once();
break;
case self::TYPE_ONCE:
$action_id = $this->register_once();
break;
}
} catch ( \RuntimeException $exception ) {
$action_id = null;
}
return $action_id;

View File

@ -23,6 +23,14 @@ class Tasks {
*/
public function init() {
// Hide the Action Scheduler admin menu item.
add_action( 'admin_menu', array( $this, 'admin_hide_as_menu' ), PHP_INT_MAX );
// Skip tasks registration if Action Scheduler is not usable yet.
if ( ! $this->is_usable() ) {
return;
}
// Register tasks.
foreach ( $this->get_tasks() as $task ) {
if ( ! is_subclass_of( $task, '\WPMailSMTP\Tasks\Task' ) ) {
@ -36,8 +44,6 @@ class Tasks {
$new_task->init();
}
}
add_action( 'admin_menu', array( $this, 'admin_hide_as_menu' ), PHP_INT_MAX );
}
/**

View File

@ -0,0 +1,105 @@
<?php
namespace WPMailSMTP\UsageTracking;
use WPMailSMTP\Tasks\Task;
/**
* Class SendUsageTask.
*
* @since 2.3.0
*/
class SendUsageTask extends Task {
/**
* Action name for this task.
*
* @since 2.3.0
*/
const ACTION = 'wp_mail_smtp_send_usage_data';
/**
* Server URL to send requests to.
*
* @since 2.3.0
*
* @var string
*/
const TRACK_URL = 'https://usage.wpmailsmtp.com/v1/smtptrack';
/**
* Class constructor.
*
* @since 2.3.0
*/
public function __construct() {
parent::__construct( self::ACTION );
}
/**
* Initialize the task with all the proper checks.
*
* @since 2.3.0
*/
public function init() {
// Register the action handler.
add_action( self::ACTION, [ $this, 'process' ] );
if ( ! function_exists( 'as_next_scheduled_action' ) ) {
return;
}
// Add new if none exists.
if ( as_next_scheduled_action( self::ACTION ) !== false ) {
return;
}
$this->recurring( $this->generate_start_date(), WEEK_IN_SECONDS )
->register();
}
/**
* Randomly pick a timestamp
* which is not more than 1 week in the future
* starting from next sunday.
*
* @since 2.3.0
*
* @return int
*/
private function generate_start_date() {
$tracking = [];
$tracking['days'] = wp_rand( 0, 6 ) * DAY_IN_SECONDS;
$tracking['hours'] = wp_rand( 0, 23 ) * HOUR_IN_SECONDS;
$tracking['minutes'] = wp_rand( 0, 59 ) * MINUTE_IN_SECONDS;
$tracking['seconds'] = wp_rand( 0, 59 );
return strtotime( 'next sunday' ) + array_sum( $tracking );
}
/**
* Send the actual data in a POST request.
* This will be executed in a separate process via Action Scheduler.
*
* @since 2.3.0
*/
public function process() {
$ut = new UsageTracking();
wp_remote_post(
self::TRACK_URL,
[
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.1',
'blocking' => true,
'body' => $ut->get_data(),
'user-agent' => $ut->get_user_agent(),
]
);
}
}

View File

@ -0,0 +1,250 @@
<?php
namespace WPMailSMTP\UsageTracking;
use WPMailSMTP\Conflicts;
use WPMailSMTP\Options;
use WPMailSMTP\WP;
/**
* Usage Tracker functionality to understand what's going on on client's sites.
*
* @since 2.3.0
*/
class UsageTracking {
/**
* The slug that will be used to save the option of Usage Tracker.
*
* @since 2.3.0
*/
const SETTINGS_SLUG = 'usage-tracking-enabled';
/**
* Whether Usage Tracking is enabled.
* Needs to check with a fresh copy of options in order to provide accurate results.
*
* @since 2.3.0
*
* @return bool
*/
public function is_enabled() {
return (bool) apply_filters(
'wp_mail_smtp_usage_tracking_is_enabled',
( new Options() )->get( 'general', self::SETTINGS_SLUG )
);
}
/**
* Load usage tracking functionality.
*
* @since 2.3.0
*/
public function load() {
// Check if loading the usage tracking functionality is allowed.
if ( ! (bool) apply_filters( 'wp_mail_smtp_usage_tracking_load_allowed', true ) ) {
return;
}
// Deregister the action if option is disabled.
add_action(
'wp_mail_smtp_options_set_after',
function () {
if ( ! $this->is_enabled() ) {
( new SendUsageTask() )->cancel();
}
}
);
// Register the action handler only if enabled.
if ( $this->is_enabled() ) {
add_filter(
'wp_mail_smtp_tasks_get_tasks',
static function ( $tasks ) {
$tasks[] = SendUsageTask::class;
return $tasks;
}
);
}
}
/**
* Get the User Agent string that will be sent to the API.
*
* @since 2.3.0
*
* @return string
*/
public function get_user_agent() {
return 'WPMailSMTP/' . WPMS_PLUGIN_VER . '; ' . get_bloginfo( 'url' );
}
/**
* Get data for sending to the server.
*
* @since 2.3.0
*
* @return array
*/
public function get_data() {
global $wpdb;
$theme_data = wp_get_theme();
$activated_dates = get_option( 'wp_mail_smtp_activated', [] );
$options = Options::init();
$mailer = wp_mail_smtp()->get_providers()->get_mailer(
$options->get( 'mail', 'mailer' ),
wp_mail_smtp()->get_processor()->get_phpmailer()
);
$data = [
// Generic data (environment).
'url' => home_url(),
'php_version' => PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION,
'wp_version' => get_bloginfo( 'version' ),
'mysql_version' => $wpdb->db_version(),
'server_version' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '',
'is_ssl' => is_ssl(),
'is_multisite' => is_multisite(),
'sites_count' => $this->get_sites_total(),
'active_plugins' => $this->get_active_plugins(),
'theme_name' => $theme_data->name,
'theme_version' => $theme_data->version,
'locale' => get_locale(),
'timezone_offset' => $this->get_timezone_offset(),
// WP Mail SMTP - specific data.
'wp_mail_smtp_version' => WPMS_PLUGIN_VER,
'wp_mail_smtp_license_key' => wp_mail_smtp()->get_license_key(),
'wp_mail_smtp_license_type' => wp_mail_smtp()->get_license_type(),
'wp_mail_smtp_is_pro' => wp_mail_smtp()->is_pro(),
'wp_mail_smtp_activated' => get_option( 'wp_mail_smtp_activated_time', 0 ),
'wp_mail_smtp_lite_installed_date' => $this->get_installed( $activated_dates, 'lite' ),
'wp_mail_smtp_pro_installed_date' => $this->get_installed( $activated_dates, 'pro' ),
'wp_mail_smtp_mailer' => $options->get( 'mail', 'mailer' ),
'wp_mail_smtp_from_email_force' => (bool) $options->get( 'mail', 'from_email_force' ),
'wp_mail_smtp_from_name_force' => (bool) $options->get( 'mail', 'from_name_force' ),
'wp_mail_smtp_return_path' => (bool) $options->get( 'mail', 'return_path' ),
'wp_mail_smtp_do_not_send' => (bool) $options->get( 'general', 'do_not_send' ),
'wp_mail_smtp_is_white_labeled' => wp_mail_smtp()->is_white_labeled(),
'wp_mail_smtp_is_const_enabled' => (bool) $options->is_const_enabled(),
'wp_mail_smtp_conflicts_is_detected' => ( new Conflicts() )->is_detected(),
'wp_mail_smtp_is_mailer_complete' => empty( $mailer ) ? false : $mailer->is_mailer_complete(),
];
if ( 'smtp' === $options->get( 'mail', 'mailer' ) ) {
$data['wp_mail_smtp_other_smtp_host'] = $options->get( 'smtp', 'host' );
$data['wp_mail_smtp_other_smtp_encryption'] = $options->get( 'smtp', 'encryption' );
$data['wp_mail_smtp_other_smtp_port'] = $options->get( 'smtp', 'port' );
$data['wp_mail_smtp_other_smtp_auth'] = (bool) $options->get( 'smtp', 'auth' );
$data['wp_mail_smtp_other_smtp_autotls'] = (bool) $options->get( 'smtp', 'autotls' );
}
if ( is_multisite() ) {
$data['wp_mail_smtp_multisite_network_wide'] = WP::use_global_plugin_settings();
}
return apply_filters( 'wp_mail_smtp_usage_tracking_get_data', $data );
}
/**
* Get timezone offset.
* We use `wp_timezone_string()` when it's available (WP 5.3+),
* otherwise fallback to the same code, copy-pasted.
*
* @since 2.3.0
*
* @return string
*/
private function get_timezone_offset() {
// It was added in WordPress 5.3.
if ( function_exists( 'wp_timezone_string' ) ) {
return wp_timezone_string();
}
/*
* The code below is basically a copy-paste from that function.
*/
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
return $timezone_string;
}
$offset = (float) get_option( 'gmt_offset' );
$hours = (int) $offset;
$minutes = ( $offset - $hours );
$sign = ( $offset < 0 ) ? '-' : '+';
$abs_hour = abs( $hours );
$abs_mins = abs( $minutes * 60 );
return sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
}
/**
* Get the list of active plugins.
*
* @since 2.3.0
*
* @return array
*/
private function get_active_plugins() {
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$active_plugins = [];
foreach ( get_mu_plugins() as $path => $plugin ) {
$active_plugins[ $path ] = isset( $plugin['Version'] ) ? $plugin['Version'] : 'Not Set';
}
foreach ( get_plugins() as $path => $plugin ) {
if ( is_plugin_active( $path ) ) {
$active_plugins[ $path ] = isset( $plugin['Version'] ) ? $plugin['Version'] : 'Not Set';
}
}
return $active_plugins;
}
/**
* Installed date.
*
* @since 2.3.0
*
* @param array $activated_dates Input array with dates.
* @param string $key Input key what you want to get.
*
* @return mixed
*/
private function get_installed( $activated_dates, $key ) {
if ( ! empty( $activated_dates[ $key ] ) ) {
return $activated_dates[ $key ];
}
return false;
}
/**
* Total number of sites.
*
* @since 2.3.0
*
* @return int
*/
private function get_sites_total() {
return function_exists( 'get_blog_count' ) ? (int) get_blog_count() : 1;
}
}

View File

@ -247,12 +247,17 @@ class WP {
* @see https://github.com/WordPress/WordPress/blob/master/wp-includes/pluggable.php#L332
*
* @since 2.2.0
* @since 2.3.0 In WP 5.5 the core code changed and is now using `network_home_url`.
*
* @return string
*/
public static function get_default_email() {
$sitename = strtolower( $_SERVER['SERVER_NAME'] ); // phpcs:ignore
if ( version_compare( get_bloginfo( 'version' ), '5.5-alpha', '<' ) ) {
$sitename = strtolower( $_SERVER['SERVER_NAME'] ); // phpcs:ignore
} else {
$sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
}
if ( 'www.' === substr( $sitename, 0, 4 ) ) {
$sitename = substr( $sitename, 4 );