EMAILING DISABLED: The %s is currently blocking all emails from being sent.', 'wp-mail-smtp' ),
esc_html( 'WP Mail SMTP v' . WPMS_PLUGIN_VER )
);
if ( Options::init()->is_const_defined( 'general', 'do_not_send' ) ) {
$notices[] = sprintf(
/* translators: %1$s - constant name; %2$s - constant value. */
__( 'To send emails, change the value of the %1$s constant to %2$s.', 'wp-mail-smtp' ),
'WPMS_DO_NOT_SEND
',
'false
'
);
} else {
$notices[] = sprintf(
/* translators: %s - plugin Misc settings page URL. */
__( 'To send emails, go to plugin Misc settings and disable the "Do Not Send" option.', 'wp-mail-smtp' ),
esc_url( add_query_arg( 'tab', 'misc', wp_mail_smtp()->get_admin()->get_admin_page_url() ) )
);
}
if (
wp_mail_smtp()->get_admin()->is_admin_page( 'tools' ) &&
(
! isset( $_GET['tab'] ) ||
( isset( $_GET['tab'] ) && $_GET['tab'] === 'test' )
)
) {
$notices[] = esc_html__( 'If you create a test email on this page, it will still be sent.', 'wp-mail-smtp' );
}
echo wp_kses_post( implode( ' ', $notices ) );
?>
get_admin()->is_admin_page() ) {
wp_mail_smtp()->wp_mail_function_incorrect_location_notice();
}
if ( wp_mail_smtp()->get_admin()->is_error_delivery_notice_enabled() ) {
$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 ) ) {
?>
Heads up! The last email your site attempted to send was unsuccessful.', 'wp-mail-smtp' ),
[
'strong' => [],
]
);
?>
get_admin()->is_admin_page() ) {
printf(
wp_kses( /* translators: %s - plugin admin page URL. */
__( 'Please review your WP Mail SMTP settings in plugin admin area.' ) . ' ',
array(
'a' => array(
'href' => array(),
),
)
),
esc_url( wp_mail_smtp()->get_admin()->get_admin_page_url() )
);
}
printf(
wp_kses( /* translators: %s - URL to the debug events page. */
__( 'For more details please try running an Email Test or reading the latest error event.' ),
[
'a' => [
'href' => [],
],
]
),
esc_url( DebugEvents::get_page_url() )
);
?>
[],
'a' => [
'href' => [],
'target' => [],
'class' => [],
'rel' => [],
],
]
);
?>
is_detected() ) {
$conflicts->notify();
}
}
/**
* Init the \PHPMailer replacement.
*
* @since 1.0.0
*
* @return MailCatcherInterface
*/
public function replace_phpmailer() {
global $phpmailer;
return $this->replace_w_fake_phpmailer( $phpmailer );
}
/**
* Overwrite default PhpMailer with our MailCatcher.
*
* @since 1.0.0
* @since 1.5.0 Throw external PhpMailer exceptions, inherits default WP behavior.
*
* @param null $obj PhpMailer object to override with own implementation.
*
* @return MailCatcherInterface
*/
protected function replace_w_fake_phpmailer( &$obj = null ) {
$obj = $this->generate_mail_catcher( true );
return $obj;
}
/**
* What to do on plugin activation.
*
* @since 1.0.0
* @since 2.0.0 Changed from general `plugin_activate` hook to this plugin specific activation hook.
*/
public function activate() {
// Store the plugin version when initial install occurred.
add_option( 'wp_mail_smtp_initial_version', WPMS_PLUGIN_VER, '', false );
// Store the plugin version activated to reference with upgrades.
update_option( 'wp_mail_smtp_version', WPMS_PLUGIN_VER, false );
// Save default options, only once.
Options::init()->set( Options::get_defaults(), true );
/**
* Store the timestamp of first plugin activation.
*
* @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 );
}
// Add transient to trigger redirect to the Setup Wizard.
set_transient( 'wp_mail_smtp_activation_redirect', true, 30 );
}
/**
* Whether this is a Pro version of a plugin.
*
* @since 1.5.0
*
* @return bool
*/
public function is_pro() {
return apply_filters( 'wp_mail_smtp_core_is_pro', ! empty( $this->pro ) );
}
/**
* Get the current license type.
*
* @since 1.5.0
*
* @return string Default value: lite.
*/
public function get_license_type() {
$type = Options::init()->get( 'license', 'type' );
if ( empty( $type ) ) {
$type = 'lite';
}
return strtolower( $type );
}
/**
* Get the current license key.
*
* @since 1.5.0
*
* @return string
*/
public function get_license_key() {
$key = Options::init()->get( 'license', 'key' );
if ( empty( $key ) ) {
$key = '';
}
return $key;
}
/**
* Upgrade link used within the various admin pages.
*
* @since 1.5.0
* @since 1.5.1 Support all UTM params.
*
* @param array|string $utm Array of UTM params, or if string provided - utm_content URL parameter.
*
* @return string
*/
public function get_upgrade_link( $utm ) {
$url = $this->get_utm_url( 'https://wpmailsmtp.com/lite-upgrade/', $utm );
/**
* Filters upgrade link.
*
* @since 1.5.0
*
* @param string $url Upgrade link.
*/
return apply_filters( 'wp_mail_smtp_core_get_upgrade_link', $url );
}
/**
* Get UTM URL.
*
* @since 3.4.0
*
* @param string $url Base url.
* @param array|string $utm Array of UTM params, or if string provided - utm_content URL parameter.
*
* @return string
*/
public function get_utm_url( $url, $utm ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
// Defaults.
$source = 'WordPress';
$medium = 'plugin-settings';
$campaign = $this->is_pro() ? 'plugin' : 'liteplugin';
$content = 'general';
if ( is_array( $utm ) ) {
if ( isset( $utm['source'] ) ) {
$source = $utm['source'];
}
if ( isset( $utm['medium'] ) ) {
$medium = $utm['medium'];
}
if ( isset( $utm['campaign'] ) ) {
$campaign = $utm['campaign'];
}
if ( isset( $utm['content'] ) ) {
$content = $utm['content'];
}
} elseif ( is_string( $utm ) ) {
$content = $utm;
}
$query_args = [
'utm_source' => esc_attr( rawurlencode( $source ) ),
'utm_medium' => esc_attr( rawurlencode( $medium ) ),
'utm_campaign' => esc_attr( rawurlencode( $campaign ) ),
];
if ( ! empty( $content ) ) {
$query_args['utm_content'] = esc_attr( rawurlencode( $content ) );
}
return add_query_arg( $query_args, $url );
}
/**
* Whether the emailing functionality is blocked, with either an option or a constatnt.
*
* @since 1.7.0
*
* @return bool
*/
public function is_blocked() {
return (bool) Options::init()->get( 'general', 'do_not_send' );
}
/**
* Whether the white-labeling is enabled.
* White-labeling disables the plugin "About us" page, it replaces any plugin marketing texts or images with
* white label ones.
*
* @since 2.0.0
*
* @return bool
*/
public function is_white_labeled() {
return (bool) apply_filters( 'wp_mail_smtp_is_white_labeled', false );
}
/**
* Require the action scheduler in an early plugins_loaded hook (-10).
*
* @see https://actionscheduler.org/usage/#load-order
*
* @since 2.1.0
*/
public function load_action_scheduler() {
require_once $this->plugin_path . '/vendor/woocommerce/action-scheduler/action-scheduler.php';
}
/**
* Get the list of all custom DB tables that should be present in the DB.
*
* @since 2.1.2
*
* @return array List of table names.
*/
public function get_custom_db_tables() {
$tables = [
Meta::get_table_name(),
DebugEvents::get_table_name(),
];
return apply_filters( 'wp_mail_smtp_core_get_custom_db_tables', $tables );
}
/**
* Generate the correct MailCatcher object based on the PHPMailer version used in WP.
*
* Also conditionally require the needed class files.
*
* @see https://make.wordpress.org/core/2020/07/01/external-library-updates-in-wordpress-5-5-call-for-testing/
*
* @since 2.2.0
*
* @param bool $exceptions True if external exceptions should be thrown.
*
* @return MailCatcherInterface
*/
public function generate_mail_catcher( $exceptions = null ) {
$is_old_version = version_compare( get_bloginfo( 'version' ), '5.5-alpha', '<' );
if ( $is_old_version ) {
if ( ! class_exists( '\PHPMailer', false ) ) {
require_once ABSPATH . WPINC . '/class-phpmailer.php';
}
$class_name = MailCatcher::class;
} else {
if ( ! class_exists( '\PHPMailer\PHPMailer\PHPMailer', false ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
}
if ( ! class_exists( '\PHPMailer\PHPMailer\Exception', false ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
}
if ( ! class_exists( '\PHPMailer\PHPMailer\SMTP', false ) ) {
require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
}
$class_name = MailCatcherV6::class;
}
/**
* Filters MailCatcher class name.
*
* @since 3.7.0
*
* @param string $mail_catcher The MailCatcher class name.
*/
$class_name = apply_filters( 'wp_mail_smtp_core_generate_mail_catcher', $class_name );
$mail_catcher = new $class_name( $exceptions );
if ( $is_old_version ) {
$mail_catcher::$validator = static function ( $email ) {
return (bool) is_email( $email );
};
}
return $mail_catcher;
}
/**
* Check if the passed object is a valid PHPMailer object.
*
* @since 2.2.0
*
* @param object $phpmailer A potential PHPMailer object to be tested.
*
* @return bool
*/
public function is_valid_phpmailer( $phpmailer ) {
return $phpmailer instanceof MailCatcherInterface ||
$phpmailer instanceof \PHPMailer ||
$phpmailer instanceof \PHPMailer\PHPMailer\PHPMailer;
}
/**
* Force the `mail.from_email_force` plugin option to always return true if the current saved mailer is Gmail.
* Alters the plugin options retrieving via the Options::get method.
*
* The gmail mailer check is performed when this filter is added.
*
* @deprecated 2.7.0
*
* @since 2.2.0
*
* @param mixed $value The value of the plugin option that is being retrieved via Options::get method.
* @param string $group The group of the plugin option that is being retrieved via Options::get method.
* @param string $key The key of the plugin option that is being retrieved via Options::get method.
*
* @return mixed
*/
public function gmail_mailer_get_from_email_force( $value, $group, $key ) {
_deprecated_function( __METHOD__, '2.7.0' );
if ( $group === 'mail' && $key === 'from_email_force' ) {
$value = true;
}
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' ) ) {
add_action( 'after_setup_theme', [ $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;
}
/**
* Prepare the HTML output for a plugin loader/spinner.
*
* @since 2.4.0
*
* @param string $color The color of the loader ('', 'blue' or 'white'), where '' is default orange.
* @param string $size The size of the loader ('lg', 'md', 'sm').
*
* @return string
*/
public function prepare_loader( $color = '', $size = 'md' ) {
$svg_name = 'loading';
if ( in_array( $color, [ 'blue', 'white' ], true ) ) {
$svg_name .= '-' . $color;
}
if ( ! in_array( $size, [ 'lg', 'md', 'sm' ], true ) ) {
$size = 'md';
}
return '