Version Description
- Fixed some failing requests during API Key checks.
- Fixed an error that appeared on fresh installs regarding invalid port setting.
Download this release
Release Info
Developer | team-rs |
Plugin | SendGrid |
Version | 1.7.4 |
Comparing to | |
See all releases |
Code changes from version 1.7.3 to 1.7.4
- lib/class-sendgrid-statistics.php +1 -1
- lib/class-sendgrid-tools.php +42 -36
- readme.txt +7 -1
- wpsendgrid.php +1 -1
lib/class-sendgrid-statistics.php
CHANGED
@@ -90,7 +90,7 @@ class Sendgrid_Statistics
|
|
90 |
$apikey = Sendgrid_Tools::get_api_key();
|
91 |
if ( ( "apikey" == Sendgrid_Tools::get_auth_method() ) and isset( $apikey ) and ( $apikey != '' ) and ! Sendgrid_Tools::check_api_key_stats( $apikey, true ) )
|
92 |
{
|
93 |
-
$message = 'Your Api key
|
94 |
$status = 'error';
|
95 |
}
|
96 |
|
90 |
$apikey = Sendgrid_Tools::get_api_key();
|
91 |
if ( ( "apikey" == Sendgrid_Tools::get_auth_method() ) and isset( $apikey ) and ( $apikey != '' ) and ! Sendgrid_Tools::check_api_key_stats( $apikey, true ) )
|
92 |
{
|
93 |
+
$message = 'Your Api key does not have statistics permissions';
|
94 |
$status = 'error';
|
95 |
}
|
96 |
|
lib/class-sendgrid-tools.php
CHANGED
@@ -60,26 +60,17 @@ class Sendgrid_Tools
|
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
-
* Check apikey
|
64 |
*
|
65 |
* @param string $apikey sendgrid apikey
|
66 |
* @return bool
|
67 |
*/
|
68 |
-
public static function
|
69 |
{
|
70 |
-
if ( ! $apikey )
|
71 |
return false;
|
72 |
|
73 |
-
|
74 |
-
wp_cache_delete(self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP);
|
75 |
-
|
76 |
-
$valid_apikey = wp_cache_get(self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP);
|
77 |
-
if ( self::VALID_CREDENTIALS_STATUS == $valid_apikey )
|
78 |
-
return true;
|
79 |
-
elseif ( self::INVALID_CREDENTIALS_STATUS == $valid_apikey )
|
80 |
-
return false;
|
81 |
-
|
82 |
-
$url = 'https://api.sendgrid.com/api/mail.send.json';
|
83 |
|
84 |
$args = array(
|
85 |
'headers' => array(
|
@@ -96,9 +87,41 @@ class Sendgrid_Tools
|
|
96 |
|
97 |
$response = json_decode( $response['body'], true );
|
98 |
|
99 |
-
if ( isset( $response['errors'] )
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
wp_cache_set(self::CHECK_API_KEY_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60);
|
103 |
|
104 |
return false;
|
@@ -333,7 +356,7 @@ class Sendgrid_Tools
|
|
333 |
if ( defined('SENDGRID_PORT') ) {
|
334 |
return SENDGRID_PORT;
|
335 |
} else {
|
336 |
-
return get_option('sendgrid_port');
|
337 |
}
|
338 |
}
|
339 |
|
@@ -487,25 +510,8 @@ class Sendgrid_Tools
|
|
487 |
*/
|
488 |
public static function check_api_key_stats( $apikey )
|
489 |
{
|
490 |
-
$
|
491 |
|
492 |
-
$
|
493 |
-
'headers' => array(
|
494 |
-
'Authorization' => 'Bearer ' . $apikey )
|
495 |
-
);
|
496 |
-
|
497 |
-
$response = wp_remote_get( $url, $args );
|
498 |
-
|
499 |
-
if ( ! is_array( $response ) or ! isset( $response['body'] ) ) {
|
500 |
-
return false;
|
501 |
-
}
|
502 |
-
|
503 |
-
$response = json_decode( $response['body'], true );
|
504 |
-
|
505 |
-
if ( isset( $response['errors'] ) and ( 'access forbidden' == $response['errors'][0]['message'] ) ) {
|
506 |
-
return false;
|
507 |
-
}
|
508 |
-
|
509 |
-
return true;
|
510 |
}
|
511 |
}
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
+
* Check apikey scopes
|
64 |
*
|
65 |
* @param string $apikey sendgrid apikey
|
66 |
* @return bool
|
67 |
*/
|
68 |
+
public static function check_api_key_scopes( $apikey, $scopes )
|
69 |
{
|
70 |
+
if ( ! $apikey or ! is_array( $scopes ) )
|
71 |
return false;
|
72 |
|
73 |
+
$url = 'https://api.sendgrid.com/v3/scopes';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
$args = array(
|
76 |
'headers' => array(
|
87 |
|
88 |
$response = json_decode( $response['body'], true );
|
89 |
|
90 |
+
if ( isset( $response['errors'] ) )
|
91 |
+
return false;
|
92 |
+
|
93 |
+
if( ! isset( $response['scopes'] ) )
|
94 |
+
return false;
|
95 |
+
|
96 |
+
foreach( $scopes as $scope ) {
|
97 |
+
if( !in_array( $scope, $response['scopes'] ) )
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
|
101 |
+
return true;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Check apikey
|
106 |
+
*
|
107 |
+
* @param string $apikey sendgrid apikey
|
108 |
+
* @return bool
|
109 |
+
*/
|
110 |
+
public static function check_api_key( $apikey, $clear_cache = false )
|
111 |
+
{
|
112 |
+
if ( ! $apikey )
|
113 |
+
return false;
|
114 |
+
|
115 |
+
if ( $clear_cache )
|
116 |
+
wp_cache_delete(self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP);
|
117 |
+
|
118 |
+
$valid_apikey = wp_cache_get(self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP);
|
119 |
+
if ( self::VALID_CREDENTIALS_STATUS == $valid_apikey )
|
120 |
+
return true;
|
121 |
+
elseif ( self::INVALID_CREDENTIALS_STATUS == $valid_apikey )
|
122 |
+
return false;
|
123 |
+
|
124 |
+
if( ! Sendgrid_Tools::check_api_key_scopes( $apikey, array( "mail.send" ) ) ) {
|
125 |
wp_cache_set(self::CHECK_API_KEY_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60);
|
126 |
|
127 |
return false;
|
356 |
if ( defined('SENDGRID_PORT') ) {
|
357 |
return SENDGRID_PORT;
|
358 |
} else {
|
359 |
+
return get_option('sendgrid_port', Sendgrid_SMTP::TLS);
|
360 |
}
|
361 |
}
|
362 |
|
510 |
*/
|
511 |
public static function check_api_key_stats( $apikey )
|
512 |
{
|
513 |
+
$required_scopes = array( 'stats.read', 'categories.stats.read', 'categories.stats.sums.read' );
|
514 |
|
515 |
+
return Sendgrid_Tools::check_api_key_scopes( $apikey, $required_scopes );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
}
|
517 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://sendgrid.com/
|
|
4 |
Tags: email, email reliability, email templates, sendgrid, smtp, transactional email, wp_mail,email infrastructure, email marketing, marketing email, deliverability, email deliverability, email delivery, email server, mail server, email integration, cloud email
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.4
|
7 |
-
Stable tag: 1.7.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -134,6 +134,9 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
|
|
134 |
|
135 |
== Changelog ==
|
136 |
|
|
|
|
|
|
|
137 |
= 1.7.3 =
|
138 |
* Add global config for content-type
|
139 |
* Validate send_method and port set in config file
|
@@ -220,6 +223,9 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
|
|
220 |
|
221 |
== Upgrade notice ==
|
222 |
|
|
|
|
|
|
|
223 |
= 1.7.3 =
|
224 |
* Add global config for content-type
|
225 |
* Validate send_method and port set in config file
|
4 |
Tags: email, email reliability, email templates, sendgrid, smtp, transactional email, wp_mail,email infrastructure, email marketing, marketing email, deliverability, email deliverability, email delivery, email server, mail server, email integration, cloud email
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.4
|
7 |
+
Stable tag: 1.7.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
134 |
|
135 |
== Changelog ==
|
136 |
|
137 |
+
= 1.7.4 =
|
138 |
+
* Fixed some failing requests during API Key checks.
|
139 |
+
* Fixed an error that appeared on fresh installs regarding invalid port setting.
|
140 |
= 1.7.3 =
|
141 |
* Add global config for content-type
|
142 |
* Validate send_method and port set in config file
|
223 |
|
224 |
== Upgrade notice ==
|
225 |
|
226 |
+
= 1.7.4 =
|
227 |
+
* Fixed some failing requests during API Key checks.
|
228 |
+
* Fixed an error that appeared on fresh installs regarding invalid port setting.
|
229 |
= 1.7.3 =
|
230 |
* Add global config for content-type
|
231 |
* Validate send_method and port set in config file
|
wpsendgrid.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: SendGrid
|
4 |
Plugin URI: http://wordpress.org/plugins/sendgrid-email-delivery-simplified/
|
5 |
Description: Email Delivery. Simplified. SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time analytics along with flexible APIs that make custom integration a breeze.
|
6 |
-
Version: 1.7.
|
7 |
Author: SendGrid
|
8 |
Author URI: http://sendgrid.com
|
9 |
Text Domain: sendgrid-email-delivery-simplified
|
3 |
Plugin Name: SendGrid
|
4 |
Plugin URI: http://wordpress.org/plugins/sendgrid-email-delivery-simplified/
|
5 |
Description: Email Delivery. Simplified. SendGrid's cloud-based email infrastructure relieves businesses of the cost and complexity of maintaining custom email systems. SendGrid provides reliable delivery, scalability and real-time analytics along with flexible APIs that make custom integration a breeze.
|
6 |
+
Version: 1.7.4
|
7 |
Author: SendGrid
|
8 |
Author URI: http://sendgrid.com
|
9 |
Text Domain: sendgrid-email-delivery-simplified
|