rebase code on oct-10-2023
This commit is contained in:
@@ -95,9 +95,6 @@ class Area {
|
||||
// Display notice instructing the user to complete plugin setup.
|
||||
add_action( 'admin_init', [ $this, 'display_setup_notice' ] );
|
||||
|
||||
// Display notice explaining removal of "Email Test" tab.
|
||||
add_action( 'admin_init', [ $this, 'display_email_test_tab_removal_notice' ] );
|
||||
|
||||
// Outputs the plugin admin header.
|
||||
add_action( 'in_admin_header', [ $this, 'display_admin_header' ], 100 );
|
||||
|
||||
@@ -107,6 +104,9 @@ class Area {
|
||||
// Process all AJAX requests.
|
||||
add_action( 'wp_ajax_wp_mail_smtp_ajax', [ $this, 'process_ajax' ] );
|
||||
|
||||
// Maybe redirect to "Tools -> Email Test" page if old direct URL to "Settings -> Email Test" is accessed.
|
||||
add_action( 'admin_init', [ $this, 'maybe_redirect_test_tab' ] );
|
||||
|
||||
// Init parent admin pages.
|
||||
if ( WP::in_wp_admin() || WP::is_doing_self_ajax() ) {
|
||||
add_action( 'init', [ $this, 'get_parent_pages' ] );
|
||||
@@ -221,36 +221,6 @@ class Area {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display notice explaining removal of "Email Test" tab.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*/
|
||||
public function display_email_test_tab_removal_notice() {
|
||||
|
||||
// Bail if we aren't on a "Settings" page.
|
||||
if ( ! $this->is_admin_page( self::SLUG ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Bail if the notice has been dismissed.
|
||||
if ( metadata_exists( 'user', get_current_user_id(), 'wp_mail_smtp_email_test_tab_removal_notice_dismissed' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
WP::add_admin_notice(
|
||||
sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s: Tools page URL. */
|
||||
__( 'The Email Test tab was moved to <a href="%s">WP Mail SMTP > Tools</a>.', 'wp-mail-smtp' ),
|
||||
[ 'a' => [ 'href' => [] ] ]
|
||||
),
|
||||
$this->get_admin_page_url( self::SLUG . '-tools' )
|
||||
),
|
||||
implode( ' ', [ WP::ADMIN_NOTICE_INFO, 'email_test_tab_removal_notice' ] )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get menu item position.
|
||||
*
|
||||
@@ -556,13 +526,13 @@ class Area {
|
||||
*/
|
||||
wp_enqueue_style(
|
||||
'wp-mail-smtp-admin-jconfirm',
|
||||
wp_mail_smtp()->assets_url . '/css/vendor/jquery-confirm.min.css',
|
||||
wp_mail_smtp()->assets_url . '/libs/jquery-confirm.min.css',
|
||||
[ 'wp-mail-smtp-admin' ],
|
||||
'3.3.4'
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'wp-mail-smtp-admin-jconfirm',
|
||||
wp_mail_smtp()->assets_url . '/js/vendor/jquery-confirm.min.js',
|
||||
wp_mail_smtp()->assets_url . '/libs/jquery-confirm.min.js',
|
||||
[ 'wp-mail-smtp-admin' ],
|
||||
'3.3.4',
|
||||
false
|
||||
@@ -950,6 +920,7 @@ class Area {
|
||||
if ( empty( $this->pages ) ) {
|
||||
$this->pages = [
|
||||
'settings' => new Pages\SettingsTab(),
|
||||
'test' => new Pages\TestTab( new Pages\Tools() ),
|
||||
'logs' => new Pages\LogsTab(),
|
||||
'alerts' => new Pages\AlertsTab(),
|
||||
'connections' => new Pages\AdditionalConnectionsTab(),
|
||||
@@ -1160,14 +1131,6 @@ class Area {
|
||||
$data['message'] = $dismissal_response;
|
||||
break;
|
||||
|
||||
case 'email_test_tab_removal_notice_dismiss':
|
||||
if ( ! check_ajax_referer( 'wp-mail-smtp-admin', 'nonce', false ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
update_user_meta( get_current_user_id(), 'wp_mail_smtp_email_test_tab_removal_notice_dismissed', true );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Allow custom tasks data processing being added here.
|
||||
$data = apply_filters( 'wp_mail_smtp_admin_process_ajax_' . $task . '_data', $data );
|
||||
@@ -1226,7 +1189,7 @@ class Area {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$custom['wp-mail-smtp-pro'] = sprintf(
|
||||
$custom['pro'] = sprintf(
|
||||
'<a href="%1$s" aria-label="%2$s" target="_blank" rel="noopener noreferrer"
|
||||
style="color: #00a32a; font-weight: 700;"
|
||||
onmouseover="this.style.color=\'#008a20\';"
|
||||
@@ -1238,14 +1201,14 @@ class Area {
|
||||
esc_html__( 'Get WP Mail SMTP Pro', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
$custom['wp-mail-smtp-settings'] = sprintf(
|
||||
$custom['settings'] = sprintf(
|
||||
'<a href="%s" aria-label="%s">%s</a>',
|
||||
esc_url( $this->get_admin_page_url() ),
|
||||
esc_attr__( 'Go to WP Mail SMTP Settings page', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Settings', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
$custom['wp-mail-smtp-docs'] = sprintf(
|
||||
$custom['docs'] = sprintf(
|
||||
'<a href="%1$s" target="_blank" aria-label="%2$s" rel="noopener noreferrer">%3$s</a>',
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/', [ 'medium' => 'all-plugins', 'content' => 'Documentation' ] ) ),
|
||||
@@ -1337,14 +1300,10 @@ class Area {
|
||||
/**
|
||||
* Maybe redirect to "Tools -> Email Test" page if old direct URL to "Settings -> Email Test" is accessed.
|
||||
*
|
||||
* @deprecated 3.9.0
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function maybe_redirect_test_tab() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
if ( $this->is_admin_page( 'general' ) && $this->get_current_tab() === 'test' ) {
|
||||
wp_safe_redirect( add_query_arg( 'tab', 'test', $this->get_admin_page_url( self::SLUG . '-tools' ) ) );
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace WPMailSMTP\Admin;
|
||||
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
@@ -176,8 +175,7 @@ class DashboardWidget {
|
||||
unset( $normal_dashboard[ $widget_key ] );
|
||||
$sorted_dashboard = array_merge( $widget_instance, $normal_dashboard );
|
||||
|
||||
//phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
|
||||
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; //phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +258,8 @@ class DashboardWidget {
|
||||
*/
|
||||
private function widget_content_html() {
|
||||
|
||||
$hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
|
||||
$hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
|
||||
$hide_summary_report_email_block = (bool) $this->widget_meta( 'get', 'hide_summary_report_email_block' );
|
||||
?>
|
||||
|
||||
<?php if ( ! $hide_graph ) : ?>
|
||||
@@ -302,155 +301,37 @@ class DashboardWidget {
|
||||
<?php $this->email_stats_block(); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$this->display_after_email_stats_block_content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the content after the email stats block.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function display_after_email_stats_block_content() {
|
||||
|
||||
if ( empty( $this->widget_meta( 'get', 'hide_email_alerts_banner' ) ) ) {
|
||||
// Check if we have error debug events.
|
||||
$error_debug_events_count = DebugEvents::get_error_debug_events_count();
|
||||
|
||||
if ( ! is_wp_error( $error_debug_events_count ) && ! empty( $error_debug_events_count ) ) {
|
||||
$this->show_email_alerts_banner( $error_debug_events_count );
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$hide_summary_report_email_block = (bool) $this->widget_meta( 'get', 'hide_summary_report_email_block' );
|
||||
|
||||
if ( SummaryReportEmail::is_disabled() && ! $hide_summary_report_email_block ) {
|
||||
$this->show_summary_report_email_block();
|
||||
}
|
||||
|
||||
$this->show_upgrade_footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the email alerts banner.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param int $error_count The number of debug events error.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function show_email_alerts_banner( $error_count ) {
|
||||
|
||||
?>
|
||||
<div id="wp-mail-smtp-dash-widget-email-alerts-education" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-email-alerts-education">
|
||||
<div class="wp-mail-smtp-dash-widget-email-alerts-education-error-icon">
|
||||
<?php
|
||||
printf(
|
||||
'<img src="%s" alt="%s"/>',
|
||||
esc_url( wp_mail_smtp()->assets_url . '/images/dash-widget/error-icon.svg' ),
|
||||
esc_attr__( 'Error icon', 'wp-mail-smtp' )
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-dash-widget-email-alerts-education-content">
|
||||
<?php
|
||||
if ( $error_count === 1 ) {
|
||||
$error_title = __( 'We detected a failed email in the last 30 days.', 'wp-mail-smtp' );
|
||||
} else {
|
||||
$error_title = sprintf(
|
||||
/* translators: %d - number of failed emails. */
|
||||
__( 'We detected %d failed emails in the last 30 days.', 'wp-mail-smtp' ),
|
||||
$error_count
|
||||
);
|
||||
}
|
||||
|
||||
$content = sprintf(
|
||||
/* translators: %s - URL to WPMailSMTP.com. */
|
||||
__( '<a href="%s" target="_blank" rel="noopener noreferrer">Upgrade to Pro</a> and get instant alert notifications when they fail.', 'wp-mail-smtp' ),
|
||||
esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'alerts-promo-upgrade-to-pro' ] ) ) // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
);
|
||||
?>
|
||||
<p>
|
||||
<strong><?php echo esc_html( $error_title ); ?></strong><br />
|
||||
<?php
|
||||
echo wp_kses(
|
||||
$content,
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'target' => [],
|
||||
'rel' => [],
|
||||
],
|
||||
]
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button type="button" id="wp-mail-smtp-dash-widget-dismiss-email-alert-block" class="wp-mail-smtp-dash-widget-dismiss-email-alert-block" title="<?php esc_attr_e( 'Dismiss email alert block', 'wp-mail-smtp' ); ?>">
|
||||
<span class="dashicons dashicons-no-alt"></span>
|
||||
</button>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the summary report email block.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function show_summary_report_email_block() {
|
||||
|
||||
?>
|
||||
<div id="wp-mail-smtp-dash-widget-summary-report-email-block" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-summary-report-email-block">
|
||||
<div>
|
||||
<div class="wp-mail-smtp-dash-widget-summary-report-email-block-setting">
|
||||
<label for="wp-mail-smtp-dash-widget-summary-report-email-enable">
|
||||
<input type="checkbox" id="wp-mail-smtp-dash-widget-summary-report-email-enable">
|
||||
<i class="wp-mail-smtp-dash-widget-loader"></i>
|
||||
<span>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( '<b>NEW!</b> Enable Weekly Email Summaries', 'wp-mail-smtp' ),
|
||||
[
|
||||
'b' => [],
|
||||
]
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
</label>
|
||||
<a href="<?php echo esc_url( SummaryReportEmail::get_preview_link() ); ?>" target="_blank">
|
||||
<?php esc_html_e( 'View Example', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<i class="dashicons dashicons-dismiss wp-mail-smtp-dash-widget-summary-report-email-dismiss"></i>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-dash-widget-summary-report-email-block-applied hidden">
|
||||
<i class="wp-mail-smtp-dashicons-yes-alt-green"></i>
|
||||
<span><?php esc_attr_e( 'Weekly Email Summaries have been enabled', 'wp-mail-smtp' ); ?></span>
|
||||
<?php if ( SummaryReportEmail::is_disabled() && ! $hide_summary_report_email_block ) : ?>
|
||||
<div id="wp-mail-smtp-dash-widget-summary-report-email-block" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-summary-report-email-block">
|
||||
<div>
|
||||
<div class="wp-mail-smtp-dash-widget-summary-report-email-block-setting">
|
||||
<label for="wp-mail-smtp-dash-widget-summary-report-email-enable">
|
||||
<input type="checkbox" id="wp-mail-smtp-dash-widget-summary-report-email-enable">
|
||||
<i class="wp-mail-smtp-dash-widget-loader"></i>
|
||||
<span>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( '<b>NEW!</b> Enable Weekly Email Summaries', 'wp-mail-smtp' ),
|
||||
[
|
||||
'b' => [],
|
||||
]
|
||||
);
|
||||
?>
|
||||
</span>
|
||||
</label>
|
||||
<a href="<?php echo esc_url( SummaryReportEmail::get_preview_link() ); ?>" target="_blank">
|
||||
<?php esc_html_e( 'View Example', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
<i class="dashicons dashicons-dismiss wp-mail-smtp-dash-widget-summary-report-email-dismiss"></i>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-dash-widget-summary-report-email-block-applied hidden">
|
||||
<i class="wp-mail-smtp-dashicons-yes-alt-green"></i>
|
||||
<span><?php esc_attr_e( 'Weekly Email Summaries have been enabled', 'wp-mail-smtp' ); ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
<?php endif; ?>
|
||||
|
||||
/**
|
||||
* Show the upgrade footer.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function show_upgrade_footer() {
|
||||
|
||||
$hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' );
|
||||
?>
|
||||
<div id="wp-mail-smtp-dash-widget-upgrade-footer" class="wp-mail-smtp-dash-widget-block wp-mail-smtp-dash-widget-upgrade-footer wp-mail-smtp-dash-widget-upgrade-footer--<?php echo ! $hide_graph ? 'hide' : 'show'; ?>">
|
||||
<p>
|
||||
<?php
|
||||
@@ -465,8 +346,7 @@ class DashboardWidget {
|
||||
],
|
||||
]
|
||||
),
|
||||
// phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'upgrade-to-pro' ] ) )
|
||||
esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'dashboard-widget', 'content' => 'upgrade-to-pro' ] ) ) // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
@@ -540,9 +420,7 @@ class DashboardWidget {
|
||||
?>
|
||||
<div class="wp-mail-smtp-dash-widget-settings-container">
|
||||
<button id="wp-mail-smtp-dash-widget-settings-button" class="wp-mail-smtp-dash-widget-settings-button button" type="button">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 19 19">
|
||||
<path d="M18,11l-2.18,0c-0.17,0.7 -0.44,1.35 -0.81,1.93l1.54,1.54l-2.1,2.1l-1.54,-1.54c-0.58,0.36 -1.23,0.63 -1.91,0.79l0,2.18l-3,0l0,-2.18c-0.68,-0.16 -1.33,-0.43 -1.91,-0.79l-1.54,1.54l-2.12,-2.12l1.54,-1.54c-0.36,-0.58 -0.63,-1.23 -0.79,-1.91l-2.18,0l0,-2.97l2.17,0c0.16,-0.7 0.44,-1.35 0.8,-1.94l-1.54,-1.54l2.1,-2.1l1.54,1.54c0.58,-0.37 1.24,-0.64 1.93,-0.81l0,-2.18l3,0l0,2.18c0.68,0.16 1.33,0.43 1.91,0.79l1.54,-1.54l2.12,2.12l-1.54,1.54c0.36,0.59 0.64,1.24 0.8,1.94l2.17,0l0,2.97Zm-8.5,1.5c1.66,0 3,-1.34 3,-3c0,-1.66 -1.34,-3 -3,-3c-1.66,0 -3,1.34 -3,3c0,1.66 1.34,3 3,3Z"></path>
|
||||
</svg>
|
||||
<span class="dashicons dashicons-admin-generic"></span>
|
||||
</button>
|
||||
<div class="wp-mail-smtp-dash-widget-settings-menu">
|
||||
<div class="wp-mail-smtp-dash-widget-settings-menu--style">
|
||||
@@ -702,12 +580,24 @@ class DashboardWidget {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $action === 'get' ) {
|
||||
return $this->get_widget_meta( $meta );
|
||||
$defaults = [
|
||||
'hide_graph' => 0,
|
||||
'hide_summary_report_email_block' => 0,
|
||||
];
|
||||
|
||||
if ( ! array_key_exists( $meta, $defaults ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$meta_key = $this->get_widget_meta_key( $meta );
|
||||
$value = sanitize_key( $value );
|
||||
$meta_key = 'wp_mail_smtp_' . static::SLUG . '_' . $meta;
|
||||
|
||||
if ( 'get' === $action ) {
|
||||
$meta_value = get_user_meta( get_current_user_id(), $meta_key, true );
|
||||
|
||||
return empty( $meta_value ) ? $defaults[ $meta ] : $meta_value;
|
||||
}
|
||||
|
||||
$value = sanitize_key( $value );
|
||||
|
||||
if ( 'set' === $action && ! empty( $value ) ) {
|
||||
return update_user_meta( get_current_user_id(), $meta_key, $value );
|
||||
@@ -719,48 +609,4 @@ class DashboardWidget {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the widget meta value.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $meta Meta name.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function get_widget_meta( $meta ) {
|
||||
|
||||
$defaults = [
|
||||
'hide_graph' => 0,
|
||||
'hide_summary_report_email_block' => 0,
|
||||
'hide_email_alerts_banner' => 0,
|
||||
];
|
||||
|
||||
$meta_value = get_user_meta( get_current_user_id(), $this->get_widget_meta_key( $meta ), true );
|
||||
|
||||
if ( ! empty( $meta_value ) ) {
|
||||
return $meta_value;
|
||||
}
|
||||
|
||||
if ( isset( $defaults[ $meta ] ) ) {
|
||||
return $defaults[ $meta ];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the meta key.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $meta Meta name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_widget_meta_key( $meta ) {
|
||||
|
||||
return 'wp_mail_smtp_' . static::SLUG . '_' . $meta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace WPMailSMTP\Admin\DebugEvents;
|
||||
|
||||
use WP_Error;
|
||||
use WPMailSMTP\Admin\Area;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\Tasks\DebugEventsCleanupTask;
|
||||
@@ -15,15 +14,6 @@ use WPMailSMTP\WP;
|
||||
*/
|
||||
class DebugEvents {
|
||||
|
||||
/**
|
||||
* Transient name for the error debug events.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ERROR_DEBUG_EVENTS_TRANSIENT = 'wp_mail_smtp_error_debug_events_transient';
|
||||
|
||||
/**
|
||||
* Register hooks.
|
||||
*
|
||||
@@ -258,51 +248,6 @@ class DebugEvents {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of error debug events in a given time span.
|
||||
*
|
||||
* By default it returns the number of error debug events in the last 30 days.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $span_of_time The time span to count the events for. Default '-30 days'.
|
||||
*
|
||||
* @return int|WP_Error The number of error debug events or WP_Error on failure.
|
||||
*/
|
||||
public static function get_error_debug_events_count( $span_of_time = '-30 days' ) {
|
||||
|
||||
$timestamp = strtotime( $span_of_time );
|
||||
|
||||
if ( ! $timestamp || $timestamp > time() ) {
|
||||
return new WP_Error( 'wp_mail_smtp_admin_debug_events_get_error_debug_events_count_invalid_time', 'Invalid time span.' );
|
||||
}
|
||||
|
||||
$transient_key = self::ERROR_DEBUG_EVENTS_TRANSIENT . '_' . sanitize_title_with_dashes( $span_of_time );
|
||||
$cached_error_events_count = get_transient( $transient_key );
|
||||
|
||||
if ( $cached_error_events_count !== false ) {
|
||||
return (int) $cached_error_events_count;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
|
||||
$sql = $wpdb->prepare(
|
||||
'SELECT COUNT(*) FROM `%1$s` WHERE event_type = %2$d AND created_at >= "%3$s"',
|
||||
self::get_table_name(),
|
||||
Event::TYPE_ERROR,
|
||||
gmdate( WP::datetime_mysql_format(), $timestamp )
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
|
||||
$error_events_count = (int) $wpdb->get_var( $sql );
|
||||
|
||||
set_transient( $transient_key, $error_events_count, HOUR_IN_SECONDS );
|
||||
|
||||
return $error_events_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the screen options for the debug events page.
|
||||
*
|
||||
@@ -414,8 +359,7 @@ class DebugEvents {
|
||||
|
||||
$table = self::get_table_name();
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$is_valid = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s;', $table ) );
|
||||
$is_valid = (bool) $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s;', $table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
|
||||
return $is_valid;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace WPMailSMTP\Admin;
|
||||
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
|
||||
/**
|
||||
* Class for interacting with the Domain Checker API.
|
||||
*
|
||||
@@ -55,12 +53,7 @@ class DomainChecker {
|
||||
'domain' => $sending_domain,
|
||||
];
|
||||
|
||||
$response = wp_remote_get(
|
||||
add_query_arg( $params, self::ENDPOINT ),
|
||||
[
|
||||
'user-agent' => Helpers::get_default_user_agent(),
|
||||
]
|
||||
);
|
||||
$response = wp_remote_get( add_query_arg( $params, self::ENDPOINT ) );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
$this->results = [
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace WPMailSMTP\Admin;
|
||||
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\Tasks\Tasks;
|
||||
use WPMailSMTP\WP;
|
||||
@@ -121,12 +120,7 @@ class Notifications {
|
||||
*/
|
||||
protected function fetch_feed() {
|
||||
|
||||
$response = wp_remote_get(
|
||||
self::SOURCE_URL,
|
||||
[
|
||||
'user-agent' => Helpers::get_default_user_agent(),
|
||||
]
|
||||
);
|
||||
$response = wp_remote_get( self::SOURCE_URL );
|
||||
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return [];
|
||||
@@ -232,7 +226,6 @@ class Notifications {
|
||||
* Get notification data.
|
||||
*
|
||||
* @since 2.3.0
|
||||
* @since 3.9.0 Make the AS a recurring task.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -244,17 +237,16 @@ class Notifications {
|
||||
|
||||
$option = $this->get_option();
|
||||
|
||||
// Update notifications a recurring task.
|
||||
if ( Tasks::is_scheduled( 'wp_mail_smtp_admin_notifications_update' ) === false ) {
|
||||
// Update notifications using async task.
|
||||
if ( empty( $option['update'] ) || time() > $option['update'] + DAY_IN_SECONDS ) {
|
||||
if ( empty( Tasks::is_scheduled( 'wp_mail_smtp_admin_notifications_update' ) ) ) {
|
||||
|
||||
wp_mail_smtp()->get_tasks()
|
||||
->create( 'wp_mail_smtp_admin_notifications_update' )
|
||||
->recurring(
|
||||
strtotime( '+1 minute' ),
|
||||
$this->get_notification_update_task_interval()
|
||||
)
|
||||
->params()
|
||||
->register();
|
||||
wp_mail_smtp()->get_tasks()
|
||||
->create( 'wp_mail_smtp_admin_notifications_update' )
|
||||
->async()
|
||||
->params()
|
||||
->register();
|
||||
}
|
||||
}
|
||||
|
||||
$events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : [];
|
||||
@@ -263,25 +255,6 @@ class Notifications {
|
||||
return array_merge( $events, $feed );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the update notifications interval.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_notification_update_task_interval() {
|
||||
|
||||
/**
|
||||
* Filters the interval for the notifications update task.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param int $interval The interval in seconds. Default to a day (in seconds).
|
||||
*/
|
||||
return (int) apply_filters( 'wp_mail_smtp_admin_notifications_get_notification_update_task_interval', DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notification count.
|
||||
*
|
||||
|
||||
@@ -68,13 +68,13 @@ class AdditionalConnectionsTab extends PageAbstract {
|
||||
|
||||
wp_enqueue_style(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/css/vendor/lity.min.css',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.css',
|
||||
[],
|
||||
'2.4.1'
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/js/vendor/lity.min.js',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.js',
|
||||
[],
|
||||
'2.4.1'
|
||||
);
|
||||
|
||||
@@ -73,13 +73,13 @@ class EmailReportsTab extends PageAbstract {
|
||||
|
||||
wp_enqueue_style(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/css/vendor/lity.min.css',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.css',
|
||||
[],
|
||||
'2.4.1'
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/js/vendor/lity.min.js',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.js',
|
||||
[],
|
||||
'2.4.1',
|
||||
false
|
||||
|
||||
@@ -82,13 +82,13 @@ class LogsTab extends PageAbstract {
|
||||
|
||||
wp_enqueue_style(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/css/vendor/lity.min.css',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.css',
|
||||
[],
|
||||
'2.4.1'
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'wp-mail-smtp-admin-lity',
|
||||
wp_mail_smtp()->assets_url . '/js/vendor/lity.min.js',
|
||||
wp_mail_smtp()->assets_url . '/libs/lity/lity.min.js',
|
||||
[],
|
||||
'2.4.1',
|
||||
false
|
||||
|
||||
@@ -814,7 +814,7 @@ Co-Founder, WP Mail SMTP';
|
||||
esc_html__( 'Typically this error is returned when you are sending too many e-mails or e-mails that have been identified as spam.', 'wp-mail-smtp' ),
|
||||
],
|
||||
'steps' => [
|
||||
esc_html__( 'Make sure you are not sending emails with too many recipients. Example: single email should not have 10+ recipients. You can install any WordPress e-mail logging plugin to check your recipients (TO, CC and BCC).', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Check the emails that are sending are sending individually. Example: email is not sending to 30 recipients. You can install any WordPress e-mail logging plugin to do that.', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Contact your SMTP host to ask about sending/rate limits.', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Verify with them your SMTP account is in good standing and your account has not been flagged.', 'wp-mail-smtp' ),
|
||||
],
|
||||
@@ -938,12 +938,12 @@ Co-Founder, WP Mail SMTP';
|
||||
],
|
||||
'title' => esc_html__( 'Mailgun failed.', 'wp-mail-smtp' ),
|
||||
'description' => [
|
||||
esc_html__( 'Typically this error occurs because there is an issue with your Mailgun settings, in many cases Mailgun API Key, Domain Name, or Region is incorrect.', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Typically this error occurs because there is an issue with your Mailgun settings, in many cases Private API Key, Domain Name, or Region is incorrect.', 'wp-mail-smtp' ),
|
||||
],
|
||||
'steps' => [
|
||||
sprintf(
|
||||
wp_kses( /* translators: %1$s - Mailgun API Key area URL. */
|
||||
__( 'Go to your Mailgun account and verify that your <a href="%1$s" target="_blank" rel="noopener noreferrer">Mailgun API Key</a> is correct.', 'wp-mail-smtp' ),
|
||||
__( 'Go to your Mailgun account and verify that your <a href="%1$s" target="_blank" rel="noopener noreferrer">Private API Key</a> is correct.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
@@ -952,7 +952,7 @@ Co-Founder, WP Mail SMTP';
|
||||
],
|
||||
]
|
||||
),
|
||||
'https://app.mailgun.com/settings/api_security'
|
||||
'https://app.mailgun.com/app/account/security/api_keys'
|
||||
),
|
||||
sprintf(
|
||||
wp_kses( /* translators: %1$s - Mailgun domains area URL. */
|
||||
@@ -1033,7 +1033,7 @@ Co-Founder, WP Mail SMTP';
|
||||
. '<li>' .
|
||||
sprintf(
|
||||
wp_kses( /* translators: %s - Google support article URL. */
|
||||
__( 'if you are using Google Workspace, please <a href="%s" target="_blank" rel="noopener noreferrer">read this article</a> to proceed.', 'wp-mail-smtp' ),
|
||||
__( 'if you are using G Suite, please <a href="%s" target="_blank" rel="noopener noreferrer">read this article</a> to proceed.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
@@ -1124,8 +1124,8 @@ Co-Founder, WP Mail SMTP';
|
||||
],
|
||||
'steps' => [
|
||||
sprintf(
|
||||
wp_kses( /* translators: %s - Google Workspace Admin area URL. */
|
||||
__( 'Make sure that your Google Workspace trial period has not expired. You can check the status <a href="%s" target="_blank" rel="noopener noreferrer">here</a>.', 'wp-mail-smtp' ),
|
||||
wp_kses( /* translators: %s - Google G Suite Admin area URL. */
|
||||
__( 'Make sure that your G Suite trial period has not expired. You can check the status <a href="%s" target="_blank" rel="noopener noreferrer">here</a>.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
@@ -1137,8 +1137,8 @@ Co-Founder, WP Mail SMTP';
|
||||
'https://admin.google.com'
|
||||
),
|
||||
sprintf(
|
||||
wp_kses( /* translators: %s - Google Workspace Admin area URL. */
|
||||
__( 'Make sure that Gmail app in your Google Workspace is actually enabled. You can check that in Apps list in <a href="%s" target="_blank" rel="noopener noreferrer">Google Workspace Admin</a> area.', 'wp-mail-smtp' ),
|
||||
wp_kses( /* translators: %s - Google G Suite Admin area URL. */
|
||||
__( 'Make sure that Gmail app in your G Suite is actually enabled. You can check that in Apps list in <a href="%s" target="_blank" rel="noopener noreferrer">G Suite Admin</a> area.', 'wp-mail-smtp' ),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
@@ -1357,7 +1357,7 @@ Co-Founder, WP Mail SMTP';
|
||||
. '</ul>',
|
||||
],
|
||||
'steps' => [
|
||||
esc_html__( 'Triple-check the plugin settings and consider reconfiguring to make sure everything is correct. Maybe there was an issue with copy&pasting.', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Triple check the plugin settings, consider reconfiguring to make sure everything is correct (eg bad copy and paste).', 'wp-mail-smtp' ),
|
||||
wp_kses(
|
||||
__( 'Contact your web hosting provider and ask them to verify your server can make outside connections. Additionally, ask them if a firewall or security policy may be preventing the connection - many shared hosts block certain ports.<br><strong>Note: this is the most common cause of this issue.</strong>', 'wp-mail-smtp' ),
|
||||
[
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace WPMailSMTP\Admin;
|
||||
|
||||
use WPMailSMTP\Admin\Pages\TestTab;
|
||||
use WPMailSMTP\Connect;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\Helpers\PluginImportDataRetriever;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\UsageTracking\UsageTracking;
|
||||
@@ -975,7 +974,6 @@ class SetupWizard {
|
||||
* AJAX callback for getting all partner's plugin information.
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @since 3.9.0 Check if a SEO toolkit plugin is installed.
|
||||
*/
|
||||
public function get_partner_plugins_info() {
|
||||
|
||||
@@ -984,7 +982,6 @@ class SetupWizard {
|
||||
$plugins = $this->get_partner_plugins();
|
||||
|
||||
$contact_form_plugin_already_installed = false;
|
||||
$seo_toolkit_plugin_already_installed = false;
|
||||
|
||||
$contact_form_basenames = [
|
||||
'wpforms-lite/wpforms.php',
|
||||
@@ -995,22 +992,12 @@ class SetupWizard {
|
||||
'ninja-forms/ninja-forms.php',
|
||||
];
|
||||
|
||||
$seo_toolkit_basenames = [
|
||||
'all-in-one-seo-pack/all_in_one_seo_pack.php',
|
||||
'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
|
||||
'seo-by-rank-math/rank-math.php',
|
||||
'seo-by-rank-math-pro/rank-math-pro.php',
|
||||
'wordpress-seo/wp-seo.php',
|
||||
'wordpress-seo-premium/wp-seo-premium.php',
|
||||
];
|
||||
|
||||
$installed_plugins = get_plugins();
|
||||
|
||||
foreach ( $installed_plugins as $basename => $plugin_info ) {
|
||||
if ( in_array( $basename, $contact_form_basenames, true ) ) {
|
||||
$contact_form_plugin_already_installed = true;
|
||||
} elseif ( in_array( $basename, $seo_toolkit_basenames, true ) ) {
|
||||
$seo_toolkit_plugin_already_installed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1022,7 +1009,6 @@ class SetupWizard {
|
||||
$data = [
|
||||
'plugins' => $plugins,
|
||||
'contact_form_plugin_already_installed' => $contact_form_plugin_already_installed,
|
||||
'seo_toolkit_plugin_already_installed' => $seo_toolkit_plugin_already_installed,
|
||||
];
|
||||
|
||||
wp_send_json_success( $data );
|
||||
@@ -1046,12 +1032,6 @@ class SetupWizard {
|
||||
'is_activated' => function_exists( 'wpforms' ),
|
||||
'is_installed' => array_key_exists( 'wpforms-lite/wpforms.php', $installed_plugins ),
|
||||
],
|
||||
[
|
||||
'slug' => 'all-in-one-seo-pack',
|
||||
'name' => esc_html__( 'All in One SEO', 'wp-mail-smtp' ),
|
||||
'is_activated' => class_exists( 'AIOSEOP_Core' ),
|
||||
'is_installed' => array_key_exists( 'all-in-one-seo-pack/all_in_one_seo_pack.php', $installed_plugins ),
|
||||
],
|
||||
[
|
||||
'slug' => 'google-analytics-for-wordpress',
|
||||
'name' => esc_html__( 'Google Analytics by MonsterInsights', 'wp-mail-smtp' ),
|
||||
@@ -1059,10 +1039,10 @@ class SetupWizard {
|
||||
'is_installed' => array_key_exists( 'google-analytics-for-wordpress/googleanalytics.php', $installed_plugins ),
|
||||
],
|
||||
[
|
||||
'slug' => 'insert-headers-and-footers',
|
||||
'name' => esc_html__( 'Code Snippets by WPCode', 'wp-mail-smtp' ),
|
||||
'is_activated' => class_exists( 'InsertHeadersAndFooters' ),
|
||||
'is_installed' => array_key_exists( 'insert-headers-and-footers/ihaf.php', $installed_plugins ),
|
||||
'slug' => 'all-in-one-seo-pack',
|
||||
'name' => esc_html__( 'All in One SEO', 'wp-mail-smtp' ),
|
||||
'is_activated' => class_exists( 'AIOSEOP_Core' ),
|
||||
'is_installed' => array_key_exists( 'all-in-one-seo-pack/all_in_one_seo_pack.php', $installed_plugins ),
|
||||
],
|
||||
[
|
||||
'slug' => 'rafflepress',
|
||||
@@ -1119,7 +1099,6 @@ class SetupWizard {
|
||||
wp_remote_post(
|
||||
'https://connect.wpmailsmtp.com/subscribe/drip/',
|
||||
[
|
||||
'user-agent' => Helpers::get_default_user_agent(),
|
||||
'body' => $body,
|
||||
]
|
||||
);
|
||||
@@ -1130,7 +1109,7 @@ class SetupWizard {
|
||||
/**
|
||||
* Get the WPForms version type if it's installed.
|
||||
*
|
||||
* @since 3.9.0
|
||||
* @since {VERSION}
|
||||
*
|
||||
* @return false|string Return `false` if WPForms is not installed, otherwise return either `lite` or `pro`.
|
||||
*/
|
||||
@@ -1258,7 +1237,6 @@ class SetupWizard {
|
||||
wp_remote_post(
|
||||
'https://wpmailsmtp.com/wizard-feedback/',
|
||||
[
|
||||
'user-agent' => Helpers::get_default_user_agent(),
|
||||
'body' => [
|
||||
'wpforms' => [
|
||||
'id' => 87892,
|
||||
|
||||
@@ -6,7 +6,6 @@ use WPMailSMTP\Admin\AdminBarMenu;
|
||||
use WPMailSMTP\Admin\DashboardWidget;
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\Admin\Notifications;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\Tasks\Meta;
|
||||
use WPMailSMTP\UsageTracking\UsageTracking;
|
||||
use WPMailSMTP\Compatibility\Compatibility;
|
||||
@@ -688,8 +687,6 @@ class Core {
|
||||
update_option( 'wp_mail_smtp_activated', $activated );
|
||||
}
|
||||
|
||||
set_transient( 'wp_mail_smtp_just_activated', true, 60 );
|
||||
|
||||
// Add transient to trigger redirect to the Setup Wizard.
|
||||
set_transient( 'wp_mail_smtp_activation_redirect', true, 30 );
|
||||
}
|
||||
@@ -754,7 +751,11 @@ class Core {
|
||||
*/
|
||||
public function get_upgrade_link( $utm ) {
|
||||
|
||||
$url = $this->get_utm_url( 'https://wpmailsmtp.com/lite-upgrade/', $utm );
|
||||
$url = add_query_arg(
|
||||
'utm_locale',
|
||||
sanitize_key( get_locale() ),
|
||||
$this->get_utm_url( 'https://wpmailsmtp.com/lite-upgrade/', $utm )
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters upgrade link.
|
||||
@@ -783,7 +784,6 @@ class Core {
|
||||
$medium = 'plugin-settings';
|
||||
$campaign = $this->is_pro() ? 'plugin' : 'liteplugin';
|
||||
$content = 'general';
|
||||
$locale = get_user_locale();
|
||||
|
||||
if ( is_array( $utm ) ) {
|
||||
if ( isset( $utm['source'] ) ) {
|
||||
@@ -798,9 +798,6 @@ class Core {
|
||||
if ( isset( $utm['content'] ) ) {
|
||||
$content = $utm['content'];
|
||||
}
|
||||
if ( isset( $utm['locale'] ) ) {
|
||||
$locale = $utm['locale'];
|
||||
}
|
||||
} elseif ( is_string( $utm ) ) {
|
||||
$content = $utm;
|
||||
}
|
||||
@@ -809,7 +806,6 @@ class Core {
|
||||
'utm_source' => esc_attr( rawurlencode( $source ) ),
|
||||
'utm_medium' => esc_attr( rawurlencode( $medium ) ),
|
||||
'utm_campaign' => esc_attr( rawurlencode( $campaign ) ),
|
||||
'utm_locale' => esc_attr( sanitize_key( $locale ) ),
|
||||
];
|
||||
|
||||
if ( ! empty( $content ) ) {
|
||||
|
||||
@@ -141,7 +141,7 @@ class DBRepair {
|
||||
|
||||
return sprintf(
|
||||
wp_kses( /* translators: %1$s - missing table name; %2$s - error message. */
|
||||
__( '<strong>Table:</strong> %1$s. <strong>Reason:</strong> %2$s', 'wp-mail-smtp' ),
|
||||
__( '<strong>Table</strong> %1$s: <strong>Reason</strong> %2$s', 'wp-mail-smtp' ),
|
||||
[
|
||||
'strong' => [],
|
||||
]
|
||||
@@ -197,16 +197,6 @@ class DBRepair {
|
||||
_n( 'Table is', 'Tables are', count( $missing_tables ), 'wp-mail-smtp' ),
|
||||
implode( '<br/>', $reasons )
|
||||
);
|
||||
|
||||
$msg = sprintf(
|
||||
wp_kses(
|
||||
_n( 'The following DB table is still missing.', 'The following DB tables are still missing.', count( $missing_tables ), 'wp-mail-smtp' ) . '<br />%s',
|
||||
[
|
||||
'br' => [],
|
||||
]
|
||||
),
|
||||
implode( '<br/>', $reasons )
|
||||
);
|
||||
} else {
|
||||
$msg = esc_html__( 'Some DB Tables are still missing.', 'wp-mail-smtp' );
|
||||
}
|
||||
|
||||
@@ -139,18 +139,4 @@ class Helpers {
|
||||
|
||||
return $error_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default user agent.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_default_user_agent() {
|
||||
|
||||
$license_type = wp_mail_smtp()->get_license_type();
|
||||
|
||||
return 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) . '; WPMailSMTP/' . $license_type . '-' . WPMS_PLUGIN_VER;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class Options extends OptionsAbstract {
|
||||
<!-- 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( 'Mailgun API Key', 'wp-mail-smtp' ); ?></label>
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"><?php esc_html_e( 'Private API Key', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'api_key' ) ) : ?>
|
||||
@@ -73,18 +73,12 @@ class Options extends OptionsAbstract {
|
||||
<?php endif; ?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
echo wp_kses(
|
||||
sprintf( /* translators: %s - API key URL. */
|
||||
__( 'Follow this link to <a href="%s" target="_blank" rel="noopener noreferrer">get a Mailgun API Key</a>. Generate a key in the "Mailgun API Keys" section.', 'wp-mail-smtp' ),
|
||||
'https://app.mailgun.com/settings/api_security'
|
||||
),
|
||||
[
|
||||
'a' => [
|
||||
'href' => [],
|
||||
'rel' => [],
|
||||
'target' => [],
|
||||
],
|
||||
]
|
||||
printf(
|
||||
/* translators: %s - API key link. */
|
||||
esc_html__( 'Follow this link to get a Private API Key from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/account/security/api_keys" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Private API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
@@ -107,7 +101,7 @@ class Options extends OptionsAbstract {
|
||||
printf(
|
||||
/* translators: %s - Domain Name link. */
|
||||
esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.mailgun.com/app/sending/domains" target="_blank" rel="noopener noreferrer">' .
|
||||
'<a href="https://app.mailgun.com/app/domains" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Api\AccountApi;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Api\SendersApi;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Api\TransactionalEmailsApi;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Configuration;
|
||||
|
||||
/**
|
||||
* Class Api is a wrapper for Sendinblue library with handy methods.
|
||||
@@ -51,54 +55,51 @@ class Api {
|
||||
* Configure API key authorization: api-key.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*
|
||||
* @return null
|
||||
* @return Configuration
|
||||
*/
|
||||
protected function get_api_config() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
|
||||
return null;
|
||||
return Configuration::getDefaultConfiguration()->setApiKey( 'api-key', isset( $this->options['api_key'] ) ? $this->options['api_key'] : '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Account API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_account_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return null;
|
||||
return new AccountApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for Sender API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_sender_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return null;
|
||||
return new SendersApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mailer client instance for SMTP API.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @deprecated 3.9.0 We are no longer using the Sendinblue SDK.
|
||||
*/
|
||||
public function get_smtp_client() {
|
||||
|
||||
_deprecated_function( __METHOD__, '3.9.0' );
|
||||
// Include the library.
|
||||
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
|
||||
|
||||
return null;
|
||||
return new TransactionalEmailsApi( null, $this->get_api_config() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace WPMailSMTP\Providers\Sendinblue;
|
||||
|
||||
use WPMailSMTP\ConnectionInterface;
|
||||
use WPMailSMTP\Admin\DebugEvents\DebugEvents;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\MailCatcherInterface;
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\ApiException;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Model\CreateSmtpEmail;
|
||||
use WPMailSMTP\Vendor\SendinBlue\Client\Model\SendSmtpEmail;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
@@ -24,41 +27,15 @@ class Mailer extends MailerAbstract {
|
||||
*/
|
||||
protected $email_sent_code = 201;
|
||||
|
||||
/**
|
||||
* Response code for scheduled email.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_scheduled_code = 202;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
* Not actually used, because we use a lib to make requests.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Update to use Brevo API.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.brevo.com/v3/smtp/email';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param MailCatcherInterface $phpmailer The MailCatcher object.
|
||||
* @param ConnectionInterface $connection The Connection object.
|
||||
*/
|
||||
public function __construct( $phpmailer, $connection = null ) {
|
||||
|
||||
parent::__construct( $phpmailer, $connection );
|
||||
|
||||
$this->set_header( 'api-key', $this->connection_options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
}
|
||||
protected $url = 'https://api.sendinblue.com/v3';
|
||||
|
||||
/**
|
||||
* The list of allowed attachment files extensions.
|
||||
@@ -74,49 +51,15 @@ class Mailer extends MailerAbstract {
|
||||
// @formatter:on
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
* @inheritDoc
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param array $headers List of key=>value pairs.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public function set_headers( $headers ) {
|
||||
|
||||
foreach ( $headers as $header ) {
|
||||
$name = isset( $header[0] ) ? $header[0] : false;
|
||||
$value = isset( $header[1] ) ? $header[1] : false;
|
||||
|
||||
$this->set_body_header( $name, $value );
|
||||
}
|
||||
|
||||
// Add custom PHPMailer-specific header.
|
||||
$this->set_body_header( 'X-Mailer', 'WPMailSMTP/Mailer/' . $this->mailer . ' ' . WPMS_PLUGIN_VER );
|
||||
}
|
||||
|
||||
/**
|
||||
* This mailer supports email-related custom headers inside a body of the message.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param string $name Key.
|
||||
* @param string $value Value.
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
public function set_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['headers'] ) ? (array) $this->body['headers'] : [];
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
[
|
||||
'headers' => $headers,
|
||||
]
|
||||
);
|
||||
$this->body['headers'][ $name ] = WP::sanitize_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -320,9 +263,8 @@ class Mailer extends MailerAbstract {
|
||||
* Get the email body.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Returns email body array instead of `SendSmtpEmail` object.
|
||||
*
|
||||
* @return array
|
||||
* @return SendSmtpEmail
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
@@ -333,110 +275,82 @@ class Mailer extends MailerAbstract {
|
||||
*
|
||||
* @param array $body Email body.
|
||||
*/
|
||||
return apply_filters( 'wp_mail_smtp_providers_sendinblue_mailer_get_body', $this->body );
|
||||
$body = apply_filters( 'wp_mail_smtp_providers_sendinblue_mailer_get_body', $this->body );
|
||||
|
||||
return new SendSmtpEmail( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send email.
|
||||
* Use a library to send emails.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Use API instead of SDK to send email.
|
||||
*/
|
||||
public function send() {
|
||||
|
||||
$response = wp_safe_remote_post(
|
||||
$this->url,
|
||||
[
|
||||
'headers' => $this->get_headers(),
|
||||
'body' => wp_json_encode( $this->get_body() ),
|
||||
]
|
||||
);
|
||||
try {
|
||||
$api = new Api( $this->connection );
|
||||
|
||||
$this->process_response( $response );
|
||||
$response = $api->get_smtp_client()->sendTransacEmail( $this->get_body() );
|
||||
|
||||
DebugEvents::add_debug(
|
||||
esc_html__( 'An email request was sent to the Brevo API.', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
$this->process_response( $response );
|
||||
} catch ( ApiException $e ) {
|
||||
$error = json_decode( $e->getResponseBody() );
|
||||
|
||||
if ( json_last_error() === JSON_ERROR_NONE && ! empty( $error ) ) {
|
||||
$message = Helpers::format_error_message( $error->message, $error->code );
|
||||
} else {
|
||||
$message = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->error_message = $message;
|
||||
} catch ( \Exception $e ) {
|
||||
$this->error_message = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We might need to do something after the email was sent to the API.
|
||||
* In this method we preprocess the response from the API.
|
||||
* Save response from the API to use it later.
|
||||
* All the actually response processing is done in send() method,
|
||||
* because SendinBlue throws exception if any error occurs.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Expect a generic class object instead of `CreateSmtpEmail`.
|
||||
*
|
||||
* @param mixed $response Response from the API.
|
||||
* @param CreateSmtpEmail $response The Sendinblue Email object.
|
||||
*/
|
||||
protected function process_response( $response ) {
|
||||
|
||||
parent::process_response( $response );
|
||||
|
||||
if ( $this->has_message_id() ) {
|
||||
$this->phpmailer->MessageID = $this->response['body']->messageId;
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Sendinblue-specific response with a helpful error.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_response_error() {
|
||||
|
||||
$error_text = [];
|
||||
|
||||
if ( ! empty( $this->error_message ) ) {
|
||||
$error_text[] = $this->error_message;
|
||||
}
|
||||
|
||||
if ( ! empty( $this->response ) ) {
|
||||
$body = wp_remote_retrieve_body( $this->response );
|
||||
|
||||
if ( ! empty( $body->message ) ) {
|
||||
$error_text[] = Helpers::format_error_message( $body->message, ! empty( $body->code ) ? $body->code : '' );
|
||||
} else {
|
||||
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
|
||||
}
|
||||
}
|
||||
|
||||
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the response has `messageId` property.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function has_message_id() {
|
||||
$this->response = $response;
|
||||
|
||||
if (
|
||||
! in_array(
|
||||
wp_remote_retrieve_response_code( $this->response ),
|
||||
[ $this->email_sent_code, $this->email_scheduled_code ],
|
||||
true
|
||||
) ||
|
||||
empty( $this->response['body']->messageId )
|
||||
is_a( $response, 'WPMailSMTP\Vendor\SendinBlue\Client\Model\CreateSmtpEmail' ) &&
|
||||
method_exists( $response, 'getMessageId' )
|
||||
) {
|
||||
return false;
|
||||
$this->phpmailer->MessageID = $response->getMessageId();
|
||||
$this->verify_sent_status = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the email was sent.
|
||||
*
|
||||
* @since 1.6.0
|
||||
* @since 3.9.0 Check if `$this->response` has `messageId` property to check if the email was sent.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_email_sent() {
|
||||
|
||||
$is_sent = false;
|
||||
|
||||
if ( $this->response instanceof CreateSmtpEmail ) {
|
||||
$is_sent = $this->response->valid();
|
||||
}
|
||||
|
||||
/** This filter is documented in src/Providers/MailerAbstract.php. */
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $this->has_message_id(), $this->mailer ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
|
||||
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,6 @@ use WPMailSMTP\Admin\DomainChecker;
|
||||
use WPMailSMTP\Admin\SetupWizard;
|
||||
use WPMailSMTP\Conflicts;
|
||||
use WPMailSMTP\Debug;
|
||||
use WPMailSMTP\Helpers\Helpers;
|
||||
use WPMailSMTP\Options;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
@@ -92,7 +91,7 @@ class UsageTracking {
|
||||
*/
|
||||
public function get_user_agent() {
|
||||
|
||||
return Helpers::get_default_user_agent();
|
||||
return 'WPMailSMTP/' . WPMS_PLUGIN_VER . '; ' . get_bloginfo( 'url' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user