updated plugin WP Mail SMTP
version 2.0.0
This commit is contained in:
@ -57,7 +57,7 @@ class Area {
|
||||
protected function hooks() {
|
||||
|
||||
// Add the Settings link to a plugin on Plugins page.
|
||||
add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_link' ), 10, 2 );
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( WPMS_PLUGIN_FILE ), array( $this, 'add_plugin_action_link' ), 10, 1 );
|
||||
|
||||
// Add the options page.
|
||||
add_action( 'admin_menu', array( $this, 'add_admin_options_page' ) );
|
||||
@ -219,14 +219,17 @@ class Area {
|
||||
self::SLUG . '-logs',
|
||||
array( $this, 'display' )
|
||||
);
|
||||
\add_submenu_page(
|
||||
self::SLUG,
|
||||
\esc_html__( 'About Us', 'wp-mail-smtp' ),
|
||||
\esc_html__( 'About Us', 'wp-mail-smtp' ),
|
||||
'manage_options',
|
||||
self::SLUG . '-about',
|
||||
array( $this, 'display' )
|
||||
);
|
||||
|
||||
if ( ! wp_mail_smtp()->is_white_labeled() ) {
|
||||
\add_submenu_page(
|
||||
self::SLUG,
|
||||
\esc_html__( 'About Us', 'wp-mail-smtp' ),
|
||||
\esc_html__( 'About Us', 'wp-mail-smtp' ),
|
||||
'manage_options',
|
||||
self::SLUG . '-about',
|
||||
array( $this, 'display' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,7 +276,7 @@ class Area {
|
||||
'upgrade_url' => 'https://wpmailsmtp.com/lite-upgrade/?discount=SMTPLITEUPGRADE&utm_source=WordPress&utm_medium=plugin-settings&utm_campaign=liteplugin',
|
||||
'upgrade_bonus' => '<p>' .
|
||||
wp_kses(
|
||||
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span>20% off</span> regular price,<br>applied at checkout.', 'wp-mail-smtp' ),
|
||||
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span>$50 off</span> regular price,<br>applied at checkout.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'strong' => true,
|
||||
'span' => true,
|
||||
@ -368,7 +371,7 @@ class Area {
|
||||
|
||||
\wp_enqueue_script(
|
||||
'wp-mail-smtp-admin-about-matchheight',
|
||||
\wp_mail_smtp()->assets_url . '/js/jquery.matchHeight.min.js',
|
||||
\wp_mail_smtp()->assets_url . '/js/vendor/jquery.matchHeight.min.js',
|
||||
array( 'wp-mail-smtp-admin' ),
|
||||
'0.7.2',
|
||||
false
|
||||
@ -394,7 +397,7 @@ class Area {
|
||||
<div id="wp-mail-smtp-header-temp"></div>
|
||||
<div id="wp-mail-smtp-header">
|
||||
<!--suppress HtmlUnknownTarget -->
|
||||
<img class="wp-mail-smtp-header-logo" src="<?php echo esc_url( wp_mail_smtp()->assets_url ); ?>/images/logo.svg" alt="WP Mail SMTP"/>
|
||||
<img class="wp-mail-smtp-header-logo" src="<?php echo esc_url( wp_mail_smtp()->assets_url ); ?>/images/logo<?php echo wp_mail_smtp()->is_white_labeled() ? '-whitelabel' : ''; ?>.svg" alt="WP Mail SMTP"/>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
@ -775,29 +778,38 @@ class Area {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a link to Settings page of a plugin on Plugins page.
|
||||
* Add plugin action links on Plugins page (lite version only).
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added a link to Email Log.
|
||||
* @since 2.0.0 Adjusted links. Process only the Lite plugin.
|
||||
*
|
||||
* @param array $links
|
||||
* @param string $file
|
||||
* @param array $links Existing plugin action links.
|
||||
*
|
||||
* @return mixed
|
||||
* @return array
|
||||
*/
|
||||
public function add_plugin_action_link( $links, $file ) {
|
||||
public function add_plugin_action_link( $links ) {
|
||||
|
||||
// Will target both pro and lite version of a plugin.
|
||||
if ( strpos( $file, 'wp-mail-smtp' ) === false ) {
|
||||
// Do not register lite plugin action links if on pro version.
|
||||
if ( wp_mail_smtp()->is_pro() ) {
|
||||
return $links;
|
||||
}
|
||||
|
||||
$settings_link = '<a href="' . esc_url( $this->get_admin_page_url() ) . '">' . esc_html__( 'Settings', 'wp-mail-smtp' ) . '</a>';
|
||||
$logs_link = '<a href="' . esc_url( $this->get_admin_page_url( self::SLUG . '-logs' ) ) . '">' . esc_html__( 'Email Log', 'wp-mail-smtp' ) . '</a>';
|
||||
$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' )
|
||||
);
|
||||
|
||||
array_unshift( $links, $settings_link, $logs_link );
|
||||
$custom['support'] = sprintf(
|
||||
'<a href="%1$s" aria-label="%2$s" style="font-weight:bold;">%3$s</a>',
|
||||
esc_url( add_query_arg( 'tab','versus', $this->get_admin_page_url( Area::SLUG . '-about' ) ) ),
|
||||
esc_attr__( 'Go to WP Mail SMTP Lite vs Pro comparison page', 'wp-mail-smtp' ),
|
||||
esc_html__( 'Premium Support', 'wp-mail-smtp' )
|
||||
);
|
||||
|
||||
return $links;
|
||||
return array_merge( $custom, (array) $links );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -598,7 +598,7 @@ class About extends PageAbstract {
|
||||
<p class="centered">
|
||||
<?php
|
||||
echo \wp_kses(
|
||||
\__( 'Bonus: WP Mail SMTP Lite users get <span class="price-off">20% off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
|
||||
\__( 'Bonus: WP Mail SMTP Lite users get <span class="price-off">$50 off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'span' => array(
|
||||
'class' => array(),
|
||||
|
@ -234,18 +234,16 @@ class SettingsTab extends PageAbstract {
|
||||
</div>
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<!-- Suggest a mailer -->
|
||||
<div class="wp-mail-smtp-mailer suggest-new">
|
||||
<a href="https://wpmailsmtp.com/suggest-a-mailer" class="wp-mail-smtp-mailer-image" target="_blank" rel="noopener noreferrer">
|
||||
<!-- Suggest a mailer -->
|
||||
<div class="wp-mail-smtp-suggest-new-mailer">
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'Don\'t see what you\'re looking for?', 'wp-mail-smtp' ); ?>
|
||||
<a href="https://wpmailsmtp.com/suggest-a-mailer" target="_blank" rel="noopener noreferrer">
|
||||
<?php esc_html_e( 'Suggest a Mailer', 'wp-mail-smtp' ); ?>
|
||||
</a>
|
||||
|
||||
<div class="wp-mail-smtp-mailer-text">
|
||||
<label><?php esc_html_e( 'Suggest a Mailer', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -338,7 +336,7 @@ class SettingsTab extends PageAbstract {
|
||||
<p class="desc">
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'As a valued WP Mail SMTP Lite user you receive <strong>20% off</strong>, automatically applied at checkout!', 'wp-mail-smtp' ),
|
||||
__( 'As a valued WP Mail SMTP Lite user you receive <strong>$50 off</strong>, automatically applied at checkout!', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'strong' => array(),
|
||||
'br' => array(),
|
||||
@ -453,7 +451,7 @@ class SettingsTab extends PageAbstract {
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span class="price-off">20% off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
|
||||
__( '<strong>Bonus:</strong> WP Mail SMTP users get <span class="price-off">$50 off regular price</span>, automatically applied at checkout.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'strong' => array(),
|
||||
'span' => array(
|
||||
|
@ -253,7 +253,7 @@ class TestTab extends PageAbstract {
|
||||
<!-- Header -->
|
||||
<tr style="padding: 0; vertical-align: top; text-align: left;">
|
||||
<td align="center" valign="middle" class="header" style="word-wrap: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; border-collapse: collapse !important; vertical-align: top; mso-table-lspace: 0pt; mso-table-rspace: 0pt; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; color: #444; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-weight: normal; margin: 0; Margin: 0; font-size: 14px; mso-line-height-rule: exactly; line-height: 140%; text-align: center; padding: 30px 30px 22px 30px;">
|
||||
<img src="<?php echo esc_url( wp_mail_smtp()->plugin_url . '/assets/images/email/wp-mail-smtp.png' ); ?>" width="250" alt="WP Mail SMTP Logo" style="outline: none; text-decoration: none; max-width: 100%; clear: both; -ms-interpolation-mode: bicubic; display: inline-block !important; width: 250px;">
|
||||
<img src="<?php echo esc_url( wp_mail_smtp()->plugin_url . '/assets/images/email/wp-mail-smtp' . ( wp_mail_smtp()->is_white_labeled() ? '-whitelabel' : '' ) . '.png' ); ?>" width="250" alt="WP Mail SMTP Logo" style="outline: none; text-decoration: none; max-width: 100%; clear: both; -ms-interpolation-mode: bicubic; display: inline-block !important; width: 250px;">
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Content -->
|
||||
@ -296,7 +296,7 @@ class TestTab extends PageAbstract {
|
||||
Access to our world class support team
|
||||
</p>
|
||||
<p class="text-large last" style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; color: #444; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-weight: normal; padding: 0; mso-line-height-rule: exactly; line-height: 140%; font-size: 13px; text-align: center; margin: 0 0 0 0; Margin: 0 0 0 0;">
|
||||
WP Mail SMTP users get <span style="font-weight:700;color:#218900;">20% off</span>, automatically applied at checkout
|
||||
WP Mail SMTP users get <span style="font-weight:700;color:#218900;">$50 off</span>, automatically applied at checkout
|
||||
</p>
|
||||
<center style="width: 100%;">
|
||||
<table class="button large expanded orange" style="border-collapse: collapse; border-spacing: 0; padding: 0; vertical-align: top; text-align: left; mso-table-lspace: 0pt; mso-table-rspace: 0pt; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; color: #e27730; width: 100% !important;">
|
||||
@ -343,7 +343,7 @@ class TestTab extends PageAbstract {
|
||||
|
||||
// phpcs:disable
|
||||
if ( wp_mail_smtp()->is_pro() ) {
|
||||
// WP Mail SMTP Pro & WPForms paid installed.
|
||||
// WP Mail SMTP Pro paid installed.
|
||||
$message =
|
||||
'Congrats, test email was sent successfully!
|
||||
|
||||
@ -705,7 +705,7 @@ Lead Developer, WP Mail SMTP';
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpforms.com/how-to-send-wordpress-emails-with-mailgun/'
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-mailgun-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
esc_html__( 'Complete the steps in section "2. Verify Your Domain".', 'wp-mail-smtp' ),
|
||||
),
|
||||
@ -893,7 +893,7 @@ Lead Developer, WP Mail SMTP';
|
||||
esc_html__( 'Make sure that the used Client ID/Secret correspond to a proper project that has Gmail API enabled.', 'wp-mail-smtp' ),
|
||||
sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s - WPForms.com tutorial URL. */
|
||||
/* translators: %s - Gmail documentation URL. */
|
||||
esc_html__( 'Please follow our <a href="%s" target="_blank" rel="noopener noreferrer">Gmail tutorial</a> to be sure that all the correct project and data is applied.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
@ -903,7 +903,7 @@ Lead Developer, WP Mail SMTP';
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpforms.com/how-to-securely-send-wordpress-emails-using-gmail-smtp/'
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-gmail-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -1063,7 +1063,7 @@ Lead Developer, WP Mail SMTP';
|
||||
<p>
|
||||
<?php
|
||||
echo wp_kses(
|
||||
__( 'As a valued WP Mail SMTP user, you will get <span class="price-off">20% off regular pricing</span>, automatically applied at checkout!', 'wp-mail-smtp' ),
|
||||
__( 'As a valued WP Mail SMTP user, you will get <span class="price-off">$50 off regular pricing</span>, automatically applied at checkout!', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'span' => array(
|
||||
'class' => array(),
|
||||
|
@ -57,7 +57,7 @@ class Core {
|
||||
$this->plugin_path = rtrim( plugin_dir_path( __DIR__ ), '/\\' );
|
||||
|
||||
if ( $this->is_not_loadable() ) {
|
||||
$this->do_not_load();
|
||||
add_action( 'admin_notices', 'wp_mail_smtp_insecure_php_version_notice' );
|
||||
|
||||
return;
|
||||
}
|
||||
@ -88,63 +88,6 @@ class Core {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* What to do if plugin is not loaded.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected function do_not_load() {
|
||||
|
||||
add_action( 'admin_notices', function () {
|
||||
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses( /* translators: %1$s - WPBeginner URL for recommended WordPress hosting. */
|
||||
__( 'Your site is running an <strong>insecure version</strong> of PHP that is no longer supported. Please contact your web hosting provider to update your PHP version or switch to a <a href="%1$s" target="_blank" rel="noopener noreferrer">recommended WordPress hosting company</a>.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
'strong' => array(),
|
||||
)
|
||||
),
|
||||
'https://www.wpbeginner.com/wordpress-hosting/'
|
||||
);
|
||||
?>
|
||||
<br><br>
|
||||
<?php
|
||||
printf(
|
||||
wp_kses( /* translators: %s - WPForms.com docs URL with more details. */
|
||||
__( '<strong>Note:</strong> WP Mail SMTP plugin is disabled on your site until you fix the issue. <a href="%s" target="_blank" rel="noopener noreferrer">Read more for additional information.</a>', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'target' => array(),
|
||||
'rel' => array(),
|
||||
),
|
||||
'strong' => array(),
|
||||
)
|
||||
),
|
||||
'https://wpforms.com/docs/supported-php-version/'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
// In case this is on plugin activation.
|
||||
if ( isset( $_GET['activate'] ) ) { //phpcs:ignore
|
||||
unset( $_GET['activate'] ); //phpcs:ignore
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign all hooks to proper places.
|
||||
*
|
||||
@ -153,7 +96,7 @@ class Core {
|
||||
public function hooks() {
|
||||
|
||||
// Activation hook.
|
||||
add_action( 'activate_plugin', array( $this, 'activate' ), 10, 2 );
|
||||
register_activation_hook( WPMS_PLUGIN_FILE, array( $this, 'activate' ) );
|
||||
|
||||
// Redefine PHPMailer.
|
||||
add_action( 'plugins_loaded', array( $this, 'get_processor' ) );
|
||||
@ -362,7 +305,7 @@ class Core {
|
||||
/**
|
||||
* Get the plugin's WP Site Health object.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @return SiteHealth
|
||||
*/
|
||||
@ -395,7 +338,7 @@ class Core {
|
||||
) {
|
||||
WP::add_admin_notice(
|
||||
sprintf(
|
||||
wp_kses( /* translators: %1$s - WP Mail SMTP plugin name; %2$s - WPForms.com URL to a related doc. */
|
||||
wp_kses( /* translators: %1$s - WP Mail SMTP plugin name; %2$s - WPMailSMTP.com URL to a related doc. */
|
||||
__( 'Your site is running an outdated version of PHP that is no longer supported and may cause issues with %1$s. <a href="%2$s" target="_blank" rel="noopener noreferrer">Read more</a> for additional information.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'a' => array(
|
||||
@ -406,11 +349,11 @@ class Core {
|
||||
)
|
||||
),
|
||||
'<strong>WP Mail SMTP</strong>',
|
||||
'https://wpforms.com/docs/supported-php-version/'
|
||||
'https://wpmailsmtp.com/docs/supported-php-versions-for-wp-mail-smtp/'
|
||||
) .
|
||||
'<br><br><em>' .
|
||||
wp_kses(
|
||||
__( '<strong>Please Note:</strong> Support for PHP 5.3-5.5 will be discontinued in 2020. After this, if no further action is taken, WP Mail SMTP functionality will be disabled.', 'wp-mail-smtp' ),
|
||||
__( '<strong>Please Note:</strong> Support for PHP 5.5 will be discontinued in 2020. After this, if no further action is taken, WP Mail SMTP functionality will be disabled.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'strong' => array(),
|
||||
'em' => array(),
|
||||
@ -618,12 +561,9 @@ class Core {
|
||||
* What to do on plugin activation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $plugin Path to the plugin file relative to the plugins directory.
|
||||
* @param bool $network_wide Whether to enable the plugin for all sites in the network
|
||||
* or just the current site. Multisite only. Default is false.
|
||||
* @since 2.0.0 Changed from general `plugin_activate` hook to this plugin specific activation hook.
|
||||
*/
|
||||
public function activate( $plugin, $network_wide ) {
|
||||
public function activate() {
|
||||
|
||||
// Store the plugin version when initial install occurred.
|
||||
add_option( 'wp_mail_smtp_initial_version', WPMS_PLUGIN_VER, '', false );
|
||||
@ -735,4 +675,18 @@ class Core {
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -1,163 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Geo to work with location, domain, IPs etc.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Geo {
|
||||
|
||||
/**
|
||||
* Get the current site hostname.
|
||||
* In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
|
||||
* Examples: example.com, localhost.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_site_domain() {
|
||||
|
||||
return ! empty( $_SERVER['SERVER_NAME'] ) ? wp_unslash( $_SERVER['SERVER_NAME'] ) : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the domain IP address.
|
||||
* Uses gethostbyname() which is quite slow, but this is done only one time.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_ip_by_domain( $domain ) {
|
||||
|
||||
if ( $domain === 'localhost' ) {
|
||||
return '127.0.0.1';
|
||||
}
|
||||
|
||||
return gethostbyname( $domain );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location coordinates by IP address.
|
||||
* We make a request to 3rd party services.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.0 Added new geo API endpoint, provided by WPForms.
|
||||
*
|
||||
* @param string $ip
|
||||
*
|
||||
* @return array Empty array for localhost.
|
||||
*/
|
||||
public static function get_location_by_ip( $ip ) {
|
||||
|
||||
// Check for a non-local IP.
|
||||
if ( empty( $ip ) || in_array( $ip, array( '127.0.0.1', '::1' ), true ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://geo.wpforms.com/v2/geolocate/json/' . $ip );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
if ( ! empty( $request['latitude'] ) && ! empty( $request['longitude'] ) ) {
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['city'] ),
|
||||
'region' => sanitize_text_field( $request['region_name'] ),
|
||||
'country' => sanitize_text_field( $request['country_code'] ),
|
||||
'postal' => sanitize_text_field( $request['zip_code'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://ipapi.co/' . $ip . '/json' );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( ! empty( $request['latitude'] ) && ! empty( $request['longitude'] ) ) {
|
||||
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['city'] ),
|
||||
'region' => sanitize_text_field( $request['region'] ),
|
||||
'country' => sanitize_text_field( $request['country'] ),
|
||||
'postal' => sanitize_text_field( $request['postal'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://tools.keycdn.com/geo.json?host=' . $ip );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( ! empty( $request['data']['geo']['latitude'] ) && ! empty( $request['data']['geo']['longitude'] ) ) {
|
||||
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['data']['geo']['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['data']['geo']['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['data']['geo']['city'] ),
|
||||
'region' => sanitize_text_field( $request['data']['geo']['region_name'] ),
|
||||
'country' => sanitize_text_field( $request['data']['geo']['country_code'] ),
|
||||
'postal' => sanitize_text_field( $request['data']['geo']['postal_code'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine calculates the distance between two points (given the latitude/longitude of those points).
|
||||
* Definitions: South latitudes are negative, east longitudes are positive.
|
||||
*
|
||||
* @see https://www.geodatasource.com/developers/php
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param float $lat1 Latitude of point 1 (in decimal degrees).
|
||||
* @param float $lon1 Longitude of point 1 (in decimal degrees).
|
||||
* @param float $lat2 Latitude of point 2 (in decimal degrees).
|
||||
* @param float $lon2 Longitude of point 2 (in decimal degrees).
|
||||
* @param string $unit Supported values: M, K, N. Miles by default.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public static function get_distance_between( $lat1, $lon1, $lat2, $lon2, $unit = 'M' ) {
|
||||
|
||||
if ( ( $lat1 === $lat2 ) && ( $lon1 === $lon2 ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$theta = $lon1 - $lon2;
|
||||
$dist = sin( deg2rad( $lat1 ) ) * sin( deg2rad( $lat2 ) ) + cos( deg2rad( $lat1 ) ) * cos( deg2rad( $lat2 ) ) * cos( deg2rad( $theta ) );
|
||||
$dist = acos( $dist );
|
||||
$dist = rad2deg( $dist );
|
||||
$miles = $dist * 60 * 1.1515;
|
||||
$unit = strtoupper( $unit );
|
||||
|
||||
if ( $unit === 'K' ) {
|
||||
return ( $miles * 1.609344 );
|
||||
} elseif ( $unit === 'N' ) {
|
||||
return ( $miles * 0.8684 );
|
||||
}
|
||||
|
||||
return $miles;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class Geo to work with location, domain, IPs etc.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Geo {
|
||||
|
||||
/**
|
||||
* Get the current site hostname.
|
||||
* In case of CLI we don't have SERVER_NAME, so use host name instead, may be not a domain name.
|
||||
* Examples: example.com, localhost.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_site_domain() {
|
||||
|
||||
return ! empty( $_SERVER['SERVER_NAME'] ) ? wp_unslash( $_SERVER['SERVER_NAME'] ) : wp_parse_url( get_home_url( get_current_blog_id() ), PHP_URL_HOST );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the domain IP address.
|
||||
* Uses gethostbyname() which is quite slow, but this is done only one time.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $domain
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_ip_by_domain( $domain ) {
|
||||
|
||||
if ( $domain === 'localhost' ) {
|
||||
return '127.0.0.1';
|
||||
}
|
||||
|
||||
return gethostbyname( $domain );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location coordinates by IP address.
|
||||
* We make a request to 3rd party services.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.6.0 Added new geo API endpoint, provided by WPForms.
|
||||
* @since 2.0.0 Updated the WPForms geo API endpoint to v3.
|
||||
*
|
||||
* @param string $ip
|
||||
*
|
||||
* @return array Empty array for localhost.
|
||||
*/
|
||||
public static function get_location_by_ip( $ip ) {
|
||||
|
||||
// Check for a non-local IP.
|
||||
if ( empty( $ip ) || in_array( $ip, array( '127.0.0.1', '::1' ), true ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://geo.wpforms.com/v3/geolocate/json/' . $ip );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
if ( ! empty( $request['latitude'] ) && ! empty( $request['longitude'] ) ) {
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['city'] ),
|
||||
'region' => sanitize_text_field( $request['region_name'] ),
|
||||
'country' => sanitize_text_field( $request['country_iso'] ),
|
||||
'postal' => sanitize_text_field( $request['zip_code'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://ipapi.co/' . $ip . '/json' );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( ! empty( $request['latitude'] ) && ! empty( $request['longitude'] ) ) {
|
||||
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['city'] ),
|
||||
'region' => sanitize_text_field( $request['region'] ),
|
||||
'country' => sanitize_text_field( $request['country'] ),
|
||||
'postal' => sanitize_text_field( $request['postal'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
$request = wp_remote_get( 'https://tools.keycdn.com/geo.json?host=' . $ip );
|
||||
|
||||
if ( ! is_wp_error( $request ) ) {
|
||||
|
||||
$request = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( ! empty( $request['data']['geo']['latitude'] ) && ! empty( $request['data']['geo']['longitude'] ) ) {
|
||||
|
||||
$data = array(
|
||||
'latitude' => sanitize_text_field( $request['data']['geo']['latitude'] ),
|
||||
'longitude' => sanitize_text_field( $request['data']['geo']['longitude'] ),
|
||||
'city' => sanitize_text_field( $request['data']['geo']['city'] ),
|
||||
'region' => sanitize_text_field( $request['data']['geo']['region_name'] ),
|
||||
'country' => sanitize_text_field( $request['data']['geo']['country_code'] ),
|
||||
'postal' => sanitize_text_field( $request['data']['geo']['postal_code'] ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine calculates the distance between two points (given the latitude/longitude of those points).
|
||||
* Definitions: South latitudes are negative, east longitudes are positive.
|
||||
*
|
||||
* @see https://www.geodatasource.com/developers/php
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param float $lat1 Latitude of point 1 (in decimal degrees).
|
||||
* @param float $lon1 Longitude of point 1 (in decimal degrees).
|
||||
* @param float $lat2 Latitude of point 2 (in decimal degrees).
|
||||
* @param float $lon2 Longitude of point 2 (in decimal degrees).
|
||||
* @param string $unit Supported values: M, K, N. Miles by default.
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public static function get_distance_between( $lat1, $lon1, $lat2, $lon2, $unit = 'M' ) {
|
||||
|
||||
if ( ( $lat1 === $lat2 ) && ( $lon1 === $lon2 ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$theta = $lon1 - $lon2;
|
||||
$dist = sin( deg2rad( $lat1 ) ) * sin( deg2rad( $lat2 ) ) + cos( deg2rad( $lat1 ) ) * cos( deg2rad( $lat2 ) ) * cos( deg2rad( $theta ) );
|
||||
$dist = acos( $dist );
|
||||
$dist = rad2deg( $dist );
|
||||
$miles = $dist * 60 * 1.1515;
|
||||
$unit = strtoupper( $unit );
|
||||
|
||||
if ( $unit === 'K' ) {
|
||||
return ( $miles * 1.609344 );
|
||||
} elseif ( $unit === 'N' ) {
|
||||
return ( $miles * 0.8684 );
|
||||
}
|
||||
|
||||
return $miles;
|
||||
}
|
||||
}
|
||||
|
@ -64,6 +64,10 @@ class Options {
|
||||
'sendgrid' => array(
|
||||
'api_key',
|
||||
),
|
||||
'smtpcom' => array(
|
||||
'api_key',
|
||||
'channel',
|
||||
),
|
||||
'sendinblue' => array(
|
||||
'api_key',
|
||||
),
|
||||
@ -407,11 +411,11 @@ class Options {
|
||||
break;
|
||||
case 'auth':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
$return = $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTH : $value;
|
||||
$return = $this->is_const_defined( $group, $key ) ? (bool) WPMS_SMTP_AUTH : $value;
|
||||
break;
|
||||
case 'autotls':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
$return = $this->is_const_defined( $group, $key ) ? WPMS_SMTP_AUTOTLS : $value;
|
||||
$return = $this->is_const_defined( $group, $key ) ? (bool) WPMS_SMTP_AUTOTLS : $value;
|
||||
break;
|
||||
case 'user':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
@ -499,6 +503,20 @@ class Options {
|
||||
|
||||
break;
|
||||
|
||||
case 'smtpcom':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
$return = $this->is_const_defined( $group, $key ) ? WPMS_SMTPCOM_API_KEY : $value;
|
||||
break;
|
||||
case 'channel':
|
||||
/** @noinspection PhpUndefinedConstantInspection */
|
||||
$return = $this->is_const_defined( $group, $key ) ? WPMS_SMTPCOM_CHANNEL : $value;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sendinblue':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
@ -626,10 +644,10 @@ class Options {
|
||||
$return = defined( 'WPMS_SSL' );
|
||||
break;
|
||||
case 'auth':
|
||||
$return = defined( 'WPMS_SMTP_AUTH' ) && WPMS_SMTP_AUTH;
|
||||
$return = defined( 'WPMS_SMTP_AUTH' );
|
||||
break;
|
||||
case 'autotls':
|
||||
$return = defined( 'WPMS_SMTP_AUTOTLS' ) && ( WPMS_SMTP_AUTOTLS === 'true' || WPMS_SMTP_AUTOTLS === true );
|
||||
$return = defined( 'WPMS_SMTP_AUTOTLS' );
|
||||
break;
|
||||
case 'user':
|
||||
$return = defined( 'WPMS_SMTP_USER' ) && WPMS_SMTP_USER;
|
||||
@ -704,6 +722,18 @@ class Options {
|
||||
|
||||
break;
|
||||
|
||||
case 'smtpcom':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
$return = defined( 'WPMS_SMTPCOM_API_KEY' ) && WPMS_SMTPCOM_API_KEY;
|
||||
break;
|
||||
case 'channel':
|
||||
$return = defined( 'WPMS_SMTPCOM_CHANNEL' ) && WPMS_SMTPCOM_CHANNEL;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'sendinblue':
|
||||
switch ( $key ) {
|
||||
case 'api_key':
|
||||
@ -805,7 +835,7 @@ class Options {
|
||||
if (
|
||||
! empty( $options['mail']['mailer'] ) &&
|
||||
isset( $options[ $options['mail']['mailer'] ] ) &&
|
||||
in_array( $options['mail']['mailer'], array( 'pepipost', 'pepipostapi', 'smtp', 'sendgrid', 'sendinblue', 'mailgun', 'gmail', 'outlook' ), true )
|
||||
in_array( $options['mail']['mailer'], array( 'pepipost', 'pepipostapi', 'smtp', 'sendgrid', 'smtpcom', 'sendinblue', 'mailgun', 'gmail', 'outlook' ), true )
|
||||
) {
|
||||
|
||||
$mailer = $options['mail']['mailer'];
|
||||
@ -833,11 +863,12 @@ class Options {
|
||||
$options[ $mailer ][ $option_name ] = $this->is_const_defined( $mailer, $option_name ) ? '' : trim( (string) $option_value );
|
||||
break;
|
||||
|
||||
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi.
|
||||
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom.
|
||||
case 'domain': // mailgun.
|
||||
case 'client_id': // gmail/outlook/amazonses.
|
||||
case 'client_secret': // gmail/outlook/amazonses.
|
||||
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;
|
||||
|
||||
|
@ -27,8 +27,9 @@ class Processor {
|
||||
|
||||
add_action( 'phpmailer_init', array( $this, 'phpmailer_init' ) );
|
||||
|
||||
add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ), 1000 );
|
||||
add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), 1000 );
|
||||
// High priority number tries to ensure our plugin code executes last and respects previous hooks, if not forced.
|
||||
add_filter( 'wp_mail_from', array( $this, 'filter_mail_from_email' ), PHP_INT_MAX );
|
||||
add_filter( 'wp_mail_from_name', array( $this, 'filter_mail_from_name' ), PHP_INT_MAX );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -233,7 +234,7 @@ class Processor {
|
||||
/**
|
||||
* Get or create the phpmailer.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @return \WPMailSMTP\MailCatcher
|
||||
*/
|
||||
|
@ -24,6 +24,7 @@ class Loader {
|
||||
*/
|
||||
protected $providers = array(
|
||||
'mail' => 'WPMailSMTP\Providers\Mail\\',
|
||||
'smtpcom' => 'WPMailSMTP\Providers\SMTPcom\\',
|
||||
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
|
||||
'sendinblue' => 'WPMailSMTP\Providers\Sendinblue\\',
|
||||
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
|
||||
|
@ -1,477 +1,477 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Abstract Class ProviderAbstract to contain common providers functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class OptionsAbstract implements OptionsInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $logo_url = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $notices = array();
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $recommended = false;
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $disabled = false;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $php = WPMS_PHP_VER;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* ProviderAbstract constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $params ) {
|
||||
|
||||
if (
|
||||
empty( $params['slug'] ) ||
|
||||
empty( $params['title'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->slug = sanitize_key( $params['slug'] );
|
||||
$this->title = sanitize_text_field( $params['title'] );
|
||||
|
||||
if ( ! empty( $params['description'] ) ) {
|
||||
$this->description = wp_kses_post( $params['description'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['notices'] ) ) {
|
||||
foreach ( (array) $params['notices'] as $key => $notice ) {
|
||||
$key = sanitize_key( $key );
|
||||
if ( empty( $key ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notice = wp_kses(
|
||||
$notice,
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'em' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( empty( $notice ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->notices[ $key ] = $notice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['recommended'] ) ) {
|
||||
$this->recommended = (bool) $params['recommended'];
|
||||
}
|
||||
if ( isset( $params['disabled'] ) ) {
|
||||
$this->disabled = (bool) $params['disabled'];
|
||||
}
|
||||
|
||||
if ( ! empty( $params['php'] ) ) {
|
||||
$this->php = sanitize_text_field( $params['php'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['logo_url'] ) ) {
|
||||
$this->logo_url = esc_url_raw( $params['logo_url'] );
|
||||
}
|
||||
|
||||
$this->options = new Options();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_logo_url() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_slug() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_description() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some mailers may display a notice above its options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_notice( $type ) {
|
||||
|
||||
$type = sanitize_key( $type );
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_notice', isset( $this->notices[ $type ] ) ? $this->notices[ $type ] : '', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_php_version() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- SMTP Host -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" 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() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Encryption -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Port -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PHPMailer SMTPAutoTLS -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Authentication -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'auth' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Username -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Password -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
|
||||
<input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
|
||||
|
||||
<?php $this->display_const_set_message( 'WPMS_SMTP_PASS' ); ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - constant name: WPMS_SMTP_PASS. */
|
||||
esc_html__( 'To change the password you need to change the value of the constant there: %s', 'wp-mail-smtp' ),
|
||||
'<code>define( \'WPMS_SMTP_PASS\', \'your_old_password\' );</code>'
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - wp-config.php file, %2$s - WPMS_ON constant name. */
|
||||
esc_html__( 'If you want to disable the use of constants, find in %1$s file the constant %2$s and turn if off:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>',
|
||||
'<code>WPMS_ON</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', false );
|
||||
</pre>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'All the defined constants will stop working and you will be able to change all the values on this page.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'The password is stored in plain text. We highly recommend you set up your password in your WordPress configuration file for improved security.', 'wp-mail-smtp' ); ?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - wp-config.php. */
|
||||
esc_html__( 'To do this add the lines below to your %s file:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', true );
|
||||
define( 'WPMS_SMTP_PASS', 'your_password' );
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is recommended or not.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recommended() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_recommended', $this->recommended, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is disabled or not.
|
||||
* Used for displaying Pro mailers inside Lite plugin.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_disabled() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_disabled', $this->disabled, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we can use this provider based on the PHP version.
|
||||
* Valid for those, that use SDK.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_correct() {
|
||||
return version_compare( phpversion(), $this->php, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function display_php_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
|
||||
esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() ),
|
||||
esc_html( $this->php ),
|
||||
esc_html( phpversion() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected function display_ssl_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - Provider name. */
|
||||
esc_html__( '%s requires a SSL certificate on a site to work and does not support your current installation. Please contact your host and request a SSL certificate or install a free one, like Let\'s Encrypt.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a message of a constant that was set inside wp-config.php file.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $constant Constant name.
|
||||
*/
|
||||
protected function display_const_set_message( $constant ) {
|
||||
?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %1$s - constant name, %2$s - file name. */
|
||||
esc_html__( 'The value of this field was set using a constant %1$s most likely inside %2$s of your WordPress installation.', 'wp-mail-smtp' ),
|
||||
'<code>' . esc_attr( $constant ) . '</code>',
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers;
|
||||
|
||||
use WPMailSMTP\Options;
|
||||
|
||||
/**
|
||||
* Abstract Class ProviderAbstract to contain common providers functionality.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class OptionsAbstract implements OptionsInterface {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $logo_url = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $slug = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title = '';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description = '';
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $notices = array();
|
||||
/**
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $recommended = false;
|
||||
/**
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $disabled = false;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $php = WPMS_PHP_VER;
|
||||
/**
|
||||
* @var Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* ProviderAbstract constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function __construct( $params ) {
|
||||
|
||||
if (
|
||||
empty( $params['slug'] ) ||
|
||||
empty( $params['title'] )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->slug = sanitize_key( $params['slug'] );
|
||||
$this->title = sanitize_text_field( $params['title'] );
|
||||
|
||||
if ( ! empty( $params['description'] ) ) {
|
||||
$this->description = wp_kses_post( $params['description'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['notices'] ) ) {
|
||||
foreach ( (array) $params['notices'] as $key => $notice ) {
|
||||
$key = sanitize_key( $key );
|
||||
if ( empty( $key ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$notice = wp_kses(
|
||||
$notice,
|
||||
array(
|
||||
'br' => true,
|
||||
'strong' => true,
|
||||
'em' => true,
|
||||
'a' => array(
|
||||
'href' => true,
|
||||
'rel' => true,
|
||||
'target' => true,
|
||||
),
|
||||
)
|
||||
);
|
||||
if ( empty( $notice ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->notices[ $key ] = $notice;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $params['recommended'] ) ) {
|
||||
$this->recommended = (bool) $params['recommended'];
|
||||
}
|
||||
if ( isset( $params['disabled'] ) ) {
|
||||
$this->disabled = (bool) $params['disabled'];
|
||||
}
|
||||
|
||||
if ( ! empty( $params['php'] ) ) {
|
||||
$this->php = sanitize_text_field( $params['php'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $params['logo_url'] ) ) {
|
||||
$this->logo_url = esc_url_raw( $params['logo_url'] );
|
||||
}
|
||||
|
||||
$this->options = new Options();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_logo_url() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_logo_url', $this->logo_url, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_slug() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_slug', $this->slug, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_title() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_title', $this->title, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_description() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_description', $this->description, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Some mailers may display a notice above its options.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_notice( $type ) {
|
||||
|
||||
$type = sanitize_key( $type );
|
||||
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_notice', isset( $this->notices[ $type ] ) ? $this->notices[ $type ] : '', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function get_php_version() {
|
||||
return apply_filters( 'wp_mail_smtp_providers_provider_get_php_version', $this->php, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function display_options() {
|
||||
?>
|
||||
|
||||
<!-- SMTP Host -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-host" 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() ); ?>-host"><?php esc_html_e( 'SMTP Host', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][host]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'host' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'host' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-host" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Encryption -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-encryption" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-radio wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label><?php esc_html_e( 'Encryption', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-none"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="none"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'none', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'None', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-ssl"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="ssl"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'ssl', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'SSL', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls">
|
||||
<input type="radio" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-enc-tls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][encryption]" value="tls"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( 'tls', $this->options->get( $this->get_slug(), 'encryption' ) ); ?>
|
||||
/>
|
||||
<?php esc_html_e( 'TLS', 'wp-mail-smtp' ); ?>
|
||||
</label>
|
||||
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'For most servers TLS is the recommended option. If your SMTP provider offers both SSL and TLS options, we recommend using TLS.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Port -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-number wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port"><?php esc_html_e( 'SMTP Port', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][port]" type="number"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'port' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'port' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-port" class="small-text" spellcheck="false"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PHPMailer SMTPAutoTLS -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-autotls" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear <?php echo $this->options->is_const_defined( $this->get_slug(), 'encryption' ) || 'tls' === $this->options->get( $this->get_slug(), 'encryption' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"><?php esc_html_e( 'Auto TLS', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-autotls"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][autotls]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'autotls' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'autotls' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'By default TLS encryption is automatically used if the server supports it, which is recommended. In some cases, due to server misconfigurations, this can cause issues and may need to be disabled.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Authentication -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-auth" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle wp-mail-smtp-clear">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"><?php esc_html_e( 'Authentication', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth">
|
||||
<input type="checkbox" id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-auth"
|
||||
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][auth]" value="yes"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'auth' ) ? 'disabled' : ''; ?>
|
||||
<?php checked( true, (bool) $this->options->get( $this->get_slug(), 'auth' ) ); ?>
|
||||
/>
|
||||
<span class="wp-mail-smtp-setting-toggle-switch"></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-checked-label"><?php esc_html_e( 'On', 'wp-mail-smtp' ); ?></span>
|
||||
<span class="wp-mail-smtp-setting-toggle-unchecked-label"><?php esc_html_e( 'Off', 'wp-mail-smtp' ); ?></span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Username -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-user" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user"><?php esc_html_e( 'SMTP Username', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][user]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'user' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'user' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-user" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SMTP Password -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-pass" class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-password wp-mail-smtp-clear <?php echo ! $this->options->is_const_defined( $this->get_slug(), 'auth' ) && ! $this->options->get( $this->get_slug(), 'auth' ) ? 'inactive' : ''; ?>">
|
||||
<div class="wp-mail-smtp-setting-label">
|
||||
<label for="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"><?php esc_html_e( 'SMTP Password', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<?php if ( $this->options->is_const_defined( $this->get_slug(), 'pass' ) ) : ?>
|
||||
<input type="text" value="*************" disabled id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass"/>
|
||||
|
||||
<?php $this->display_const_set_message( 'WPMS_SMTP_PASS' ); ?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - constant name: WPMS_SMTP_PASS. */
|
||||
esc_html__( 'To change the password you need to change the value of the constant there: %s', 'wp-mail-smtp' ),
|
||||
'<code>define( \'WPMS_SMTP_PASS\', \'your_old_password\' );</code>'
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - wp-config.php file, %2$s - WPMS_ON constant name. */
|
||||
esc_html__( 'If you want to disable the use of constants, find in %1$s file the constant %2$s and turn if off:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>',
|
||||
'<code>WPMS_ON</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', false );
|
||||
</pre>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'All the defined constants will stop working and you will be able to change all the values on this page.', 'wp-mail-smtp' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][pass]" type="password"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'pass' ) ); ?>"
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="new-password"
|
||||
/>
|
||||
<p class="desc">
|
||||
<?php esc_html_e( 'The password is stored in plain text. We highly recommend you set up your password in your WordPress configuration file for improved security.', 'wp-mail-smtp' ); ?>
|
||||
<br>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - wp-config.php. */
|
||||
esc_html__( 'To do this add the lines below to your %s file:', 'wp-mail-smtp' ),
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<pre>
|
||||
define( 'WPMS_ON', true );
|
||||
define( 'WPMS_SMTP_PASS', 'your_password' );
|
||||
</pre>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is recommended or not.
|
||||
*
|
||||
* @since 1.6.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_recommended() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_recommended', $this->recommended, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this mailer is disabled or not.
|
||||
* Used for displaying Pro mailers inside Lite plugin.
|
||||
*
|
||||
* @since 1.7.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_disabled() {
|
||||
|
||||
return (bool) apply_filters( 'wp_mail_smtp_providers_provider_is_disabled', $this->disabled, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we can use this provider based on the PHP version.
|
||||
* Valid for those, that use SDK.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_php_correct() {
|
||||
return version_compare( phpversion(), $this->php, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function display_php_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %1$s - Provider name; %2$s - PHP version required by Provider; %3$s - current PHP version. */
|
||||
esc_html__( '%1$s requires PHP %2$s to work and does not support your current PHP version %3$s. Please contact your host and request a PHP upgrade to the latest one.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() ),
|
||||
esc_html( $this->php ),
|
||||
esc_html( phpversion() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a helpful message to those users, that are using an outdated version of PHP,
|
||||
* which is not supported by the currently selected Provider.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
protected function display_ssl_warning() {
|
||||
?>
|
||||
|
||||
<blockquote>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s - Provider name. */
|
||||
esc_html__( '%s requires a SSL certificate on a site to work and does not support your current installation. Please contact your host and request a SSL certificate or install a free one, like Let\'s Encrypt.', 'wp-mail-smtp' ),
|
||||
esc_html( $this->get_title() )
|
||||
);
|
||||
?>
|
||||
<br>
|
||||
<?php esc_html_e( 'Meanwhile you can switch to some other mailers.', 'wp-mail-smtp' ); ?>
|
||||
</blockquote>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a message of a constant that was set inside wp-config.php file.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $constant Constant name.
|
||||
*/
|
||||
protected function display_const_set_message( $constant ) {
|
||||
?>
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %1$s - constant that was used; %2$s - file where it was used. */
|
||||
esc_html__( 'The value of this field was set using a constant %1$s most likely inside %2$s of your WordPress installation.', 'wp-mail-smtp' ),
|
||||
'<code>' . esc_attr( $constant ) . '</code>',
|
||||
'<code>wp-config.php</code>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class Options extends OptionsAbstract {
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= '</p><p class="buttonned"><a href="https://wpmailsmtp.com/go/pepipost/" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">' .
|
||||
esc_html__( 'Get Pepipost Now (Free)', 'wp-mail-smtp' ) .
|
||||
esc_html__( 'Get Started with Pepipost', 'wp-mail-smtp' ) .
|
||||
'</a></p>';
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ class Options extends OptionsAbstract {
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - pepipost.com link to get an API Key. */
|
||||
printf( /* translators: %s - link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://app.pepipost.com/app/settings/integration" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get the API Key', 'wp-mail-smtp' ) .
|
||||
|
@ -1,44 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class SMTP.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* SMTP constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp.svg',
|
||||
'slug' => 'smtp',
|
||||
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to a related article on WPForms.com. */
|
||||
__( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="%s" target="_blank" rel="noopener noreferrer">SMTP documentation</a>.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-other-smtp-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTP;
|
||||
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class SMTP.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* SMTP constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp.svg',
|
||||
'slug' => 'smtp',
|
||||
'title' => esc_html__( 'Other SMTP', 'wp-mail-smtp' ),
|
||||
'description' => sprintf(
|
||||
wp_kses(
|
||||
/* translators: %s - URL to SMTP documentation. */
|
||||
__( 'Use the SMTP details provided by your hosting provider or email service.<br><br>To see recommended settings for the popular services as well as troubleshooting tips, check out our <a href="%s" target="_blank" rel="noopener noreferrer">SMTP documentation</a>.', 'wp-mail-smtp' ),
|
||||
array(
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
)
|
||||
),
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-other-smtp-mailer-in-wp-mail-smtp/'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
460
wp-content/plugins/wp-mail-smtp/src/Providers/SMTPcom/Mailer.php
Normal file
460
wp-content/plugins/wp-mail-smtp/src/Providers/SMTPcom/Mailer.php
Normal file
@ -0,0 +1,460 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTPcom;
|
||||
|
||||
use WPMailSMTP\Providers\MailerAbstract;
|
||||
use WPMailSMTP\WP;
|
||||
|
||||
/**
|
||||
* Class Mailer for SMTP.com integration.
|
||||
*
|
||||
* @see https://www.smtp.com/smtp-api-documentation/ for the API documentation.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Mailer extends MailerAbstract {
|
||||
|
||||
/**
|
||||
* Which response code from HTTP provider is considered to be successful?
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $email_sent_code = 200;
|
||||
|
||||
/**
|
||||
* URL to make an API request to.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url = 'https://api.smtp.com/v4/messages';
|
||||
|
||||
/**
|
||||
* Mailer constructor.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param \WPMailSMTP\MailCatcher $phpmailer
|
||||
*/
|
||||
public function __construct( $phpmailer ) {
|
||||
|
||||
// We want to prefill everything from \WPMailSMTP\MailCatcher class, which extends \PHPMailer.
|
||||
parent::__construct( $phpmailer );
|
||||
|
||||
// Set mailer specific headers.
|
||||
$this->set_header( 'Authorization', 'Bearer ' . $this->options->get( $this->mailer, 'api_key' ) );
|
||||
$this->set_header( 'Accept', 'application/json' );
|
||||
$this->set_header( 'content-type', 'application/json' );
|
||||
|
||||
// Set mailer specific body parameters.
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'channel' => $this->options->get( $this->mailer, 'channel' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way email body is returned.
|
||||
* By default we are sending an array of data.
|
||||
* SMTP.com requires a JSON, so we encode the body.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_body() {
|
||||
|
||||
$body = parent::get_body();
|
||||
|
||||
return wp_json_encode( $body );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the FROM (name and email).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $email From Email address.
|
||||
* @param string $name From Name.
|
||||
*/
|
||||
public function set_from( $email, $name = '' ) {
|
||||
|
||||
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$from['address'] = $email;
|
||||
|
||||
if ( ! empty( $name ) ) {
|
||||
$from['name'] = $name;
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'originator' => array(
|
||||
'from' => $from,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the CC/BCC/TO (with names and emails).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $recipients
|
||||
*/
|
||||
public function set_recipients( $recipients ) {
|
||||
|
||||
if ( empty( $recipients ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow only these recipient types.
|
||||
$allowed_types = array( 'to', 'cc', 'bcc' );
|
||||
$data = array();
|
||||
|
||||
foreach ( $recipients as $type => $emails ) {
|
||||
if (
|
||||
! in_array( $type, $allowed_types, true ) ||
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data[ $type ] = array();
|
||||
|
||||
// Iterate over all emails for each type.
|
||||
// There might be multiple cc/to/bcc emails.
|
||||
foreach ( $emails as $email ) {
|
||||
$holder = array();
|
||||
$address = isset( $email[0] ) ? $email[0] : false;
|
||||
$name = isset( $email[1] ) ? $email[1] : false;
|
||||
|
||||
if ( ! filter_var( $address, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$holder['address'] = $address;
|
||||
if ( ! empty( $name ) ) {
|
||||
$holder['name'] = $name;
|
||||
}
|
||||
|
||||
array_push( $data[ $type ], $holder );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'recipients' => $data,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the email content.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array|string $content String when text/plain, array otherwise.
|
||||
*/
|
||||
public function set_content( $content ) {
|
||||
|
||||
if ( empty( $content ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$parts = array();
|
||||
|
||||
if ( is_array( $content ) ) {
|
||||
$allowed = array( 'text', 'html' );
|
||||
|
||||
foreach ( $content as $type => $body ) {
|
||||
if (
|
||||
! in_array( $type, $allowed, true ) ||
|
||||
empty( $body )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$content_type = 'text/plain';
|
||||
$content_value = $body;
|
||||
|
||||
if ( $type === 'html' ) {
|
||||
$content_type = 'text/html';
|
||||
}
|
||||
|
||||
$parts[] = array(
|
||||
'type' => $content_type,
|
||||
'content' => $content_value,
|
||||
'charset' => $this->phpmailer->CharSet,
|
||||
'encoding' => $this->phpmailer->Encoding,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$content_type = 'text/html';
|
||||
$content_value = $content;
|
||||
|
||||
if ( $this->phpmailer->ContentType === 'text/plain' ) {
|
||||
$content_type = 'text/plain';
|
||||
}
|
||||
|
||||
$parts[] = array(
|
||||
'type' => $content_type,
|
||||
'content' => $content_value,
|
||||
'charset' => $this->phpmailer->CharSet,
|
||||
'encoding' => $this->phpmailer->Encoding,
|
||||
);
|
||||
}
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'body' => array(
|
||||
'parts' => $parts,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redefine the way custom headers are processed for this mailer - they should be in body.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $headers
|
||||
*/
|
||||
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 2.0.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_body_header( $name, $value ) {
|
||||
|
||||
$name = sanitize_text_field( $name );
|
||||
if ( empty( $name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headers = isset( $this->body['custom_headers'] ) ? (array) $this->body['custom_headers'] : array();
|
||||
|
||||
$headers[ $name ] = WP::sanitize_value( $value );
|
||||
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'custom_headers' => $headers,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SMTP.com accepts an array of attachments in body.attachments section of the JSON payload.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $attachments
|
||||
*/
|
||||
public function set_attachments( $attachments ) {
|
||||
|
||||
if ( empty( $attachments ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$file = false;
|
||||
|
||||
/*
|
||||
* We are not using WP_Filesystem API as we can't reliably work with it.
|
||||
* It is not always available, same as credentials for FTP.
|
||||
*/
|
||||
try {
|
||||
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
|
||||
$file = file_get_contents( $attachment[0] ); // phpcs:ignore
|
||||
}
|
||||
}
|
||||
catch ( \Exception $e ) {
|
||||
$file = false;
|
||||
}
|
||||
|
||||
if ( $file === false ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
|
||||
|
||||
$data[] = array(
|
||||
'content' => base64_encode( $file ),
|
||||
'type' => $filetype,
|
||||
'encoding' => 'base64',
|
||||
'filename' => empty( $attachment[2] ) ? 'file-' . wp_hash( microtime() ) . '.' . $filetype : trim( $attachment[2] ),
|
||||
'disposition' => in_array( $attachment[6], array( 'inline', 'attachment' ), true ) ? $attachment[6] : 'attachment', // either inline or attachment.
|
||||
'cid' => empty( $attachment[7] ) ? '' : trim( (string) $attachment[7] ),
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'body' => array(
|
||||
'attachments' => $data,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Reply-To part of the message.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param array $reply_to
|
||||
*/
|
||||
public function set_reply_to( $reply_to ) {
|
||||
|
||||
if ( empty( $reply_to ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $reply_to as $key => $emails ) {
|
||||
if (
|
||||
empty( $emails ) ||
|
||||
! is_array( $emails )
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$address = isset( $emails[0] ) ? $emails[0] : false;
|
||||
$name = isset( $emails[1] ) ? $emails[1] : false;
|
||||
|
||||
if ( ! filter_var( $address, FILTER_VALIDATE_EMAIL ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['address'] = $address;
|
||||
if ( ! empty( $name ) ) {
|
||||
$data['name'] = $name;
|
||||
}
|
||||
|
||||
// Let the first valid email from the passed $reply_to serve as the reply_to parameter in STMP.com API.
|
||||
// Only one email address and name is allowed in the `reply_to` parameter in the SMTP.com API payload.
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
$this->set_body_param(
|
||||
array(
|
||||
'originator' => array(
|
||||
'reply_to' => $data,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SMTP.com doesn't support return_path params.
|
||||
* So we do nothing.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $from_email
|
||||
*/
|
||||
public function set_return_path( $from_email ) {}
|
||||
|
||||
/**
|
||||
* Get a SMTP.com-specific response with a helpful error.
|
||||
*
|
||||
* SMTP.com API error response (non 200 error code responses) is:
|
||||
* {
|
||||
* "status": "fail",
|
||||
* "data": {
|
||||
* "error_key": "short error message",
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* It's good to combine the error_key and the message together for the best error explanation.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_response_error() {
|
||||
|
||||
$body = (array) wp_remote_retrieve_body( $this->response );
|
||||
|
||||
$error_text = array();
|
||||
|
||||
if ( ! empty( $body['data'] ) ) {
|
||||
foreach ( (array) $body['data'] as $error_key => $error_message ) {
|
||||
$error_text[] = $error_key . ' - ' . $error_message;
|
||||
}
|
||||
}
|
||||
|
||||
return implode( PHP_EOL, array_map( 'esc_textarea', $error_text ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mailer debug information, that is helpful during support.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_debug_info() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
$text[] = '<strong>' . esc_html__( 'Api Key:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['api_key'] ) ? 'Yes' : 'No' );
|
||||
$text[] = '<strong>' . esc_html__( 'Channel:', 'wp-mail-smtp' ) . '</strong> ' .
|
||||
( ! empty( $options['channel'] ) ? 'Yes' : 'No' );
|
||||
|
||||
return implode( '<br>', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the mailer has all its settings correctly set up and saved.
|
||||
*
|
||||
* This mailer is configured when `api_key` and `channel` settings are defined.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mailer_complete() {
|
||||
|
||||
$options = $this->options->get_group( $this->mailer );
|
||||
|
||||
if ( ! empty( $options['api_key'] ) && ! empty( $options['channel'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP\Providers\SMTPcom;
|
||||
|
||||
use WPMailSMTP\Options as PluginOptions;
|
||||
use WPMailSMTP\Providers\OptionsAbstract;
|
||||
|
||||
/**
|
||||
* Class Options.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class Options extends OptionsAbstract {
|
||||
|
||||
/**
|
||||
* Mailer slug.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
const SLUG = 'smtpcom';
|
||||
|
||||
/**
|
||||
* Options constructor.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$allowed_kses_html = array(
|
||||
'strong' => array(),
|
||||
'br' => array(),
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
'rel' => array(),
|
||||
'target' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %s - URL to smtp.com site. */
|
||||
__( '<strong><a href="%s" target="_blank" rel="noopener noreferrer">SMTP.com</a> is a recommended transactional email service.</strong> With over 22 years of email delivery expertise, SMTP.com has been around for almost as long as email itself. They are known among internet providers as one of the most reliable senders on the internet. Their easy integration process lets you start sending emails in minutes and benefit from years of experience. SMTP.com provides users 10,000 free emails the first 30 days.', 'wp-mail-smtp' ),
|
||||
$allowed_kses_html
|
||||
),
|
||||
'https://wpmailsmtp.com/go/smtp/'
|
||||
);
|
||||
$description .= '<br><br>';
|
||||
$description .= sprintf(
|
||||
wp_kses( /* translators: %s - URL to wpmailsmtp.com doc page for stmp.com. */
|
||||
__( 'Read our <a href="%s" target="_blank" rel="noopener noreferrer">SMTP.com documentation</a> to learn how to configure SMTP.com and improve your email deliverability.', 'wp-mail-smtp' ),
|
||||
$allowed_kses_html
|
||||
),
|
||||
'https://wpmailsmtp.com/docs/how-to-set-up-the-smtp-com-mailer-in-wp-mail-smtp'
|
||||
);
|
||||
|
||||
$mailer_options = PluginOptions::init()->get_group( self::SLUG );
|
||||
|
||||
if ( empty( $mailer_options['api_key'] ) && empty( $mailer_options['channel'] ) ) {
|
||||
$description .= '</p><p class="buttonned"><a href="https://wpmailsmtp.com/go/smtp/" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">' .
|
||||
esc_html__( 'Get Started with SMTP.com', 'wp-mail-smtp' ) .
|
||||
'</a></p>';
|
||||
}
|
||||
|
||||
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,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_SMTPCOM_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 SMTP.com: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://my.smtp.com/settings/api" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get API Key', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Channel/Sender -->
|
||||
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-channel" 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() ); ?>-channel"><?php esc_html_e( 'Sender Name', 'wp-mail-smtp' ); ?></label>
|
||||
</div>
|
||||
<div class="wp-mail-smtp-setting-field">
|
||||
<input name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][channel]" type="text"
|
||||
value="<?php echo esc_attr( $this->options->get( $this->get_slug(), 'channel' ) ); ?>"
|
||||
<?php echo $this->options->is_const_defined( $this->get_slug(), 'channel' ) ? 'disabled' : ''; ?>
|
||||
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-channel" spellcheck="false"
|
||||
/>
|
||||
<?php
|
||||
if ( $this->options->is_const_defined( $this->get_slug(), 'channel' ) ) {
|
||||
$this->display_const_set_message( 'WPMS_SMTPCOM_CHANNEL' );
|
||||
}
|
||||
?>
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - Channel/Sender Name link for smtp.com documentation. */
|
||||
esc_html__( 'Follow this link to get a Sender Name from SMTP.com: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://my.smtp.com/senders/" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get Sender Name', 'wp-mail-smtp' ) .
|
||||
'</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
@ -26,42 +26,30 @@ class Options extends OptionsAbstract {
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$description = sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to sendinblue.com site. */
|
||||
__( '<strong><a href="%1$s" target="_blank" rel="noopener noreferrer">Sendinblue</a> is a recommended transactional email service.</strong> Founded in 2012, they serve 80,000+ growing companies around the world and send over 30 million emails each day. They understand that transactional emails are the heart of your customer relationships. Their email deliverability experts are constantly at work optimizing the reliability and speed of their SMTP infrastructure. Sendinblue provides users 300 free emails per day.', 'wp-mail-smtp' ) .
|
||||
'<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,
|
||||
'strong' => true,
|
||||
'a' => array(
|
||||
'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'
|
||||
);
|
||||
|
||||
$api_key = PluginOptions::init()->get( self::SLUG, 'api_key' );
|
||||
|
||||
if ( empty( $api_key ) ) {
|
||||
$description .= '</p><p class="buttonned"><a href="https://wpmailsmtp.com/go/sendinblue/" target="_blank" rel="noopener noreferrer" class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-blueish">' .
|
||||
esc_html__( 'Get Sendinblue Now (Free)', 'wp-mail-smtp' ) .
|
||||
'</a></p>';
|
||||
}
|
||||
|
||||
parent::__construct(
|
||||
array(
|
||||
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendinblue.svg',
|
||||
'slug' => self::SLUG,
|
||||
'title' => esc_html__( 'Sendinblue', 'wp-mail-smtp' ),
|
||||
'description' => $description,
|
||||
'recommended' => true,
|
||||
'php' => '5.6',
|
||||
'description' => sprintf(
|
||||
wp_kses( /* translators: %1$s - URL to sendinblue.com site. */
|
||||
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Sendinblue</a> serves 80,000+ growing companies around the world and sends over 30 million emails each day. They provide users 300 free emails per day.', 'wp-mail-smtp' ) .
|
||||
'<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(
|
||||
'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'
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -103,7 +91,7 @@ class Options extends OptionsAbstract {
|
||||
|
||||
<p class="desc">
|
||||
<?php
|
||||
printf( /* translators: %s - sendinblue.com link to get an API Key. */
|
||||
printf( /* translators: %s - link to get an API Key. */
|
||||
esc_html__( 'Follow this link to get an API Key: %s.', 'wp-mail-smtp' ),
|
||||
'<a href="https://account.sendinblue.com/advanced/api" target="_blank" rel="noopener noreferrer">' .
|
||||
esc_html__( 'Get v3 API Key', 'wp-mail-smtp' ) .
|
||||
|
@ -5,7 +5,7 @@ namespace WPMailSMTP;
|
||||
/**
|
||||
* Class SiteHealth adds the plugin status and information to the WP Site Health admin page.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
class SiteHealth {
|
||||
|
||||
@ -15,7 +15,7 @@ class SiteHealth {
|
||||
*
|
||||
* @see https://make.wordpress.org/core/2019/04/25/site-health-check-in-5-2/
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
const BADGE_COLOR = 'blue';
|
||||
|
||||
@ -24,14 +24,14 @@ class SiteHealth {
|
||||
* This should be a plugin unique string, which will be used in the WP Site Health page,
|
||||
* for the "info" tab and will present the plugin info section.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
const DEBUG_INFO_SLUG = 'wp_mail_smtp';
|
||||
|
||||
/**
|
||||
* Translatable string for the plugin label.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -43,7 +43,7 @@ class SiteHealth {
|
||||
/**
|
||||
* Initialize the site heath functionality.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
@ -55,7 +55,7 @@ class SiteHealth {
|
||||
* Register plugin WP site health tests.
|
||||
* This will be displayed in the "Status" tab of the WP Site Health page.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @param array $tests The array with all WP site health tests.
|
||||
*
|
||||
@ -75,7 +75,7 @@ class SiteHealth {
|
||||
* Register plugin WP Site Health debug information.
|
||||
* This will be displayed in the "Info" tab of the WP Site Health page.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*
|
||||
* @param array $debug_info Array of existing debug information.
|
||||
*
|
||||
@ -109,7 +109,7 @@ class SiteHealth {
|
||||
/**
|
||||
* Perform the WP site health test for checking, if the mailer setup is complete.
|
||||
*
|
||||
* @since {VERSION}
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public function mailer_setup_complete_test() {
|
||||
|
||||
|
@ -1,234 +1,234 @@
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class WP provides WordPress shortcuts.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class WP {
|
||||
|
||||
/**
|
||||
* The "queue" of notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $admin_notices = array();
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_SUCCESS = 'notice-success';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_ERROR = 'notice-error';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_INFO = 'notice-info';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_WARNING = 'notice-warning';
|
||||
|
||||
/**
|
||||
* True is WP is processing an AJAX call.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_doing_ajax() {
|
||||
|
||||
if ( function_exists( 'wp_doing_ajax' ) ) {
|
||||
return wp_doing_ajax();
|
||||
}
|
||||
|
||||
return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* True if I am in the Admin Panel, not doing AJAX.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function in_wp_admin() {
|
||||
|
||||
return ( is_admin() && ! self::is_doing_ajax() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice to the "queue of notices".
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added `$is_dismissible` param.
|
||||
*
|
||||
* @param string $message Message text (HTML is OK).
|
||||
* @param string $class Display class (severity).
|
||||
* @param bool $is_dismissible Whether the message should be dismissible.
|
||||
*/
|
||||
public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO, $is_dismissible = true ) {
|
||||
|
||||
self::$admin_notices[] = array(
|
||||
'message' => $message,
|
||||
'class' => $class,
|
||||
'is_dismissible' => (bool) $is_dismissible,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Allow the notice to be dismissible, remove the id attribute, which is not unique.
|
||||
*/
|
||||
public static function display_admin_notices() {
|
||||
|
||||
foreach ( (array) self::$admin_notices as $notice ) :
|
||||
$dismissible = $notice['is_dismissible'] ? 'is-dismissible' : '';
|
||||
?>
|
||||
|
||||
<div class="notice wp-mail-smtp-notice <?php echo esc_attr( $notice['class'] ); ?> notice <?php echo esc_attr( $dismissible ); ?>">
|
||||
<p>
|
||||
<?php echo $notice['message']; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether WP_DEBUG is active.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_debug() {
|
||||
|
||||
return defined( 'WP_DEBUG' ) && WP_DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to global $wpdb.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \wpdb
|
||||
*/
|
||||
public static function wpdb() {
|
||||
global $wpdb;
|
||||
|
||||
return $wpdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the postfix for assets files - ".min" or empty.
|
||||
* ".min" if in production mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function asset_min() {
|
||||
|
||||
$min = '.min';
|
||||
|
||||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
|
||||
$min = '';
|
||||
}
|
||||
|
||||
return $min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the string is a JSON or not.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_json( $string ) {
|
||||
|
||||
return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full date format as per WP options.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function datetime_format() {
|
||||
|
||||
return sprintf(
|
||||
/* translators: %1$s - date, \a\t - specially escaped "at", %2$s - time. */
|
||||
esc_html__( '%1$s \a\t %2$s', 'wp-mail-smtp' ),
|
||||
get_option( 'date_format' ),
|
||||
get_option( 'time_format' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full date form as per MySQL format.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function datetime_mysql_format() {
|
||||
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the value, similar to sanitize_text_field(), but a bit differently.
|
||||
* It preserves < and > for non-HTML tags.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return mixed|string|string[]|null
|
||||
*/
|
||||
public static function sanitize_value( $value ) {
|
||||
|
||||
// Remove HTML tags.
|
||||
$filtered = wp_strip_all_tags( $value, false );
|
||||
// Remove multi-lines/tabs.
|
||||
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
|
||||
// Remove whitespaces.
|
||||
$filtered = trim( $filtered );
|
||||
|
||||
// Remove octets.
|
||||
$found = false;
|
||||
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
|
||||
$filtered = str_replace( $match[0], '', $filtered );
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $found ) {
|
||||
// Strip out the whitespace that may now exist after removing the octets.
|
||||
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
namespace WPMailSMTP;
|
||||
|
||||
/**
|
||||
* Class WP provides WordPress shortcuts.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class WP {
|
||||
|
||||
/**
|
||||
* The "queue" of notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $admin_notices = array();
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_SUCCESS = 'notice-success';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_ERROR = 'notice-error';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_INFO = 'notice-info';
|
||||
/**
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const ADMIN_NOTICE_WARNING = 'notice-warning';
|
||||
|
||||
/**
|
||||
* True is WP is processing an AJAX call.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_doing_ajax() {
|
||||
|
||||
if ( function_exists( 'wp_doing_ajax' ) ) {
|
||||
return wp_doing_ajax();
|
||||
}
|
||||
|
||||
return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
|
||||
}
|
||||
|
||||
/**
|
||||
* True if I am in the Admin Panel, not doing AJAX.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function in_wp_admin() {
|
||||
|
||||
return ( is_admin() && ! self::is_doing_ajax() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a notice to the "queue of notices".
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Added `$is_dismissible` param.
|
||||
*
|
||||
* @param string $message Message text (HTML is OK).
|
||||
* @param string $class Display class (severity).
|
||||
* @param bool $is_dismissible Whether the message should be dismissible.
|
||||
*/
|
||||
public static function add_admin_notice( $message, $class = self::ADMIN_NOTICE_INFO, $is_dismissible = true ) {
|
||||
|
||||
self::$admin_notices[] = array(
|
||||
'message' => $message,
|
||||
'class' => $class,
|
||||
'is_dismissible' => (bool) $is_dismissible,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @since 1.5.0 Allow the notice to be dismissible, remove the id attribute, which is not unique.
|
||||
*/
|
||||
public static function display_admin_notices() {
|
||||
|
||||
foreach ( (array) self::$admin_notices as $notice ) :
|
||||
$dismissible = $notice['is_dismissible'] ? 'is-dismissible' : '';
|
||||
?>
|
||||
|
||||
<div class="notice wp-mail-smtp-notice <?php echo esc_attr( $notice['class'] ); ?> notice <?php echo esc_attr( $dismissible ); ?>">
|
||||
<p>
|
||||
<?php echo $notice['message']; ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether WP_DEBUG is active.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_debug() {
|
||||
|
||||
return defined( 'WP_DEBUG' ) && WP_DEBUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to global $wpdb.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return \wpdb
|
||||
*/
|
||||
public static function wpdb() {
|
||||
global $wpdb;
|
||||
|
||||
return $wpdb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the postfix for assets files - ".min" or empty.
|
||||
* ".min" if in production mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function asset_min() {
|
||||
|
||||
$min = '.min';
|
||||
|
||||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
|
||||
$min = '';
|
||||
}
|
||||
|
||||
return $min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the string is a JSON or not.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_json( $string ) {
|
||||
|
||||
return is_string( $string ) && is_array( json_decode( $string, true ) ) && ( json_last_error() === JSON_ERROR_NONE ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full date format as per WP options.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function datetime_format() {
|
||||
|
||||
return sprintf(
|
||||
/* translators: %1$s - date, \a\t - specially escaped "at", %2$s - time. */
|
||||
esc_html__( '%1$s \a\t %2$s', 'wp-mail-smtp' ),
|
||||
get_option( 'date_format' ),
|
||||
get_option( 'time_format' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full date form as per MySQL format.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function datetime_mysql_format() {
|
||||
|
||||
return 'Y-m-d H:i:s';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the value, similar to sanitize_text_field(), but a bit differently.
|
||||
* It preserves `<` and `>` for non-HTML tags.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return mixed|string|string[]|null
|
||||
*/
|
||||
public static function sanitize_value( $value ) {
|
||||
|
||||
// Remove HTML tags.
|
||||
$filtered = wp_strip_all_tags( $value, false );
|
||||
// Remove multi-lines/tabs.
|
||||
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
|
||||
// Remove whitespaces.
|
||||
$filtered = trim( $filtered );
|
||||
|
||||
// Remove octets.
|
||||
$found = false;
|
||||
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
|
||||
$filtered = str_replace( $match[0], '', $filtered );
|
||||
$found = true;
|
||||
}
|
||||
|
||||
if ( $found ) {
|
||||
// Strip out the whitespace that may now exist after removing the octets.
|
||||
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user