updated plugin WP Mail SMTP version 2.4.0
This commit is contained in:
@ -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 ) {
|
||||
|
||||
@ -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 ) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user