SendGrid - Version 1.9.2

Version Description

  • Improved response time on admin dashboard
Download this release

Release Info

Developer team-rs
Plugin Icon 128x128 SendGrid
Version 1.9.2
Comparing to
See all releases

Code changes from version 1.9.1 to 1.9.2

Files changed (3) hide show
  1. lib/class-sendgrid-tools.php +32 -27
  2. readme.txt +5 -1
  3. wpsendgrid.php +1 -1
lib/class-sendgrid-tools.php CHANGED
@@ -6,7 +6,6 @@ class Sendgrid_Tools
6
  const CHECK_CREDENTIALS_CACHE_KEY = "sendgrid_credentials_check";
7
  const CHECK_API_KEY_CACHE_KEY = "sendgrid_api_key_check";
8
  const VALID_CREDENTIALS_STATUS = "valid";
9
- const INVALID_CREDENTIALS_STATUS = "invalid";
10
 
11
  // used static variable because php 5.3 doesn't support array as constant
12
  public static $allowed_ports = array( Sendgrid_SMTP::TLS, Sendgrid_SMTP::TLS_ALTERNATIVE, Sendgrid_SMTP::SSL );
@@ -23,43 +22,45 @@ class Sendgrid_Tools
23
  */
24
  public static function check_username_password( $username, $password, $clear_cache = false )
25
  {
26
- if ( !$username or !$password ) {
27
  return false;
28
  }
29
 
30
- if ( $clear_cache ) {
31
- wp_cache_delete( self::CHECK_CREDENTIALS_CACHE_KEY, self::CACHE_GROUP );
 
 
 
 
 
 
 
32
  }
33
 
34
- $valid_username_password = wp_cache_get( self::CHECK_CREDENTIALS_CACHE_KEY, self::CACHE_GROUP );
35
  if ( self::VALID_CREDENTIALS_STATUS == $valid_username_password ) {
36
  return true;
37
- } elseif ( self::INVALID_CREDENTIALS_STATUS == $valid_username_password ) {
38
- return false;
39
  }
40
 
41
  $url = 'https://api.sendgrid.com/api/profile.get.json?';
42
- $url .= "api_user=" . urlencode($username) . "&api_key=" . urlencode($password);
43
 
44
  $response = wp_remote_get( $url, array( 'decompress' => false ) );
45
 
46
- if ( ! is_array( $response ) or ! isset( $response['body'] ) )
47
- {
48
- wp_cache_set( self::CHECK_CREDENTIALS_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60 );
49
-
50
  return false;
51
  }
52
 
53
  $response = json_decode( $response['body'], true );
54
 
55
- if ( isset( $response['error'] ) )
56
- {
57
- wp_cache_set( self::CHECK_CREDENTIALS_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60 );
58
-
59
  return false;
60
  }
61
 
62
- wp_cache_set( self::CHECK_CREDENTIALS_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 1800 );
 
 
 
 
63
 
64
  return true;
65
  }
@@ -88,8 +89,6 @@ class Sendgrid_Tools
88
  $response = wp_remote_get( $url, $args );
89
 
90
  if ( ! is_array( $response ) or ! isset( $response['body'] ) ) {
91
- wp_cache_set( self::CHECK_API_KEY_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60 );
92
-
93
  return false;
94
  }
95
 
@@ -125,24 +124,30 @@ class Sendgrid_Tools
125
  return false;
126
  }
127
 
128
- if ( $clear_cache ) {
129
- wp_cache_delete( self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP );
 
 
 
 
 
 
 
130
  }
131
 
132
- $valid_apikey = wp_cache_get( self::CHECK_API_KEY_CACHE_KEY, self::CACHE_GROUP );
133
  if ( self::VALID_CREDENTIALS_STATUS == $valid_apikey ) {
134
  return true;
135
- } elseif ( self::INVALID_CREDENTIALS_STATUS == $valid_apikey ) {
136
- return false;
137
  }
138
 
139
  if( ! Sendgrid_Tools::check_api_key_scopes( $apikey, array( "mail.send" ) ) ) {
140
- wp_cache_set( self::CHECK_API_KEY_CACHE_KEY, self::INVALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 60 );
141
-
142
  return false;
143
  }
144
 
145
- wp_cache_set( self::CHECK_API_KEY_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, self::CACHE_GROUP, 1800 );
 
 
 
 
146
 
147
  return true;
148
  }
6
  const CHECK_CREDENTIALS_CACHE_KEY = "sendgrid_credentials_check";
7
  const CHECK_API_KEY_CACHE_KEY = "sendgrid_api_key_check";
8
  const VALID_CREDENTIALS_STATUS = "valid";
 
9
 
10
  // used static variable because php 5.3 doesn't support array as constant
11
  public static $allowed_ports = array( Sendgrid_SMTP::TLS, Sendgrid_SMTP::TLS_ALTERNATIVE, Sendgrid_SMTP::SSL );
22
  */
23
  public static function check_username_password( $username, $password, $clear_cache = false )
24
  {
25
+ if ( ! $username or ! $password ) {
26
  return false;
27
  }
28
 
29
+ if ( $clear_cache and is_multisite() ) {
30
+ set_site_transient( self::CHECK_CREDENTIALS_CACHE_KEY, null );
31
+ } elseif ( $clear_cache ) {
32
+ set_transient( self::CHECK_CREDENTIALS_CACHE_KEY, null );
33
+ }
34
+
35
+ $valid_username_password = get_transient( self::CHECK_CREDENTIALS_CACHE_KEY );
36
+ if ( is_multisite() ) {
37
+ $valid_username_password = get_site_transient( self::CHECK_CREDENTIALS_CACHE_KEY );
38
  }
39
 
 
40
  if ( self::VALID_CREDENTIALS_STATUS == $valid_username_password ) {
41
  return true;
 
 
42
  }
43
 
44
  $url = 'https://api.sendgrid.com/api/profile.get.json?';
45
+ $url .= "api_user=" . urlencode( $username ) . "&api_key=" . urlencode( $password );
46
 
47
  $response = wp_remote_get( $url, array( 'decompress' => false ) );
48
 
49
+ if ( ! is_array( $response ) or ! isset( $response['body'] ) ) {
 
 
 
50
  return false;
51
  }
52
 
53
  $response = json_decode( $response['body'], true );
54
 
55
+ if ( isset( $response['error'] ) ) {
 
 
 
56
  return false;
57
  }
58
 
59
+ if ( is_multisite() ) {
60
+ set_site_transient( self::CHECK_CREDENTIALS_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, 2 * 60 * 60 );
61
+ } else {
62
+ set_transient( self::CHECK_CREDENTIALS_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, 2 * 60 * 60 );
63
+ }
64
 
65
  return true;
66
  }
89
  $response = wp_remote_get( $url, $args );
90
 
91
  if ( ! is_array( $response ) or ! isset( $response['body'] ) ) {
 
 
92
  return false;
93
  }
94
 
124
  return false;
125
  }
126
 
127
+ if ( $clear_cache and is_multisite() ) {
128
+ set_site_transient( self::CHECK_API_KEY_CACHE_KEY, null );
129
+ } elseif ( $clear_cache ) {
130
+ set_transient( self::CHECK_API_KEY_CACHE_KEY, null );
131
+ }
132
+
133
+ $valid_apikey = get_transient( self::CHECK_API_KEY_CACHE_KEY );
134
+ if ( is_multisite() ) {
135
+ $valid_apikey = get_site_transient( self::CHECK_API_KEY_CACHE_KEY );
136
  }
137
 
 
138
  if ( self::VALID_CREDENTIALS_STATUS == $valid_apikey ) {
139
  return true;
 
 
140
  }
141
 
142
  if( ! Sendgrid_Tools::check_api_key_scopes( $apikey, array( "mail.send" ) ) ) {
 
 
143
  return false;
144
  }
145
 
146
+ if ( is_multisite() ) {
147
+ set_site_transient( self::CHECK_API_KEY_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, 2 * 60 * 60 );
148
+ } else {
149
+ set_transient( self::CHECK_API_KEY_CACHE_KEY, self::VALID_CREDENTIALS_STATUS, 2 * 60 * 60 );
150
+ }
151
 
152
  return true;
153
  }
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: 4.2
6
  Tested up to: 4.5
7
- Stable tag: 1.9.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -212,6 +212,8 @@ The code snippets above are usually added in the functions.php file of your them
212
 
213
  == Changelog ==
214
 
 
 
215
  = 1.9.1 =
216
  * Added filters that allow the change of text or HTML content of all emails before they are sent
217
  * Fixed an issue with the widget admin notice
@@ -324,6 +326,8 @@ The code snippets above are usually added in the functions.php file of your them
324
 
325
  == Upgrade notice ==
326
 
 
 
327
  = 1.9.1 =
328
  * Added filters that allow the change of text or HTML content of all emails before they are sent
329
  * Fixed an issue with the widget admin notice
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: 4.2
6
  Tested up to: 4.5
7
+ Stable tag: 1.9.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
212
 
213
  == Changelog ==
214
 
215
+ = 1.9.2 =
216
+ * Improved response time on admin dashboard
217
  = 1.9.1 =
218
  * Added filters that allow the change of text or HTML content of all emails before they are sent
219
  * Fixed an issue with the widget admin notice
326
 
327
  == Upgrade notice ==
328
 
329
+ = 1.9.2 =
330
+ * Improved response time on admin dashboard
331
  = 1.9.1 =
332
  * Added filters that allow the change of text or HTML content of all emails before they are sent
333
  * Fixed an issue with the widget admin notice
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.9.1
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.9.2
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified