updated plugin WP Mail SMTP
version 2.5.0
This commit is contained in:
@ -92,7 +92,7 @@ class Auth extends AuthAbstract {
|
||||
'client_id' => $this->options['client_id'],
|
||||
'client_secret' => $this->options['client_secret'],
|
||||
'redirect_uris' => array(
|
||||
self::get_plugin_auth_url(),
|
||||
self::get_oauth_redirect_url(),
|
||||
),
|
||||
)
|
||||
);
|
||||
@ -102,7 +102,8 @@ class Auth extends AuthAbstract {
|
||||
$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->setRedirectUri( self::get_plugin_auth_url() );
|
||||
$client->setRedirectUri( self::get_oauth_redirect_url() );
|
||||
$client->setState( self::get_plugin_auth_url() );
|
||||
|
||||
// Apply custom options to the client.
|
||||
$client = apply_filters( 'wp_mail_smtp_providers_gmail_auth_get_client_custom_options', $client );
|
||||
@ -115,15 +116,22 @@ class Auth extends AuthAbstract {
|
||||
$creds = $client->fetchAccessTokenWithAuthCode( $this->options['auth_code'] );
|
||||
} catch ( \Exception $e ) {
|
||||
$creds['error'] = $e->getMessage();
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$creds['error']
|
||||
);
|
||||
}
|
||||
|
||||
// Bail if we have an error.
|
||||
if ( ! empty( $creds['error'] ) ) {
|
||||
if ( $creds['error'] === 'invalid_client' ) {
|
||||
$creds['error'] .= PHP_EOL . esc_html__( 'Please make sure your Google Client ID and Secret in the plugin settings are valid. Save the settings and try the Authorization again.' , 'wp-mail-smtp' );
|
||||
}
|
||||
|
||||
Debug::set(
|
||||
'Mailer: Gmail' . "\r\n" .
|
||||
$creds['error']
|
||||
);
|
||||
|
||||
return $client;
|
||||
} else {
|
||||
Debug::clear();
|
||||
}
|
||||
|
||||
$this->update_access_token( $client->getAccessToken() );
|
||||
@ -173,7 +181,7 @@ class Auth extends AuthAbstract {
|
||||
*/
|
||||
public function process() {
|
||||
|
||||
if ( ! ( isset( $_GET['tab'] ) && $_GET['tab'] === 'auth' ) ) {
|
||||
if ( ! ( isset( $_GET['tab'] ) && $_GET['tab'] === 'auth' ) ) { // phpcs:ignore
|
||||
wp_safe_redirect( wp_mail_smtp()->get_admin()->get_admin_page_url() );
|
||||
exit;
|
||||
}
|
||||
@ -199,8 +207,8 @@ class Auth extends AuthAbstract {
|
||||
$scope = '';
|
||||
$error = '';
|
||||
|
||||
if ( isset( $_GET['error'] ) ) {
|
||||
$error = sanitize_key( $_GET['error'] );
|
||||
if ( isset( $_GET['error'] ) ) { // phpcs:ignore
|
||||
$error = sanitize_key( $_GET['error'] ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// In case of any error: display a message to a user.
|
||||
@ -215,11 +223,11 @@ class Auth extends AuthAbstract {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $_GET['code'] ) ) {
|
||||
$code = $_GET['code'];
|
||||
if ( isset( $_GET['code'] ) ) { // phpcs:ignore
|
||||
$code = urldecode( $_GET['code'] ); // phpcs:ignore
|
||||
}
|
||||
if ( isset( $_GET['scope'] ) ) {
|
||||
$scope = urldecode( $_GET['scope'] );
|
||||
if ( isset( $_GET['scope'] ) ) { // phpcs:ignore
|
||||
$scope = urldecode( base64_decode( $_GET['scope'] ) ); // phpcs:ignore
|
||||
}
|
||||
|
||||
// Let's try to get the access token.
|
||||
@ -328,4 +336,19 @@ class Auth extends AuthAbstract {
|
||||
|
||||
return $this->aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Google oAuth 2.0 redirect URL.
|
||||
*
|
||||
* This is the URL that Google will redirect after the access to the Gmail account is granted or rejected.
|
||||
* The below endpoint will then redirect back to the user's WP site (to self::get_plugin_auth_url() URL).
|
||||
*
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_oauth_redirect_url() {
|
||||
|
||||
return 'https://connect.wpmailsmtp.com/google/';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user