updated plugin WP Mail SMTP version 2.4.0

This commit is contained in:
2020-09-25 14:44:17 +00:00
committed by Gitium
parent 4f3d745449
commit 3053837189
673 changed files with 31869 additions and 65613 deletions

View File

@ -1,44 +1,44 @@
<?php
namespace WPMailSMTP\Providers\AmazonSES;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 1.7.0
*/
class Options extends OptionsAbstract {
/**
* AmazonSES Options constructor.
*
* @since 1.7.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/aws.svg',
'slug' => 'amazonses',
'title' => esc_html__( 'Amazon SES', 'wp-mail-smtp' ),
'disabled' => true,
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<p>
<?php esc_html_e( 'We\'re sorry, the Amazon SES mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
</p>
<?php
}
}
<?php
namespace WPMailSMTP\Providers\AmazonSES;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 1.7.0
*/
class Options extends OptionsAbstract {
/**
* AmazonSES Options constructor.
*
* @since 1.7.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/aws.svg',
'slug' => 'amazonses',
'title' => esc_html__( 'Amazon SES', 'wp-mail-smtp' ),
'disabled' => true,
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<p>
<?php esc_html_e( 'We\'re sorry, the Amazon SES mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
</p>
<?php
}
}

View File

@ -1,148 +1,148 @@
<?php
namespace WPMailSMTP\Providers;
use WPMailSMTP\Options as PluginOptions;
/**
* Class AuthAbstract.
*
* @since 1.0.0
*/
abstract class AuthAbstract implements AuthInterface {
/**
* Mailer DB options.
*
* @since 1.0.0
*
* @var array
*/
protected $options = array();
/**
* @since 1.0.0
*
* @var mixed
*/
protected $client;
/**
* Mailer slug.
*
* @since 1.0.0
*
* @var string
*/
protected $mailer_slug = '';
/**
* Key for a stored unique state value.
*
* @since 1.5.0
*
* @var string
*/
public $state_key = 'wp_mail_smtp_provider_client_state';
/**
* Use the composer autoloader to include the auth library and all dependencies.
*
* @since 1.0.0
*/
protected function include_vendor_lib() {
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
}
/**
* Get the url, that users will be redirected back to finish the OAuth process.
*
* @since 1.0.0
*
* @return string
*/
public static function get_plugin_auth_url() {
return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
}
/**
* Update auth code in our DB.
*
* @since 1.0.0
*
* @param string $code
*/
protected function update_auth_code( $code ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['auth_code'] = $code;
// To save in currently retrieved options array.
$this->options['auth_code'] = $code;
$options->set( $all );
}
/**
* Update access token in our DB.
*
* @since 1.0.0
*
* @param mixed $token
*/
protected function update_access_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['access_token'] = $token;
// To save in currently retrieved options array.
$this->options['access_token'] = $token;
$options->set( $all );
}
/**
* Update refresh token in our DB.
*
* @since 1.0.0
*
* @param mixed $token
*/
protected function update_refresh_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['refresh_token'] = $token;
// To save in currently retrieved options array.
$this->options['refresh_token'] = $token;
$options->set( $all );
}
/**
* @inheritdoc
*/
public function is_clients_saved() {
return ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] );
}
/**
* @inheritdoc
*/
public function is_auth_required() {
return empty( $this->options['access_token'] ) || empty( $this->options['refresh_token'] );
}
}
<?php
namespace WPMailSMTP\Providers;
use WPMailSMTP\Options as PluginOptions;
/**
* Class AuthAbstract.
*
* @since 1.0.0
*/
abstract class AuthAbstract implements AuthInterface {
/**
* Mailer DB options.
*
* @since 1.0.0
*
* @var array
*/
protected $options = array();
/**
* @since 1.0.0
*
* @var mixed
*/
protected $client;
/**
* Mailer slug.
*
* @since 1.0.0
*
* @var string
*/
protected $mailer_slug = '';
/**
* Key for a stored unique state value.
*
* @since 1.5.0
*
* @var string
*/
public $state_key = 'wp_mail_smtp_provider_client_state';
/**
* Use the composer autoloader to include the auth library and all dependencies.
*
* @since 1.0.0
*/
protected function include_vendor_lib() {
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
}
/**
* Get the url, that users will be redirected back to finish the OAuth process.
*
* @since 1.0.0
*
* @return string
*/
public static function get_plugin_auth_url() {
return add_query_arg( 'tab', 'auth', wp_mail_smtp()->get_admin()->get_admin_page_url() );
}
/**
* Update auth code in our DB.
*
* @since 1.0.0
*
* @param string $code
*/
protected function update_auth_code( $code ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['auth_code'] = $code;
// To save in currently retrieved options array.
$this->options['auth_code'] = $code;
$options->set( $all );
}
/**
* Update access token in our DB.
*
* @since 1.0.0
*
* @param mixed $token
*/
protected function update_access_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['access_token'] = $token;
// To save in currently retrieved options array.
$this->options['access_token'] = $token;
$options->set( $all );
}
/**
* Update refresh token in our DB.
*
* @since 1.0.0
*
* @param mixed $token
*/
protected function update_refresh_token( $token ) {
$options = new PluginOptions();
$all = $options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['refresh_token'] = $token;
// To save in currently retrieved options array.
$this->options['refresh_token'] = $token;
$options->set( $all );
}
/**
* @inheritdoc
*/
public function is_clients_saved() {
return ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] );
}
/**
* @inheritdoc
*/
public function is_auth_required() {
return empty( $this->options['access_token'] ) || empty( $this->options['refresh_token'] );
}
}

View File

@ -1,30 +1,30 @@
<?php
namespace WPMailSMTP\Providers;
/**
* Interface AuthInterface.
*
* @since 1.0.0
*/
interface AuthInterface {
/**
* Whether user saved Client ID/App ID and Client Secret/App Password or not.
* Both options are required.
*
* @since 1.0.0
*
* @return bool
*/
public function is_clients_saved();
/**
* Whether we have an access and refresh tokens or not.
*
* @since 1.0.0
*
* @return bool
*/
public function is_auth_required();
}
<?php
namespace WPMailSMTP\Providers;
/**
* Interface AuthInterface.
*
* @since 1.0.0
*/
interface AuthInterface {
/**
* Whether user saved Client ID/App ID and Client Secret/App Password or not.
* Both options are required.
*
* @since 1.0.0
*
* @return bool
*/
public function is_clients_saved();
/**
* Whether we have an access and refresh tokens or not.
*
* @since 1.0.0
*
* @return bool
*/
public function is_auth_required();
}

View File

@ -6,6 +6,8 @@ use WPMailSMTP\Admin\Area;
use WPMailSMTP\Debug;
use WPMailSMTP\Options as PluginOptions;
use WPMailSMTP\Providers\AuthAbstract;
use WPMailSMTP\Vendor\Google_Client;
use WPMailSMTP\Vendor\Google_Service_Gmail;
/**
* Class Auth to request access and refresh tokens.
@ -74,7 +76,7 @@ class Auth extends AuthAbstract {
* @since 1.0.0
* @since 1.5.0 Add ability to apply custom options to the client via a filter.
*
* @return \Google_Client
* @return Google_Client
*/
public function get_client() {
@ -85,7 +87,7 @@ class Auth extends AuthAbstract {
$this->include_vendor_lib();
$client = new \Google_Client(
$client = new Google_Client(
array(
'client_id' => $this->options['client_id'],
'client_secret' => $this->options['client_secret'],
@ -99,7 +101,7 @@ class Auth extends AuthAbstract {
$client->setApprovalPrompt( 'force' );
$client->setIncludeGrantedScopes( true );
// We request only the sending capability, as it's what we only need to do.
$client->setScopes( array( \Google_Service_Gmail::MAIL_GOOGLE_COM ) );
$client->setScopes( array( Google_Service_Gmail::MAIL_GOOGLE_COM ) );
$client->setRedirectUri( self::get_plugin_auth_url() );
// Apply custom options to the client.
@ -224,13 +226,13 @@ class Auth extends AuthAbstract {
if (
! empty( $code ) &&
(
$scope === \Google_Service_Gmail::MAIL_GOOGLE_COM . ' ' . \Google_Service_Gmail::GMAIL_SEND ||
$scope === \Google_Service_Gmail::GMAIL_SEND . ' ' . \Google_Service_Gmail::MAIL_GOOGLE_COM ||
$scope === \Google_Service_Gmail::GMAIL_SEND ||
$scope === \Google_Service_Gmail::MAIL_GOOGLE_COM
$scope === Google_Service_Gmail::MAIL_GOOGLE_COM . ' ' . Google_Service_Gmail::GMAIL_SEND ||
$scope === Google_Service_Gmail::GMAIL_SEND . ' ' . Google_Service_Gmail::MAIL_GOOGLE_COM ||
$scope === Google_Service_Gmail::GMAIL_SEND ||
$scope === Google_Service_Gmail::MAIL_GOOGLE_COM
)
) {
// Save the auth code. So \Google_Client can reuse it to retrieve the access token.
// Save the auth code. So Google_Client can reuse it to retrieve the access token.
$this->update_auth_code( $code );
} else {
wp_safe_redirect(
@ -264,8 +266,8 @@ class Auth extends AuthAbstract {
if (
! empty( $this->client ) &&
class_exists( 'Google_Client', false ) &&
$this->client instanceof \Google_Client
class_exists( 'WPMailSMTP\Vendor\Google_Client', false ) &&
$this->client instanceof Google_Client
) {
return filter_var( $this->client->createAuthUrl(), FILTER_SANITIZE_URL );
}
@ -282,7 +284,7 @@ class Auth extends AuthAbstract {
*/
public function get_user_info() {
$gmail = new \Google_Service_Gmail( $this->get_client() );
$gmail = new Google_Service_Gmail( $this->get_client() );
try {
$email = $gmail->users->getProfile( 'me' )->getEmailAddress();
@ -306,20 +308,18 @@ class Auth extends AuthAbstract {
return $this->aliases;
}
$gmail = new \Google_Service_Gmail( $this->get_client() );
$gmail = new Google_Service_Gmail( $this->get_client() );
try {
$response = $gmail->users_settings_sendAs->listUsersSettingsSendAs( 'me' ); // phpcs:ignore
// phpcs:disable
if ( isset( $response->sendAs ) ) {
$this->aliases = array_map(
function( $sendAsObject ) {
return $sendAsObject->sendAsEmail;
},
$response->sendAs
);
}
$this->aliases = array_map(
function( $sendAsObject ) {
return $sendAsObject['sendAsEmail'];
},
(array) $response->getSendAs()
);
// phpcs:enable
} catch ( \Exception $exception ) {

View File

@ -5,6 +5,8 @@ namespace WPMailSMTP\Providers\Gmail;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcherInterface;
use WPMailSMTP\Providers\MailerAbstract;
use WPMailSMTP\Vendor\Google_Service_Gmail;
use WPMailSMTP\Vendor\Google_Service_Gmail_Message;
/**
* Class Mailer.
@ -28,7 +30,7 @@ class Mailer extends MailerAbstract {
*
* @since 1.0.0
*
* @var \Google_Service_Gmail_Message
* @var Google_Service_Gmail_Message
*/
protected $message;
@ -76,7 +78,7 @@ class Mailer extends MailerAbstract {
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
$auth = new Auth();
$message = new \Google_Service_Gmail_Message();
$message = new Google_Service_Gmail_Message();
// Set the authorized Gmail email address as the "from email" if the set email is not on the list of aliases.
$possible_from_emails = $auth->get_user_possible_send_from_addresses();
@ -103,7 +105,7 @@ class Mailer extends MailerAbstract {
$message->setRaw( $base64 );
$service = new \Google_Service_Gmail( $auth->get_client() );
$service = new Google_Service_Gmail( $auth->get_client() );
$response = $service->users_messages->send( 'me', $message );
$this->process_response( $response );
@ -123,7 +125,7 @@ class Mailer extends MailerAbstract {
* @since 1.0.0
* @since 1.5.0 Added action "wp_mail_smtp_providers_gmail_mailer_process_response" with $response.
*
* @param \Google_Service_Gmail_Message $response Instance of Gmail response.
* @param Google_Service_Gmail_Message $response Instance of Gmail response.
*/
protected function process_response( $response ) {

View File

@ -25,8 +25,8 @@ class Loader {
protected $providers = array(
'mail' => 'WPMailSMTP\Providers\Mail\\',
'smtpcom' => 'WPMailSMTP\Providers\SMTPcom\\',
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
'sendinblue' => 'WPMailSMTP\Providers\Sendinblue\\',
'pepipostapi' => 'WPMailSMTP\Providers\PepipostAPI\\',
'mailgun' => 'WPMailSMTP\Providers\Mailgun\\',
'sendgrid' => 'WPMailSMTP\Providers\Sendgrid\\',
'amazonses' => 'WPMailSMTP\Providers\AmazonSES\\',
@ -53,7 +53,7 @@ class Loader {
*/
public function get_providers() {
if ( ! Options::init()->is_pepipost_active() ) {
if ( ! Options::init()->is_mailer_active( 'pepipost' ) ) {
unset( $this->providers['pepipost'] );
}

View File

@ -1,49 +1,49 @@
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Mail
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function get_debug_info() {
$mail_text = array();
$mail_text[] = '<br><strong>Server:</strong>';
$disabled_functions = ini_get( 'disable_functions' );
$disabled = (array) explode( ',', trim( $disabled_functions ) );
$mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
if ( function_exists( 'apache_get_modules' ) ) {
$modules = apache_get_modules();
$mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
}
if ( function_exists( 'selinux_is_enabled' ) ) {
$mail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
}
if ( function_exists( 'grsecurity_is_enabled' ) ) {
$mail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
}
return implode( '<br>', $mail_text );
}
/**
* @inheritdoc
*/
public function is_mailer_complete() {
return true;
}
}
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Mail
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function get_debug_info() {
$mail_text = array();
$mail_text[] = '<br><strong>Server:</strong>';
$disabled_functions = ini_get( 'disable_functions' );
$disabled = (array) explode( ',', trim( $disabled_functions ) );
$mail_text[] = '<strong>PHP.mail():</strong> ' . ( in_array( 'mail', $disabled, true ) || ! function_exists( 'mail' ) ? 'No' : 'Yes' );
if ( function_exists( 'apache_get_modules' ) ) {
$modules = apache_get_modules();
$mail_text[] = '<strong>Apache.mod_security:</strong> ' . ( in_array( 'mod_security', $modules, true ) || in_array( 'mod_security2', $modules, true ) ? 'Yes' : 'No' );
}
if ( function_exists( 'selinux_is_enabled' ) ) {
$mail_text[] = '<strong>OS.SELinux:</strong> ' . ( selinux_is_enabled() ? 'Yes' : 'No' );
}
if ( function_exists( 'grsecurity_is_enabled' ) ) {
$mail_text[] = '<strong>OS.grsecurity:</strong> ' . ( grsecurity_is_enabled() ? 'Yes' : 'No' );
}
return implode( '<br>', $mail_text );
}
/**
* @inheritdoc
*/
public function is_mailer_complete() {
return true;
}
}

View File

@ -1,42 +1,42 @@
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Mail constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/php.svg',
'slug' => 'mail',
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<blockquote>
<?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
</blockquote>
<?php
}
}
<?php
namespace WPMailSMTP\Providers\Mail;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Option.
*
* @since 1.0.0
*/
class Options extends OptionsAbstract {
/**
* Mail constructor.
*
* @since 1.0.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/php.svg',
'slug' => 'mail',
'title' => esc_html__( 'Default (none)', 'wp-mail-smtp' ),
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<blockquote>
<?php esc_html_e( 'You currently have the native WordPress option selected. Please select any other Mailer option above to continue the setup.', 'wp-mail-smtp' ); ?>
</blockquote>
<?php
}
}

View File

@ -227,7 +227,7 @@ class Mailer extends MailerAbstract {
*
* @since 1.0.0
*
* @param array $attachments
* @param array $attachments The array of attachments data.
*/
public function set_attachments( $attachments ) {
@ -249,8 +249,7 @@ class Mailer extends MailerAbstract {
if ( is_file( $attachment[0] ) && is_readable( $attachment[0] ) ) {
$file = file_get_contents( $attachment[0] );
}
}
catch ( \Exception $e ) {
} catch ( \Exception $e ) {
$file = false;
}
@ -267,7 +266,7 @@ class Mailer extends MailerAbstract {
if ( ! empty( $data ) ) {
// First, generate a boundary for the multipart message.
$boundary = base_convert( uniqid( 'boundary', true ), 10, 36 );
$boundary = $this->phpmailer->generate_id();
// Iterate through pre-built params and build a payload.
foreach ( $this->body as $key => $value ) {

View File

@ -1,44 +1,44 @@
<?php
namespace WPMailSMTP\Providers\Outlook;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 1.7.0
*/
class Options extends OptionsAbstract {
/**
* Outlook Options constructor.
*
* @since 1.7.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/microsoft.svg',
'slug' => 'outlook',
'title' => esc_html__( 'Outlook', 'wp-mail-smtp' ),
'disabled' => true,
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<p>
<?php esc_html_e( 'We\'re sorry, the Microsoft Outlook mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
</p>
<?php
}
}
<?php
namespace WPMailSMTP\Providers\Outlook;
use WPMailSMTP\Providers\OptionsAbstract;
/**
* Class Options.
*
* @since 1.7.0
*/
class Options extends OptionsAbstract {
/**
* Outlook Options constructor.
*
* @since 1.7.0
*/
public function __construct() {
parent::__construct(
array(
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/microsoft.svg',
'slug' => 'outlook',
'title' => esc_html__( 'Outlook', 'wp-mail-smtp' ),
'disabled' => true,
)
);
}
/**
* @inheritdoc
*/
public function display_options() {
?>
<p>
<?php esc_html_e( 'We\'re sorry, the Microsoft Outlook mailer is not available on your plan. Please upgrade to the PRO plan to unlock all these awesome features.', 'wp-mail-smtp' ); ?>
</p>
<?php
}
}

View File

@ -1,32 +1,32 @@
<?php
namespace WPMailSMTP\Providers\Pepipost;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Pepipost
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function is_mailer_complete() {
$options = $this->options->get_group( $this->mailer );
// Host and Port are the only really required options.
if (
! empty( $options['host'] ) &&
! empty( $options['port'] )
) {
return true;
}
return false;
}
}
<?php
namespace WPMailSMTP\Providers\Pepipost;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\Pepipost
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function is_mailer_complete() {
$options = $this->options->get_group( $this->mailer );
// Host and Port are the only really required options.
if (
! empty( $options['host'] ) &&
! empty( $options['port'] )
) {
return true;
}
return false;
}
}

View File

@ -1,32 +1,32 @@
<?php
namespace WPMailSMTP\Providers\SMTP;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\SMTP
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function is_mailer_complete() {
$options = $this->options->get_group( $this->mailer );
// Host and Port are the only really required options.
if (
! empty( $options['host'] ) &&
! empty( $options['port'] )
) {
return true;
}
return false;
}
}
<?php
namespace WPMailSMTP\Providers\SMTP;
use WPMailSMTP\Providers\MailerAbstract;
/**
* Class Mailer inherits everything from parent abstract class.
* This file is required for a proper work of Loader and \ReflectionClass.
*
* @package WPMailSMTP\Providers\SMTP
*/
class Mailer extends MailerAbstract {
/**
* @inheritdoc
*/
public function is_mailer_complete() {
$options = $this->options->get_group( $this->mailer );
// Host and Port are the only really required options.
if (
! empty( $options['host'] ) &&
! empty( $options['port'] )
) {
return true;
}
return false;
}
}

View File

@ -1,93 +1,98 @@
<?php
namespace WPMailSMTP\Providers\Sendinblue;
/**
* Class Api is a wrapper for Sendinblue library with handy methods.
*
* @since 1.6.0
*/
class Api {
/**
* Contains mailer options, constants + DB values.
*
* @since 1.6.0
*
* @var array
*/
private $options;
/**
* API constructor that inits defaults and retrieves options.
*
* @since 1.6.0
*/
public function __construct() {
$this->options = \WPMailSMTP\Options::init()->get_group( Options::SLUG );
}
/**
* Configure API key authorization: api-key.
*
* @since 1.6.0
*
* @return \SendinBlue\Client\Configuration
*/
protected function get_api_config() {
return \SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey( 'api-key', isset( $this->options['api_key'] ) ? $this->options['api_key'] : '' );
}
/**
* Get the mailer client instance for Account API.
*
* @since 1.6.0
*/
public function get_account_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new \SendinBlue\Client\Api\AccountApi( null, $this->get_api_config() );
}
/**
* Get the mailer client instance for Sender API.
*
* @since 1.6.0
*/
public function get_sender_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new \SendinBlue\Client\Api\SendersApi( null, $this->get_api_config() );
}
/**
* Get the mailer client instance for SMTP API.
*
* @since 1.6.0
*/
public function get_smtp_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new \SendinBlue\Client\Api\SMTPApi( null, $this->get_api_config() );
}
/**
* Whether the mailer is ready to be used in API calls.
*
* @since 1.6.0
*
* @return bool
*/
public function is_ready() {
return ! empty( $this->options['api_key'] );
}
}
<?php
namespace WPMailSMTP\Providers\Sendinblue;
use WPMailSMTP\Vendor\SendinBlue\Client\Api\AccountApi;
use WPMailSMTP\Vendor\SendinBlue\Client\Api\SendersApi;
use WPMailSMTP\Vendor\SendinBlue\Client\Api\SMTPApi;
use WPMailSMTP\Vendor\SendinBlue\Client\Configuration;
/**
* Class Api is a wrapper for Sendinblue library with handy methods.
*
* @since 1.6.0
*/
class Api {
/**
* Contains mailer options, constants + DB values.
*
* @since 1.6.0
*
* @var array
*/
private $options;
/**
* API constructor that inits defaults and retrieves options.
*
* @since 1.6.0
*/
public function __construct() {
$this->options = \WPMailSMTP\Options::init()->get_group( Options::SLUG );
}
/**
* Configure API key authorization: api-key.
*
* @since 1.6.0
*
* @return Configuration
*/
protected function get_api_config() {
return Configuration::getDefaultConfiguration()->setApiKey( 'api-key', isset( $this->options['api_key'] ) ? $this->options['api_key'] : '' );
}
/**
* Get the mailer client instance for Account API.
*
* @since 1.6.0
*/
public function get_account_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new AccountApi( null, $this->get_api_config() );
}
/**
* Get the mailer client instance for Sender API.
*
* @since 1.6.0
*/
public function get_sender_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new SendersApi( null, $this->get_api_config() );
}
/**
* Get the mailer client instance for SMTP API.
*
* @since 1.6.0
*/
public function get_smtp_client() {
// Include the library.
require_once wp_mail_smtp()->plugin_path . '/vendor/autoload.php';
return new SMTPApi( null, $this->get_api_config() );
}
/**
* Whether the mailer is ready to be used in API calls.
*
* @since 1.6.0
*
* @return bool
*/
public function is_ready() {
return ! empty( $this->options['api_key'] );
}
}

View File

@ -5,6 +5,9 @@ namespace WPMailSMTP\Providers\Sendinblue;
use WPMailSMTP\Debug;
use WPMailSMTP\MailCatcherInterface;
use WPMailSMTP\Providers\MailerAbstract;
use WPMailSMTP\Vendor\SendinBlue\Client\ApiException;
use WPMailSMTP\Vendor\SendinBlue\Client\Model\CreateSmtpEmail;
use WPMailSMTP\Vendor\SendinBlue\Client\Model\SendSmtpEmail;
use WPMailSMTP\WP;
/**
@ -286,11 +289,11 @@ class Mailer extends MailerAbstract {
*
* @since 1.6.0
*
* @return \SendinBlue\Client\Model\SendSmtpEmail
* @return SendSmtpEmail
*/
public function get_body() {
return new \SendinBlue\Client\Model\SendSmtpEmail( $this->body );
return new SendSmtpEmail( $this->body );
}
/**
@ -306,7 +309,7 @@ class Mailer extends MailerAbstract {
$response = $api->get_smtp_client()->sendTransacEmail( $this->get_body() );
$this->process_response( $response );
} catch ( \SendinBlue\Client\ApiException $e ) {
} catch ( ApiException $e ) {
$error = json_decode( $e->getResponseBody() );
if ( json_last_error() === JSON_ERROR_NONE && ! empty( $error ) ) {
@ -330,7 +333,7 @@ class Mailer extends MailerAbstract {
*
* @since 1.6.0
*
* @param \SendinBlue\Client\Model\CreateSmtpEmail $response
* @param CreateSmtpEmail $response The Sendinblue Email object.
*/
protected function process_response( $response ) {
@ -348,7 +351,7 @@ class Mailer extends MailerAbstract {
$is_sent = false;
if ( $this->response instanceof \SendinBlue\Client\Model\CreateSmtpEmail ) {
if ( $this->response instanceof CreateSmtpEmail ) {
$is_sent = $this->response->valid();
}

View File

@ -27,30 +27,41 @@ 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 our 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' ),
[
'strong' => true,
'br' => true,
'a' => [
'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(
[
'logo_url' => wp_mail_smtp()->assets_url . '/images/providers/sendinblue.svg',
'slug' => self::SLUG,
'title' => esc_html__( 'Sendinblue', 'wp-mail-smtp' ),
'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' ),
[
'br' => true,
'a' => [
'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'
),
'description' => $description,
'supports' => [
'from_email' => true,
'from_name' => true,
@ -58,6 +69,7 @@ class Options extends OptionsAbstract {
'from_email_force' => true,
'from_name_force' => true,
],
'recommended' => true,
]
);
}