plugin updates

This commit is contained in:
Tony Volpe
2024-07-18 20:40:50 +00:00
parent 1cbeccbe26
commit f13cad0e36
314 changed files with 45107 additions and 30963 deletions

View File

@@ -1401,7 +1401,7 @@ class Area {
array_filter(
$submenu[ self::SLUG ],
function ( $item ) {
return strpos( $item[2], 'https://wpmailsmtp.com/lite-upgrade' ) !== false;
return strpos( urldecode( $item[2] ), 'wpmailsmtp.com/lite-upgrade' ) !== false;
}
)
);
@@ -1418,6 +1418,15 @@ class Area {
} else {
$submenu[ self::SLUG ][ $upgrade_link_position ][] = 'wp-mail-smtp-sidebar-upgrade-pro';
}
$current_screen = get_current_screen();
$upgrade_utm_content = $current_screen === null ? 'Upgrade to Pro' : 'Upgrade to Pro - ' . $current_screen->base;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$upgrade_utm_content = empty( $_GET['tab'] ) ? $upgrade_utm_content : $upgrade_utm_content . ' -- ' . sanitize_key( $_GET['tab'] );
// Add the correct utm_content to the menu item.
$submenu[ self::SLUG ][ $upgrade_link_position ][2] =
esc_url( wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'admin-menu', 'content' => $upgrade_utm_content ] ) ); // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
// phpcs:enable WordPress.WP.GlobalVariablesOverride.Prohibited
// Output inline styles.

View File

@@ -57,6 +57,10 @@ class Education {
return;
}
$current_screen = get_current_screen();
$upgrade_utm_content = $current_screen === null ? 'Upgrade to Pro' : 'Upgrade to Pro - ' . $current_screen->base;
$upgrade_utm_content = empty( $_GET['tab'] ) ? $upgrade_utm_content : $upgrade_utm_content . ' -- ' . sanitize_key( $_GET['tab'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
printf(
'<div id="wp-mail-smtp-notice-bar">
<div class="wp-mail-smtp-notice-bar-container">
@@ -67,7 +71,7 @@ class Education {
wp_kses(
sprintf( /* translators: %s - WPMailSMTP.com Upgrade page URL. */
__( 'Youre using WP Mail SMTP Lite. To unlock more features, consider <a href="%s" target="_blank" rel="noopener noreferrer">upgrading to Pro</a>.', 'wp-mail-smtp' ),
wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'notice-bar' ] )
wp_mail_smtp()->get_upgrade_link( [ 'medium' => 'notice-bar', 'content' => $upgrade_utm_content ] ) // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
),
[
'a' => [

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( 'Microsoft Teams', 'wp-mail-smtp' ); ?></h3>
<p class="desc"><?php esc_html_e( 'Paste in the Microsoft Teams webhook URL youd like to use to receive alerts when email sending fails. Read our documentation on setting up Microsoft Teams 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( 'Microsoft Teams 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

@@ -94,7 +94,7 @@ class Connect {
'endpoint' => admin_url( 'admin-ajax.php' ),
'version' => WPMS_PLUGIN_VER,
'siteurl' => admin_url(),
'homeurl' => home_url(),
'homeurl' => site_url(),
'redirect' => rawurldecode( base64_encode( $redirect ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
'v' => 2,
],

View File

@@ -202,17 +202,6 @@ class DBRepair {
$reasons = array_filter( $reasons ); // Filtering out the empty values.
if ( ! empty( $reasons ) ) {
$msg = sprintf(
wp_kses( /* translators: %1$s: Singular/Plural string, %2$s - the error messages from the migrations for the missing tables. */
__( 'The following DB %1$s still missing. <br />%2$s', 'wp-mail-smtp' ),
[
'br' => [],
]
),
_n( 'Table is', 'Tables are', count( $missing_tables ), 'wp-mail-smtp' ),
implode( '<br/>', $reasons )
);
$msg = sprintf(
wp_kses(
_n( 'The following DB table is still missing.', 'The following DB tables are still missing.', count( $missing_tables ), 'wp-mail-smtp' ) . '<br />%s',

View File

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

View File

@@ -66,4 +66,53 @@ class UI {
</label>
<?php
}
/**
* Output an obfuscated password field.
*
* @since 4.1.0
*
* @param array $args Field attributes.
*
* @return void
*/
public static function hidden_password_field( $args ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$args = wp_parse_args(
$args,
[
'name' => '',
'id' => '',
'value' => '',
'clear_text' => esc_html__( 'Remove', 'wp-mail-smtp' ),
]
);
$value = str_repeat( '*', strlen( $args['value'] ) );
// phpcs:disable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
?>
<div class="wp-mail-smtp-input-btn-row">
<input type="password"
spellcheck="false"
autocomplete="new-password"
<?php if ( ! empty( $value ) ) : ?>disabled<?php endif; ?>
<?php if ( ! empty( $args['name'] && empty( $value ) ) ) : ?>name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?>
<?php if ( ! empty( $args['name'] ) ) : ?>data-name="<?php echo esc_attr( $args['name'] ); ?>"<?php endif; ?>
<?php if ( ! empty( $args['id'] ) ) : ?>id="<?php echo esc_attr( $args['id'] ); ?>"<?php endif; ?>
<?php if ( ! empty( $value ) ) : ?>value="<?php echo esc_attr( $value ); ?>"<?php endif; ?>/>
<?php if ( ! empty( $value ) ) : ?>
<button type="button"
class="wp-mail-smtp-btn wp-mail-smtp-btn-md wp-mail-smtp-btn-grey"
data-clear-field="<?php echo esc_attr( $args['id'] ); ?>"><?php echo esc_html( $args['clear_text'] ); ?></button>
<?php endif; ?>
</div>
<?php
// phpcs:enable Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace
}
}

View File

@@ -92,6 +92,9 @@ class Options {
'sendlayer' => [
'api_key',
],
'smtp2go' => [
'api_key',
],
'pepipostapi' => [
'api_key',
],
@@ -146,6 +149,7 @@ class Options {
'sendgrid',
'sparkpost',
'zoho',
'smtp2go',
'smtp',
'pepipost',
'pepipostapi',
@@ -714,6 +718,16 @@ class Options {
break;
case 'smtp2go':
switch ( $key ) {
case 'api_key':
/** @noinspection PhpUndefinedConstantInspection */
$return = $this->is_const_defined( $group, $key ) ? WPMS_SMTP2GO_API_KEY : $value;
break;
}
break;
case 'pepipostapi':
switch ( $key ) {
case 'api_key':
@@ -740,6 +754,15 @@ class Options {
break;
case 'alert_teams_webhook':
switch ( $key ) {
case 'connections':
$return = $this->is_const_defined( $group, $key ) ? [ [ 'webhook_url' => WPMS_ALERT_TEAMS_WEBHOOK_URL ] ] : $value;
break;
}
break;
case 'alert_twilio_sms':
switch ( $key ) {
case 'connections':
@@ -1053,6 +1076,15 @@ class Options {
break;
case 'smtp2go':
switch ( $key ) {
case 'api_key':
$return = defined( 'WPMS_SMTP2GO_API_KEY' ) && WPMS_SMTP2GO_API_KEY;
break;
}
break;
case 'pepipostapi':
switch ( $key ) {
case 'api_key':
@@ -1080,6 +1112,15 @@ class Options {
break;
case 'alert_teams_webhook':
switch ( $key ) {
case 'connections':
$return = defined( 'WPMS_ALERT_TEAMS_WEBHOOK_URL' ) && WPMS_ALERT_TEAMS_WEBHOOK_URL;
break;
}
break;
case 'alert_twilio_sms':
switch ( $key ) {
case 'connections':
@@ -1319,7 +1360,7 @@ class Options {
}
break;
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom/sparkpost/sendlayer.
case 'api_key': // mailgun/sendgrid/sendinblue/pepipostapi/smtpcom/sparkpost/sendlayer/smtp2go.
case 'domain': // mailgun/zoho/sendgrid/sendinblue.
case 'client_id': // gmail/outlook/amazonses/zoho.
case 'client_secret': // gmail/outlook/amazonses/zoho.

View File

@@ -20,6 +20,7 @@ class Loader {
* @since 1.0.0
* @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.
*
* @var array
*/
@@ -35,6 +36,7 @@ class Loader {
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
'postmark' => 'WPMailSMTP\Providers\Postmark\\',
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
'smtp2go' => 'WPMailSMTP\Providers\SMTP2GO\\',
'sparkpost' => 'WPMailSMTP\Providers\SparkPost\\',
'zoho' => 'WPMailSMTP\Providers\Zoho\\',
'smtp' => 'WPMailSMTP\Providers\SMTP\\',

View File

@@ -380,10 +380,21 @@ abstract class OptionsAbstract implements OptionsInterface {
<?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->connection_options->get( $this->get_slug(), 'pass' ) ); ?>"
id="wp-mail-smtp-setting-<?php echo esc_attr( $this->get_slug() ); ?>-pass" spellcheck="false" autocomplete="new-password"
/>
<?php
$slug = $this->get_slug();
$value = $this->connection_options->get( $slug, 'pass' );
UI::hidden_password_field(
[
'name' => "wp-mail-smtp[{$slug}][pass]",
'id' => "wp-mail-smtp-setting-{$slug}-pass",
'value' => $value,
'clear_text' => esc_html__( 'Remove Password', 'wp-mail-smtp' ),
]
);
?>
<p class="desc">
<?php esc_html_e( 'The password is encrypted in the database, but for improved security we recommend using your site\'s WordPress configuration file to set your password.', 'wp-mail-smtp' ); ?>
<br>

View File

@@ -0,0 +1,485 @@
<?php
namespace WPMailSMTP\Providers\SMTP2GO;
use WPMailSMTP\Helpers\Helpers;
use WPMailSMTP\Providers\MailerAbstract;
use WPMailSMTP\WP;
/**
* Class Mailer.
*
* @since 4.1.0
*/
class Mailer extends MailerAbstract {
/**
* Which response code from HTTP provider is considered to be successful?
*
* @since 4.1.0
*
* @var int
*/
protected $email_sent_code = 200;
/**
* URL to make an API request to.
*
* @since 4.1.0
*
* @var string
*/
protected $url = 'https://api.smtp2go.com/v3/email/send';
/**
* Mailer constructor.
*
* @since 4.1.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.
$this->set_header( 'X-Smtp2go-Api-Key', $this->connection_options->get( $this->mailer, 'api_key' ) );
$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.1.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 );
}
// Add custom 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 4.1.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['custom_headers'] ) ? (array) $this->body['custom_headers'] : [];
// Index by key to remove duplicates.
$headers = wp_list_pluck( $headers, 'value', 'header' );
// Sanitize headers.
$headers[ $name ] = $this->sanitize_header_value( $name, $value );
// Turn headers into a list of header => value entries.
$data = array_reduce(
array_keys( $headers ),
function ( $data, $header ) use ( $headers ) {
$data[] = [
'header' => $header,
'value' => $headers[ $header ],
];
return $data;
},
[]
);
$this->body['custom_headers'] = $data;
}
/**
* Set the From information for an email.
*
* @since 4.1.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(
[
'sender' => $this->address_format( [ $email, $name ] ),
]
);
}
/**
* Set email recipients: to, cc, bcc.
*
* @since 4.1.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;
}
// 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 );
}
}
/**
* Doesn't support this.
* So we do nothing.
*
* @since 4.1.0
*
* @param array $emails Reply To email addresses.
*/
public function set_reply_to( $emails ) {}
/**
* Set email subject.
*
* @since 4.1.0
*
* @param string $subject Email subject.
*/
public function set_subject( $subject ) {
$this->set_body_param(
[
'subject' => $subject,
]
);
}
/**
* Set email content.
*
* @since 4.1.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(
[
'text_body' => $content['text'],
]
);
}
if ( ! empty( $content['html'] ) ) {
$this->set_body_param(
[
'html_body' => $content['html'],
]
);
}
} else {
if ( $this->phpmailer->ContentType === 'text/plain' ) {
$this->set_body_param(
[
'text_body' => $content,
]
);
} else {
$this->set_body_param(
[
'html_body' => $content,
]
);
}
}
}
/**
* Set attachments for an email.
*
* @since 4.1.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 "inlines" groups.
foreach ( $attachments as $attachment ) {
$mode = in_array( $attachment[6], [ 'inline', 'attachment' ], true ) ? $attachment[6] : 'attachment';
if ( $mode === 'inline' ) {
$data['inlines'][] = $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 );
}
}
/**
* Doesn't support this.
* So we do nothing.
*
* @since 4.1.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.
* SMTP2GO requires a JSON, so we encode the body.
*
* @since 4.1.0
*/
public function get_body() {
$body = parent::get_body();
return wp_json_encode( $body );
}
/**
* Prepare attachments data.
*
* @since 4.1.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] ) );
$data[] = [
'filename' => empty( $attachment[2] ) ? 'file-' . wp_hash( microtime() ) . '.' . $filetype : trim( $attachment[2] ),
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
'fileblob' => base64_encode( $file ),
'mimetype' => $attachment[4],
];
}
return $data;
}
/**
* 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.1.0
*
* @param mixed $response Response data.
*/
protected function process_response( $response ) {
parent::process_response( $response );
if (
! is_wp_error( $response ) &&
! empty( $this->response['body']->data ) &&
! empty( $this->response['body']->data->email_id )
) {
$this->phpmailer->addCustomHeader( 'X-Msg-ID', $this->response['body']->data->email_id );
$this->verify_sent_status = true;
}
}
/**
* Whether the email is sent or not.
* We check response code and a non-empty `email_id` field in the response body.
*
* @since 4.1.0
*
* @return bool
*/
public function is_email_sent() {
$is_sent = false;
if (
wp_remote_retrieve_response_code( $this->response ) === $this->email_sent_code &&
! empty( $this->response['body']->data ) &&
! empty( $this->response['body']->data->email_id )
) {
$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
}
/**
* Get a SMTP2GO-specific response with a helpful error.
*
* @since 4.1.0
*
* @return string
*/
public function get_response_error() { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded, Generic.Metrics.CyclomaticComplexity.TooHigh
$error_text[] = $this->error_message;
if ( ! empty( $this->response ) ) {
$body = wp_remote_retrieve_body( $this->response );
if ( ! empty( $body->data ) ) {
if ( ! empty( $body->data->failures ) ) {
foreach ( $body->data->failures as $error ) {
$error_text[] = Helpers::format_error_message( $error );
}
}
if ( ! empty( $body->data->error ) ) {
$error_code = ! empty( $body->data->error_code ) ? $body->data->error_code : '';
$error_text[] = Helpers::format_error_message( $body->data->error, $error_code );
}
if ( ! empty( $body->data->field_validation_errors ) ) {
$message = '';
$code = '';
if ( ! empty( $body->data->field_validation_errors->message ) ) {
$message = $body->data->field_validation_errors->message;
}
if ( ! empty( $body->data->field_validation_errors->fieldname ) ) {
$code = $body->data->field_validation_errors->fieldname;
}
if ( ! empty( $message ) ) {
$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.1.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'] ) ) {
return true;
}
return false;
}
/**
* Prepare address param.
*
* @since 4.1.0
*
* @param array $address Address array.
*
* @return array
*/
private function address_format( $address ) {
$email = isset( $address[0] ) ? $address[0] : false;
$name = isset( $address[1] ) ? $address[1] : false;
$result = $email;
if ( ! empty( $name ) ) {
$result = "{$name} <{$email}>";
}
return $result;
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace WPMailSMTP\Providers\SMTP2GO;
use WPMailSMTP\ConnectionInterface;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 4.1.0
*/
class Options extends OptionsAbstract {
/**
* Mailer slug.
*
* @since 4.1.0
*/
const SLUG = 'smtp2go';
/**
* Options constructor.
*
* @since 4.1.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 SMTP2GO.com site. */
__( '<a href="%1$s" target="_blank" rel="noopener noreferrer">SMTP2GO</a> provides a robust and reliable email delivery service with global infrastructure, real-time analytics, and advanced security features. If you\'re just starting out, you can use SMTP2GO\'s free plan to send up to 1000 emails per month.', '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">SMTP2GO documentation</a>.', 'wp-mail-smtp' ),
[
'strong' => true,
'br' => true,
'a' => [
'href' => true,
'rel' => true,
'target' => true,
],
]
),
'https://www.smtp2go.com/',
esc_url( wp_mail_smtp()->get_utm_url( 'https://wpmailsmtp.com/docs/how-to-set-up-the-smtp2go-mailer-in-wp-mail-smtp/', 'SMTP2GO documentation' ) )
);
parent::__construct(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/smtp2go.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'SMTP2GO', '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.1.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_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 endif; ?>
<p class="desc">
<?php
printf( /* translators: %s - link to get an API Key. */
esc_html__( 'Generate an API key on the Sending &rarr; API Keys page in your %s.', 'wp-mail-smtp' ),
'<a href="https://app.smtp2go.com/" target="_blank" rel="noopener noreferrer">' .
esc_html__( 'control panel', 'wp-mail-smtp' ) .
'</a>'
);
?>
</p>
</div>
</div>
<?php
}
}

View File

@@ -72,6 +72,13 @@ class Options extends OptionsAbstract {
'title' => esc_html__( 'SendLayer', 'wp-mail-smtp' ),
'description' => $description,
'recommended' => true,
'supports' => [
'from_email' => true,
'from_name' => true,
'return_path' => false,
'from_email_force' => true,
'from_name_force' => true,
],
],
$connection
);

View File

@@ -39,6 +39,9 @@ class ProcessQueueTask extends Task {
// Register the action handler.
add_action( self::ACTION, [ $this, 'process' ] );
// Cleanup completed task occurrences.
add_action( 'action_scheduler_after_process_queue', [ $this, 'cleanup' ] );
// Exit if this task the queue is disabled, or it's already scheduled.
if (
! wp_mail_smtp()->get_queue()->is_enabled() ||
@@ -68,4 +71,14 @@ class ProcessQueueTask extends Task {
$this->cancel_force();
}
}
/**
* Cleanup completed tasks.
*
* @since 4.1.0
*/
public function cleanup() {
$this->remove_completed( 10 );
}
}

View File

@@ -38,6 +38,9 @@ class SendEnqueuedEmailTask extends Task {
// Register the action handler.
add_action( self::ACTION, [ $this, 'process' ] );
// Cleanup completed task occurrences.
add_action( 'action_scheduler_after_process_queue', [ $this, 'cleanup' ] );
}
/**
@@ -81,4 +84,14 @@ class SendEnqueuedEmailTask extends Task {
wp_mail_smtp()->get_queue()->send_email( $email_id );
}
/**
* Cleanup completed tasks.
*
* @since 4.1.0
*/
public function cleanup() {
$this->remove_completed( 10 );
}
}

View File

@@ -353,4 +353,27 @@ class Task {
add_action( 'shutdown', [ $this, 'cancel' ], PHP_INT_MAX );
}
/**
* Remove completed occurrences of this task.
*
* @since 4.1.0
*
* @param int $limit The amount of rows to remove.
*/
protected function remove_completed( $limit = 0 ) {
global $wpdb;
$limit = max( 0, intval( $limit ) );
$query = 'DELETE FROM ' . $wpdb->prefix . 'actionscheduler_actions WHERE hook = "' . $this->action . '" AND status = "complete"';
if ( $limit > 0 ) {
$query .= " LIMIT {$limit}";
}
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
$wpdb->query( $query );
// phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
}
}

View File

@@ -64,6 +64,9 @@ class Tasks {
// Remove scheduled action meta after action execution.
add_action( 'action_scheduler_after_execute', [ $this, 'clear_action_meta' ], PHP_INT_MAX, 2 );
// Cancel tasks on plugin deactivation.
register_deactivation_hook( WPMS_PLUGIN_FILE, [ $this, 'cancel_all' ] );
}
/**