plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -479,7 +479,7 @@ class AboutTab extends PageAbstract {
'wp-charitable' => [
'path' => 'charitable/charitable.php',
'icon' => wp_mail_smtp()->assets_url . '/images/about/plugin-charitable.png',
'name' => esc_html__( 'WP Charitable', 'wp-mail-smtp' ),
'name' => esc_html__( 'Charitable', 'wp-mail-smtp' ),
'desc' => esc_html__( 'Top-rated WordPress donation and fundraising plugin. Over 10,000+ non-profit organizations and website owners use Charitable to create fundraising campaigns and raise more money online.', 'wp-mail-smtp' ),
'url' => 'https://downloads.wordpress.org/plugin/charitable.zip',
],

View File

@@ -187,6 +187,35 @@ class AlertsTab extends PageAbstract {
</div>
</div>
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-alert">
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content section-heading">
<div class="wp-mail-smtp-setting-field">
<h3><?php esc_html_e( 'Discord', 'wp-mail-smtp' ); ?></h3>
<p class="desc"><?php esc_html_e( 'Paste in the Discord webhook URL youd like to use to receive alerts when email sending fails. Read our documentation on setting up Discord alerts.', 'wp-mail-smtp' ); ?></p>
</div>
</div>
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-checkbox-toggle">
<div class="wp-mail-smtp-setting-label">
<label><?php esc_html_e( 'Discord Alerts', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php
UI::toggle();
?>
</div>
</div>
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-alert-options">
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-alert-connection-options">
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-text">
<div class="wp-mail-smtp-setting-label">
<label><?php esc_html_e( 'Webhook URL', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field"><input type="text"></div>
</div>
</div>
</div>
</div>
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-alert">
<div class="wp-mail-smtp-setting-row wp-mail-smtp-setting-row-content section-heading">
<div class="wp-mail-smtp-setting-field">

View File

@@ -248,7 +248,7 @@ class SettingsTab extends PageAbstract {
</p>
<p>
<?php esc_html_e( 'We know that you will truly love WP Mail SMTP. It\'s used by over 3,000,000 websites.', 'wp-mail-smtp' ); ?>
<?php esc_html_e( 'We know that you will truly love WP Mail SMTP. It\'s used by over 4,000,000 websites.', 'wp-mail-smtp' ); ?>
</p>
<p><strong><?php esc_html_e( 'Pro Features:', 'wp-mail-smtp' ); ?></strong></p>

View File

@@ -991,7 +991,7 @@ Co-Founder, WP Mail SMTP';
],
]
),
'https://app.mailgun.com/app/sending/domains'
'https://app.mailgun.com/mg/sending/domains'
),
esc_html__( 'Verify your domain Region is correct.', 'wp-mail-smtp' ),
],

View File

@@ -32,6 +32,7 @@ class Helpers {
'postmark',
'sparkpost',
'smtp2go',
'mailjet',
],
true
);

View File

@@ -28,7 +28,7 @@ class Options {
* @var array Map of all the default options of the plugin.
*/
private static $map = [
'mail' => [
'mail' => [
'from_name',
'from_email',
'mailer',
@@ -36,7 +36,7 @@ class Options {
'from_name_force',
'from_email_force',
],
'smtp' => [
'smtp' => [
'host',
'port',
'encryption',
@@ -45,60 +45,64 @@ class Options {
'user',
'pass',
],
'gmail' => [
'gmail' => [
'one_click_setup_enabled',
'client_id',
'client_secret',
],
'outlook' => [
'outlook' => [
'client_id',
'client_secret',
],
'zoho' => [
'zoho' => [
'domain',
'client_id',
'client_secret',
],
'amazonses' => [
'amazonses' => [
'client_id',
'client_secret',
'region',
],
'mailgun' => [
'mailgun' => [
'api_key',
'domain',
'region',
],
'sendgrid' => [
'mailjet' => [
'api_key',
'secret_key',
],
'sendgrid' => [
'api_key',
'domain',
],
'sparkpost' => [
'sparkpost' => [
'api_key',
'region',
],
'postmark' => [
'postmark' => [
'server_api_token',
'message_stream',
],
'smtpcom' => [
'smtpcom' => [
'api_key',
'channel',
],
'sendinblue' => [
'sendinblue' => [
'api_key',
'domain',
],
'sendlayer' => [
'sendlayer' => [
'api_key',
],
'smtp2go' => [
'smtp2go' => [
'api_key',
],
'pepipostapi' => [
'pepipostapi' => [
'api_key',
],
'pepipost' => [
'pepipost' => [
'host',
'port',
'encryption',
@@ -106,26 +110,30 @@ class Options {
'user',
'pass',
],
'license' => [
'license' => [
'key',
],
'alert_email' => [
'alert_email' => [
'enabled',
'connections',
],
'alert_slack_webhook' => [
'alert_slack_webhook' => [
'enabled',
'connections',
],
'alert_twilio_sms' => [
'alert_discord_webhook' => [
'enabled',
'connections',
],
'alert_custom_webhook' => [
'alert_twilio_sms' => [
'enabled',
'connections',
],
'alert_events' => [
'alert_custom_webhook' => [
'enabled',
'connections',
],
'alert_events' => [
'email_hard_bounced',
],
];
@@ -144,6 +152,7 @@ class Options {
'amazonses',
'gmail',
'mailgun',
'mailjet',
'outlook',
'postmark',
'sendgrid',
@@ -319,7 +328,7 @@ class Options {
* Get the values saved in DB.
* If plugin is configured with constants right from the start - this will not have all the values.
*/
$options = isset( $this->options[ $group ] ) ? $this->options[ $group ] : array();
$options = isset( $this->options[ $group ] ) ? $this->options[ $group ] : [];
// We need to process certain constants-aware options through actual constants.
if ( isset( self::$map[ $group ] ) ) {
@@ -439,7 +448,7 @@ class Options {
break;
case 'encryption':
$value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? 'none' : $value;
$value = in_array( $group, [ 'smtp', 'pepipost' ], true ) ? 'none' : $value;
break;
case 'region':
@@ -448,7 +457,7 @@ class Options {
case 'auth':
case 'autotls':
$value = in_array( $group, array( 'smtp', 'pepipost' ), true ) ? false : true;
$value = in_array( $group, [ 'smtp', 'pepipost' ], true ) ? false : true;
break;
case 'pass':
@@ -479,7 +488,7 @@ class Options {
*
* @param string $group
* @param string $key
* @param mixed $value
* @param mixed $value
*
* @return mixed
*/
@@ -648,6 +657,20 @@ class Options {
break;
case 'mailjet':
switch ( $key ) {
case 'api_key':
/** @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_MAILJET_API_KEY : $value;
break;
case 'secret_key':
/** @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_MAILJET_SECRET_KEY : $value;
break;
}
break;
case 'sendgrid':
switch ( $key ) {
case 'api_key':
@@ -754,6 +777,15 @@ class Options {
break;
case 'alert_discord_webhook':
switch ( $key ) {
case 'connections':
$return = $this->is_const_defined( $group, $key ) ? [ [ 'webhook_url' => WPMS_ALERT_DISCORD_WEBHOOK_URL ] ] : $value;
break;
}
break;
case 'alert_teams_webhook':
switch ( $key ) {
case 'connections':
@@ -1016,6 +1048,18 @@ class Options {
break;
case 'mailjet':
switch ( $key ) {
case 'api_key':
$return = defined( 'WPMS_MAILJET_API_KEY' ) && WPMS_MAILJET_API_KEY;
break;
case 'secret_key':
$return = defined( 'WPMS_MAILJET_SECRET_KEY' ) && WPMS_MAILJET_SECRET_KEY;
break;
}
break;
case 'sendgrid':
switch ( $key ) {
case 'api_key':
@@ -1112,6 +1156,15 @@ class Options {
break;
case 'alert_discord_webhook':
switch ( $key ) {
case 'connections':
$return = defined( 'WPMS_ALERT_DISCORD_WEBHOOK_URL' ) && WPMS_ALERT_DISCORD_WEBHOOK_URL;
break;
}
break;
case 'alert_teams_webhook':
switch ( $key ) {
case 'connections':
@@ -1125,9 +1178,9 @@ class Options {
switch ( $key ) {
case 'connections':
$return = defined( 'WPMS_ALERT_TWILIO_SMS_ACCOUNT_SID' ) && WPMS_ALERT_TWILIO_SMS_ACCOUNT_SID &&
defined( 'WPMS_ALERT_TWILIO_SMS_AUTH_TOKEN' ) && WPMS_ALERT_TWILIO_SMS_AUTH_TOKEN &&
defined( 'WPMS_ALERT_TWILIO_SMS_FROM_PHONE_NUMBER' ) && WPMS_ALERT_TWILIO_SMS_FROM_PHONE_NUMBER &&
defined( 'WPMS_ALERT_TWILIO_SMS_TO_PHONE_NUMBER' ) && WPMS_ALERT_TWILIO_SMS_TO_PHONE_NUMBER;
defined( 'WPMS_ALERT_TWILIO_SMS_AUTH_TOKEN' ) && WPMS_ALERT_TWILIO_SMS_AUTH_TOKEN &&
defined( 'WPMS_ALERT_TWILIO_SMS_FROM_PHONE_NUMBER' ) && WPMS_ALERT_TWILIO_SMS_FROM_PHONE_NUMBER &&
defined( 'WPMS_ALERT_TWILIO_SMS_TO_PHONE_NUMBER' ) && WPMS_ALERT_TWILIO_SMS_TO_PHONE_NUMBER;
break;
}
@@ -1356,11 +1409,13 @@ class Options {
if ( $mailer === 'smtp' && ! $this->is_const_defined( 'smtp', 'pass' ) ) {
try {
$options[ $mailer ][ $option_name ] = Crypto::encrypt( $option_value );
} catch ( \Exception $e ) {} // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch, Squiz.Commenting.EmptyCatchComment.Missing, Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
} catch ( \Exception $e ) {
} // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch, Squiz.Commenting.EmptyCatchComment.Missing, Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
}
break;
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom/sparkpost/sendlayer/smtp2go.
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom/sparkpost/sendlayer/smtp2go/mailjet.
case 'secret_key': // mailjet.
case 'domain': // mailgun/zoho/sendgrid/sendinblue.
case 'client_id': // gmail/outlook/amazonses/zoho.
case 'client_secret': // gmail/outlook/amazonses/zoho.
@@ -1396,16 +1451,16 @@ class Options {
$arrays = func_get_args();
if ( count( $arrays ) < 2 ) {
return isset( $arrays[0] ) ? $arrays[0] : array();
return isset( $arrays[0] ) ? $arrays[0] : [];
}
$merged = array();
$merged = [];
while ( $arrays ) {
$array = array_shift( $arrays );
if ( ! is_array( $array ) ) {
return array();
return [];
}
if ( empty( $array ) ) {
@@ -1435,11 +1490,11 @@ class Options {
/**
* Check whether the site is using Pepipost SMTP or not.
*
* @deprecated 2.4.0
*
* @since 1.0.0
* @since 1.0.0
*
* @return bool
* @deprecated 2.4.0
*
*/
public function is_pepipost_active() {
@@ -1479,7 +1534,7 @@ class Options {
* @return bool
*/
public function is_mailer_smtp() {
return apply_filters( 'wp_mail_smtp_options_is_mailer_smtp', in_array( $this->get( 'mail', 'mailer' ), array( 'pepipost', 'smtp' ), true ) );
return apply_filters( 'wp_mail_smtp_options_is_mailer_smtp', in_array( $this->get( 'mail', 'mailer' ), [ 'pepipost', 'smtp' ], true ) );
}
/**

View File

@@ -134,11 +134,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_GMAIL_CLIENT_SECRET' ); ?>
<?php else : ?>
<input type="password" spellcheck="false"
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][client_secret]"
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'client_secret' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-client_secret"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'client_secret' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][client_secret]",
'id' => "wp-mail-smtp-setting-{$slug}-client_secret",
'value' => $value,
'clear_text' => esc_html__( 'Remove Client Secret', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
</div>
</div>

View File

@@ -21,6 +21,7 @@ class Loader {
* @since 1.6.0 Added Sendinblue.
* @since 1.7.0 Added AmazonSES/Outlook as indication of the Pro mailers.
* @since 4.1.0 Added SMTP2GO.
* @since 4.2.0 Added Mailjet.
*
* @var array
*/
@@ -32,6 +33,7 @@ class Loader {
'amazonses' => 'WPMailSMTP\Providers\AmazonSES\\',
'gmail' => 'WPMailSMTP\Providers\Gmail\\',
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
'mailjet' => 'WPMailSMTP\Providers\Mailjet\\',
'outlook' => 'WPMailSMTP\Providers\Outlook\\',
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
'postmark' => 'WPMailSMTP\Providers\Postmark\\',
@@ -111,7 +113,7 @@ class Loader {
*/
public function get_options_all( $connection = null ) {
$options = array();
$options = [];
foreach ( $this->get_providers() as $provider => $path ) {
@@ -166,17 +168,17 @@ class Loader {
/**
* Get a generic entity based on the request.
*
* @uses \ReflectionClass
*
* @since 1.0.0
*
* @param string $provider
* @param string $request
* @param array $args Entity instantiation arguments.
* @param array $args Entity instantiation arguments.
*
* @return OptionsAbstract|MailerAbstract|AuthAbstract|null
* @uses \ReflectionClass
*
*/
protected function get_entity( $provider, $request, $args = [] ) {
protected function get_entity( $provider, $request, $args = [] ) {
$provider = sanitize_key( $provider );
$request = sanitize_text_field( $request );
@@ -194,8 +196,7 @@ class Loader {
$class = $path . $request;
$entity = new $class( ...$args );
}
}
catch ( \Exception $e ) {
} catch ( \Exception $e ) {
Debug::set( "There was a problem while retrieving {$request} for {$provider}: {$e->getMessage()}" );
$entity = null;
}

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\Mailgun;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -65,11 +66,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_MAILGUN_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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php
@@ -107,7 +116,7 @@ class Options extends OptionsAbstract {
printf(
/* translators: %s - Domain Name link. */
esc_html__( 'Follow this link to get a Domain Name from Mailgun: %s.', 'wp-mail-smtp' ),
'<a href="https://app.mailgun.com/app/sending/domains" target="_blank" rel="noopener noreferrer">' .
'<a href="https://app.mailgun.com/mg/sending/domains" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Get a Domain Name', 'wp-mail-smtp' ) .
'</a>'
);

View File

@@ -0,0 +1,549 @@
<?php
namespace WPMailSMTP\Providers\Mailjet;
use WPMailSMTP\Helpers\Helpers;
use WPMailSMTP\Providers\MailerAbstract;
use WPMailSMTP\WP;
/**
* Class Mailer.
*
* @since 4.2.0
*/
class Mailer extends MailerAbstract {
/**
* Which response code from HTTP provider is considered to be successful?
*
* @since 4.2.0
*
* @var int
*/
protected $email_sent_code = 200;
/**
* URL to make an API request to.
*
* @since 4.2.0
*
* @var string
*/
protected $url = 'https://api.mailjet.com/v3.1/send';
/**
* Mailer constructor.
*
* @since 4.2.0
*
* @param MailCatcherInterface $phpmailer The MailCatcher object.
* @param ConnectionInterface $connection The Connection object.
*/
public function __construct( $phpmailer, $connection = null ) {
// We want to prefill everything from MailCatcher class, which extends PHPMailer.
parent::__construct( $phpmailer, $connection );
// Set mailer specific headers.
$user = $this->connection_options->get( $this->mailer, 'api_key' );
$pass = $this->connection_options->get( $this->mailer, 'secret_key' );
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$this->set_header( 'Authorization', 'Basic ' . base64_encode( "$user:$pass" ) );
$this->set_header( 'Accept', 'application/json' );
$this->set_header( 'Content-Type', 'application/json' );
}
/**
* Redefine the way custom headers are processed for this mailer - they should be in body.
*
* @since 4.2.0
*
* @param array $headers Headers array.
*/
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 );
}
}
/**
* This mailer supports email-related custom headers inside a body of the message.
*
* @since 4.2.0
*
* @param string $name Header name.
* @param string $value Header value.
*/
public function set_body_header( $name, $value ) {
$name = sanitize_text_field( $name );
if ( empty( $name ) ) {
return;
}
$headers = isset( $this->body['Headers'] ) ? (array) $this->body['Headers'] : [];
$headers[ $name ] = $this->sanitize_header_value( $name, $value );
$this->set_body_param(
[
'Headers' => $headers,
]
);
}
/**
* Set the From information for an email.
*
* @since 4.2.0
*
* @param string $email The sender email address.
* @param string $name The sender name.
*/
public function set_from( $email, $name ) {
if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
return;
}
$this->set_body_param(
[
'From' => $this->address_format( [ $email, $name ] ),
]
);
}
/**
* Set email recipients: to, cc, bcc.
*
* @since 4.2.0
*
* @param array $recipients Email recipients.
*/
public function set_recipients( $recipients ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
if ( empty( $recipients ) ) {
return;
}
// Allow only these recipient types.
$allowed_types = [ 'to', 'cc', 'bcc' ];
$data = [];
foreach ( $recipients as $type => $emails ) {
if (
! in_array( $type, $allowed_types, true ) ||
empty( $emails ) ||
! is_array( $emails )
) {
continue;
}
$type = ucfirst( $type );
// Iterate over all emails for each type.
// There might be multiple cc/to/bcc emails.
foreach ( $emails as $email ) {
if ( ! isset( $email[0] ) || ! filter_var( $email[0], FILTER_VALIDATE_EMAIL ) ) {
continue;
}
$data[ $type ][] = $this->address_format( $email );
}
}
if ( ! empty( $data ) ) {
$this->set_body_param( $data );
}
}
/**
* Set the Reply To information for an email.
*
* @since 4.2.0
*
* @param array $emails Reply To email addresses.
*/
public function set_reply_to( $emails ) {
if ( empty( $emails ) ) {
return;
}
$email = array_shift( $emails );
if ( ! isset( $email[0] ) || ! filter_var( $email[0], FILTER_VALIDATE_EMAIL ) ) {
return;
}
$this->set_body_param(
[
'ReplyTo' => $this->address_format( $email ),
]
);
}
/**
* Set email subject.
*
* @since 4.2.0
*
* @param string $subject Email subject.
*/
public function set_subject( $subject ) {
$this->set_body_param(
[
'Subject' => $subject,
]
);
}
/**
* Set email content.
*
* @since 4.2.0
*
* @param string|array $content Email content.
*/
public function set_content( $content ) {
if ( empty( $content ) ) {
return;
}
if ( is_array( $content ) ) {
if ( ! empty( $content['text'] ) ) {
$this->set_body_param(
[
'TextPart' => $content['text'],
]
);
}
if ( ! empty( $content['html'] ) ) {
$this->set_body_param(
[
'HTMLPart' => $content['html'],
]
);
}
} else {
if ( $this->phpmailer->ContentType === 'text/plain' ) {
$this->set_body_param(
[
'TextPart' => $content,
]
);
} else {
$this->set_body_param(
[
'HTMLPart' => $content,
]
);
}
}
}
/**
* Set attachments for an email.
*
* @since 4.2.0
*
* @param array $attachments Attachments array.
*/
public function set_attachments( $attachments ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
if ( empty( $attachments ) ) {
return;
}
$data = [];
// Split attachments into "attachments" and "inline" groups.
foreach ( $attachments as $attachment ) {
$mode = in_array( $attachment[6], [ 'inline', 'attachment' ], true ) ? $attachment[6] : 'attachment';
if ( $mode === 'inline' ) {
$data['InlinedAttachments'][] = $attachment;
} else {
$data['Attachments'][] = $attachment;
}
}
// Prepare attachments.
foreach ( $data as $disposition => $attachments ) {
$data[ $disposition ] = $this->prepare_attachments( $attachments );
}
if ( ! empty( $data ) ) {
$this->set_body_param( $data );
}
}
/**
* Prepare attachments data for SendLayer API.
*
* @since 4.2.0
*
* @param array $attachments Array of attachments.
*
* @return array
*/
protected function prepare_attachments( $attachments ) {
$data = [];
foreach ( $attachments as $attachment ) {
$file = $this->get_attachment_file_content( $attachment );
if ( $file === false ) {
continue;
}
$filetype = str_replace( ';', '', trim( $attachment[4] ) );
$entry = [
'Filename' => empty( $attachment[2] ) ? 'file-' . wp_hash( microtime() ) . '.' . $filetype : trim( $attachment[2] ),
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
'Base64Content' => base64_encode( $file ),
'ContentType' => $attachment[4],
];
if ( $attachment[6] === 'inline' ) {
$entry['ContentID'] = $entry['Filename'];
}
$data[] = $entry;
}
return $data;
}
/**
* Doesn't support this.
* So we do nothing.
*
* @since 4.2.0
*
* @param string $email Return Path email address.
*/
public function set_return_path( $email ) {}
/**
* Redefine the way email body is returned.
* By default, we are sending an array of data.
* This mailer requires a JSON, so we encode the body.
*
* @since 4.2.0
*/
public function get_body() {
$body = [
'Messages' => [
parent::get_body(),
],
];
return wp_json_encode( $body );
}
/**
* Whether the email is sent or not.
* We check response code and a non-empty `email_id` field in the response body.
*
* @since 4.2.0
*
* @return bool
*/
public function is_email_sent() {
$is_sent = false;
if ( wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code ) {
$is_sent = true;
}
// phpcs:disable WPForms.Comments.Since.MissingPhpDoc, WPForms.PHP.ValidateHooks.InvalidHookName
/** This filter is documented in src/Providers/MailerAbstract.php. */
return apply_filters( 'wp_mail_smtp_providers_mailer_is_email_sent', $is_sent, $this->mailer );
// phpcs:enable WPForms.Comments.Since.MissingPhpDoc, WPForms.PHP.ValidateHooks.InvalidHookName
}
/**
* We might need to do something after the email was sent to the API.
* In this method we preprocess the response from the API.
*
* @since 4.2.0
*
* @param mixed $response Response data.
*/
protected function process_response( $response ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
parent::process_response( $response );
// Bail if request failed, or has no message entries.
if (
is_wp_error( $response ) ||
empty( $this->response['body']->Messages ) ||
! is_array( $this->response['body']->Messages )
) {
return;
}
// Only pick successful messages.
$messages = array_filter(
$this->response['body']->Messages,
function( $message ) {
return strtolower( $message->Status ) === 'success';
}
);
// Bail if all messages failed.
if ( empty( $messages ) ) {
return;
}
// Bail if no primary TO is defined. Unlikely, but just in case.
if ( ! isset( $this->body['To'] ) ||
! is_array( $this->body['To'] ) ||
! isset( $this->body['To'][0]['Email'] ) ||
empty( $this->body['To'][0]['Email'] )
) {
return;
}
$primary_to = $this->body['To'][0]['Email'];
foreach ( $messages as $message ) {
foreach ( $message->To as $to ) {
if ( strtolower( $to->Email ) === $primary_to ) {
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $to->MessageID );
$this->verify_sent_status = true;
return;
}
}
}
}
/**
* Gather errors from a nested array.
*
* @since 4.2.0
*
* @param array $data Array of data.
* @param int $recursion Current recursion step.
*
* @return array
*/
private function gather_response_errors( $data, $recursion = 10 ) {
$errors = [];
// Bail if recursion exceeds the limit.
if ( $recursion <= 0 ) {
return $errors;
}
// Bail if provided data is not an array.
if ( ! is_array( $data ) ) {
return $errors;
}
if ( ! empty( $data['ErrorMessage'] ) ) {
$errors[] = $data;
return $errors;
}
foreach ( $data as $datum ) {
$errors = array_merge( $errors, $this->gather_response_errors( $datum, $recursion - 1 ) );
}
return $errors;
}
/**
* Get a mailer-specific response with a helpful error.
*
* @since 4.2.0
*
* @return string
*/
public function get_response_error() { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded
$error_text[] = $this->error_message;
if ( ! empty( $this->response ) ) {
$body = wp_remote_retrieve_body( $this->response );
$body = json_decode( wp_json_encode( $body ), true );
$errors = $this->gather_response_errors( $body );
foreach ( $errors as $error ) {
$message = $error['ErrorMessage'];
$code = ! empty( $error['ErrorCode'] ) ? $error['ErrorCode'] : '';
if ( ! empty( $error['ErrorRelatedTo'] ) ) {
$related_to = implode( ', ', $error['ErrorRelatedTo'] );
$message = "{$message} [{$related_to}]";
}
$error_text[] = Helpers::format_error_message( $message, $code );
}
} else {
$error_text[] = WP::wp_remote_get_response_error_message( $this->response );
}
return implode( WP::EOL, array_map( 'esc_textarea', array_filter( $error_text ) ) );
}
/**
* Whether the mailer has all its settings correctly set up and saved.
*
* @since 4.2.0
*
* @return bool
*/
public function is_mailer_complete() {
$options = $this->connection_options->get_group( $this->mailer );
// API key is the only required option.
if ( ! empty( $options['api_key'] ) && ! empty( $options['secret_key'] ) ) {
return true;
}
return false;
}
/**
* Prepare address param.
*
* @since 4.2.0
*
* @param array $address Address array.
*
* @return array
*/
private function address_format( $address ) {
$result = [];
$email = isset( $address[0] ) ? $address[0] : false;
$name = isset( $address[1] ) ? $address[1] : false;
$result['Email'] = $email;
if ( ! empty( $name ) ) {
$result['Name'] = $name;
}
return $result;
}
}

View File

@@ -0,0 +1,173 @@
<?php
namespace WPMailSMTP\Providers\Mailjet;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 4.2.0
*/
class Options extends OptionsAbstract {
/**
* Mailer slug.
*
* @since 4.2.0
*/
const SLUG = 'mailjet';
/**
* Options constructor.
*
* @since 4.2.0
*
* @param ConnectionInterface $connection The Connection object.
*/
public function __construct( $connection = null ) {
if ( is_null( $connection ) ) {
$connection = wp_mail_smtp()->get_connections_manager()->get_primary_connection();
}
$description = sprintf(
wp_kses( /* translators: %1$s - URL to Mailjet.com site. */
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">Mailjet</a> is a cloud-based email service platform that enables businesses to send marketing and transactional emails, offering features like email automation, real-time analytics, and responsive design templates. If you\'re just starting out, you can send up to 200 emails per day without a credit card.', 'wp-mail-smtp' ) .
'<br><br>' .
/* translators: %2$s - URL to wpmailsmtp.com doc. */
__( 'To get started, read our <a href="%2$s" target="_blank" rel="noopener noreferrer">Mailjet documentation</a>.', 'wp-mail-smtp' ),
[
'strong' => true,
'br' => true,
'a' => [
'href' => true,
'rel' => true,
'target' => true,
],
]
),
'https://www.mailjet.com/',
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-mailjet-mailer-in-wp-mail-smtp/', 'Mailjet documentation' ) )
);
parent::__construct(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/mailjet.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'Mailjet', 'wp-mail-smtp' ),
'php' => '5.6',
'description' => $description,
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
],
$connection
);
}
/**
* Output the mailer provider options.
*
* @since 4.2.0
*/
public function display_options() {
// Do not display options if PHP version is not correct.
if ( ! $this->is_php_correct() ) {
$this->display_php_warning();
return;
}
?>
<!-- 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->connection_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_MAILJET_API_KEY' ); ?>
<?php else : ?>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php
printf( /* translators: %s - link to get an API Key. */
esc_html__( 'Follow this link to get the API key from Mailjet: %s.', 'wp-mail-smtp' ),
'<a href="https://app.mailjet.com/account/apikeys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'API Key Management', 'wp-mail-smtp' ) .
'</a>'
);
?>
</p>
</div>
</div>
<!-- Secret Key -->
<div id="wp-mail-smtp-setting-row-<?php echo esc_attr( $this->get_slug() ); ?>-secret_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() ); ?>-secret_key"><?php esc_html_e( 'Secret Key', 'wp-mail-smtp' ); ?></label>
</div>
<div class="wp-mail-smtp-setting-field">
<?php if ( $this->connection_options->is_const_defined( $this->get_slug(), 'secret_key' ) ) : ?>
<input type="text" disabled value="****************************************"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-secret_key"
/>
<?php $this->display_const_set_message( 'WPMS_MAILJET_SECRET_KEY' ); ?>
<?php else : ?>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'secret_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][secret_key]",
'id' => "wp-mail-smtp-setting-{$slug}-secret_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove Secret Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php
printf( /* translators: %s - link to get an API Key. */
esc_html__( 'Follow this link to get the Secret key from Mailjet: %s.', 'wp-mail-smtp' ),
'<a href="https://app.mailjet.com/account/apikeys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'API Key Management', 'wp-mail-smtp' ) .
'</a>'
);
?>
</p>
</div>
</div>
<?php
}
}

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\Postmark;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -94,10 +95,19 @@ class Options extends OptionsAbstract {
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-server_api_token"/>
<?php $this->display_const_set_message( 'WPMS_POSTMARK_SERVER_API_TOKEN' ); ?>
<?php else : ?>
<input type="password" spellcheck="false"
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][server_api_token]"
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'server_api_token' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-server_api_token"/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'server_api_token' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][server_api_token]",
'id' => "wp-mail-smtp-setting-{$slug}-server_api_token",
'value' => $value,
'clear_text' => esc_html__( 'Remove Server API Token', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php

View File

@@ -500,7 +500,7 @@ class Mailer extends MailerAbstract {
$result = $email;
if ( ! empty( $name ) ) {
$result = "{$name} <{$email}>";
$result = "\"{$name}\" <{$email}>";
}
return $result;

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\SMTP2GO;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -99,11 +100,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_SMTP2GO_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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\SMTPcom;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -112,17 +113,25 @@ class Options extends OptionsAbstract {
/>
<?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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?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">' .
'<a href="https://my.smtp.com/account?tab=manage_api_keys" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Get API Key', 'wp-mail-smtp' ) .
'</a>'
);
@@ -151,7 +160,7 @@ class Options extends OptionsAbstract {
<?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">' .
'<a href="https://my.smtp.com/account?tab=manage_channels" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'Get Sender Name', 'wp-mail-smtp' ) .
'</a>'
);

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\Sendgrid;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -73,11 +74,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_SENDGRID_API_KEY' ); ?>
<?php else : ?>
<input type="password" spellcheck="false"
name="wp-mail-smtp[<?php echo esc_attr( $this->get_slug() ); ?>][api_key]"
value="<?php echo esc_attr( $this->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\Sendinblue;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -117,11 +118,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_SENDINBLUE_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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\Sendlayer;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -107,11 +108,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_SENDLAYER_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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php

View File

@@ -3,6 +3,7 @@
namespace WPMailSMTP\Providers\SparkPost;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Helpers\UI;
use WPMailSMTP\Providers\OptionsAbstract;
/**
@@ -93,11 +94,19 @@ class Options extends OptionsAbstract {
/>
<?php $this->display_const_set_message( 'WPMS_SPARKPOST_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->connection_options->get( $this->get_slug(), 'api_key' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-api_key"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $this->get_slug(), 'api_key' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][api_key]",
'id' => "wp-mail-smtp-setting-{$slug}-api_key",
'value' => $value,
'clear_text' => esc_html__( 'Remove API Key', 'wp-mail-smtp' ),
]
);
?>
<?php endif; ?>
<p class="desc">
<?php

View File

@@ -239,6 +239,9 @@ class Queue {
// Cleanup any attachments.
$this->cleanup_attachments();
// Stop injecting the original initiator state.
remove_filter( 'wp_mail_smtp_wp_mail_initiator_set_initiator', [ $this, 'apply_initiator_state' ] );
// Stop applying PHPMailer state.
remove_action( 'phpmailer_init', [ $this, 'apply_mailer_state' ], PHP_INT_MAX );

View File

@@ -366,10 +366,17 @@ class Task {
global $wpdb;
$limit = max( 0, intval( $limit ) );
$query = 'DELETE FROM ' . $wpdb->prefix . 'actionscheduler_actions WHERE hook = "' . $this->action . '" AND status = "complete"';
$query = $wpdb->prepare(
"DELETE FROM {$wpdb->prefix}actionscheduler_actions WHERE hook = %s AND status = %s",
$this->action,
'complete'
);
if ( $limit > 0 ) {
$query .= " LIMIT {$limit}";
$query .= $wpdb->prepare(
' LIMIT %d',
$limit
);
}
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared