SendGrid - Version 1.6.7

Version Description

  • Ability to use email templates, fix category statistics, display sender test form if we only have sending errors
Download this release

Release Info

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

Code changes from version 1.6.6 to 1.6.7

assets/screenshot-10.png ADDED
Binary file
lib/class-sendgrid-settings.php CHANGED
@@ -57,6 +57,7 @@ class Sendgrid_Settings
57
  $errors = ( $sent->errors[0] ) ? $sent->errors[0] : $sent;
58
  $message = 'Email not sent. ' . $errors;
59
  $status = 'error';
 
60
  }
61
 
62
  }
@@ -69,6 +70,7 @@ class Sendgrid_Settings
69
  } else {
70
  $message = 'Email not sent. ' . $sent;
71
  $status = 'error';
 
72
  }
73
  }
74
  } else {
@@ -120,6 +122,12 @@ class Sendgrid_Settings
120
  update_option('sendgrid_categories', $categories);
121
  }
122
 
 
 
 
 
 
 
123
  if (isset($_POST['sendgrid_api']))
124
  {
125
  $method = $_POST['sendgrid_api'];
@@ -171,6 +179,7 @@ class Sendgrid_Settings
171
  $email = Sendgrid_Tools::get_from_email();
172
  $reply_to = Sendgrid_Tools::get_reply_to();
173
  $categories = stripslashes( Sendgrid_Tools::get_categories() );
 
174
  $port = Sendgrid_Tools::get_port();
175
 
176
  $allowed_methods = array('smtp', 'api');
@@ -201,6 +210,13 @@ class Sendgrid_Settings
201
  }
202
  }
203
 
 
 
 
 
 
 
 
204
  $are_global_credentials = ( defined('SENDGRID_USERNAME') and defined('SENDGRID_PASSWORD') );
205
  $is_global_api_key = defined('SENDGRID_API_KEY');
206
  $has_port = defined('SENDGRID_PORT');
57
  $errors = ( $sent->errors[0] ) ? $sent->errors[0] : $sent;
58
  $message = 'Email not sent. ' . $errors;
59
  $status = 'error';
60
+ $error_type = 'sending';
61
  }
62
 
63
  }
70
  } else {
71
  $message = 'Email not sent. ' . $sent;
72
  $status = 'error';
73
+ $error_type = 'sending';
74
  }
75
  }
76
  } else {
122
  update_option('sendgrid_categories', $categories);
123
  }
124
 
125
+ if ( isset( $_POST['sendgrid_template'] ) )
126
+ {
127
+ $template = $_POST['sendgrid_template'];
128
+ update_option( 'sendgrid_template', $template );
129
+ }
130
+
131
  if (isset($_POST['sendgrid_api']))
132
  {
133
  $method = $_POST['sendgrid_api'];
179
  $email = Sendgrid_Tools::get_from_email();
180
  $reply_to = Sendgrid_Tools::get_reply_to();
181
  $categories = stripslashes( Sendgrid_Tools::get_categories() );
182
+ $template = stripslashes( Sendgrid_Tools::get_template() );
183
  $port = Sendgrid_Tools::get_port();
184
 
185
  $allowed_methods = array('smtp', 'api');
210
  }
211
  }
212
 
213
+ if ( $template ) {
214
+ if ( ! Sendgrid_Tools::check_template( $template ) ) {
215
+ $message = 'Template not found';
216
+ $status = 'error';
217
+ }
218
+ }
219
+
220
  $are_global_credentials = ( defined('SENDGRID_USERNAME') and defined('SENDGRID_PASSWORD') );
221
  $is_global_api_key = defined('SENDGRID_API_KEY');
222
  $has_port = defined('SENDGRID_PORT');
lib/class-sendgrid-statistics.php CHANGED
@@ -127,15 +127,17 @@ class Sendgrid_Statistics
127
  $parameters['end_date'] = $_POST['end_date'];
128
  }
129
 
130
- if ( $_POST['type'] && 'general' != $_POST['type'] ) {
 
 
131
  if( 'wordpress' == $_POST['type'] ) {
132
- $parameters['category'] = 'wp_sendgrid_plugin';
133
  } else {
134
- $parameters['category'] = urlencode( $_POST['type'] );
135
  }
 
136
  }
137
-
138
- echo Sendgrid_Tools::curl_request( 'v3/stats', $parameters );
139
 
140
  die();
141
  }
127
  $parameters['end_date'] = $_POST['end_date'];
128
  }
129
 
130
+ $endpoint = 'v3/stats';
131
+
132
+ if ( isset( $_POST['type'] ) && 'general' != $_POST['type'] ) {
133
  if( 'wordpress' == $_POST['type'] ) {
134
+ $parameters['categories'] = 'wp_sendgrid_plugin';
135
  } else {
136
+ $parameters['categories'] = urlencode( $_POST['type'] );
137
  }
138
+ $endpoint = 'v3/categories/stats';
139
  }
140
+ echo Sendgrid_Tools::curl_request( $endpoint, $parameters );
 
141
 
142
  die();
143
  }
lib/class-sendgrid-tools.php CHANGED
@@ -61,6 +61,37 @@ class Sendgrid_Tools
61
  return true;
62
  }
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  /**
65
  * Make cURL request to SendGrid API
66
  *
@@ -264,4 +295,18 @@ class Sendgrid_Tools
264
 
265
  return array();
266
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  }
61
  return true;
62
  }
63
 
64
+ /**
65
+ * Check template
66
+ *
67
+ * @param string $template sendgrid template
68
+ * @return bool
69
+ */
70
+ public static function check_template( $template )
71
+ {
72
+ $url = 'v3/templates/' . $template;
73
+
74
+ $parameters['api_user'] = Sendgrid_Tools::get_username();
75
+ $parameters['api_key'] = Sendgrid_Tools::get_password();
76
+ $parameters['apikey'] = Sendgrid_Tools::get_api_key();
77
+
78
+ $response = Sendgrid_Tools::curl_request( $url, $parameters );
79
+
80
+ if ( !$response )
81
+ {
82
+ return false;
83
+ }
84
+
85
+ $response = json_decode( $response, true );
86
+
87
+ if ( isset( $response['error'] ) )
88
+ {
89
+ return false;
90
+ }
91
+
92
+ return true;
93
+ }
94
+
95
  /**
96
  * Make cURL request to SendGrid API
97
  *
295
 
296
  return array();
297
  }
298
+
299
+ /**
300
+ * Return template from the database or global variable
301
+ *
302
+ * @return string template
303
+ */
304
+ public static function get_template()
305
+ {
306
+ if ( defined('SENDGRID_TEMPLATE') ) {
307
+ return SENDGRID_TEMPLATE;
308
+ } else {
309
+ return get_option( 'sendgrid_template' );
310
+ }
311
+ }
312
  }
lib/overwrite-sendgrid-methods.php CHANGED
@@ -175,6 +175,11 @@ if ( ! function_exists('wp_mail'))
175
  }
176
  }
177
 
 
 
 
 
 
178
  // Headers
179
  $cc = array();
180
  $bcc = array();
@@ -270,6 +275,14 @@ if ( ! function_exists('wp_mail'))
270
  }
271
  }
272
  break;
 
 
 
 
 
 
 
 
273
  default:
274
  // Add it to our grand headers array
275
  $headers[trim( $name )] = trim( $content );
175
  }
176
  }
177
 
178
+ $template = Sendgrid_Tools::get_template();
179
+ if ( $template) {
180
+ $mail->setTemplateId( $template );
181
+ }
182
+
183
  // Headers
184
  $cc = array();
185
  $bcc = array();
275
  }
276
  }
277
  break;
278
+ case 'template':
279
+ $template_ok = Sendgrid_Tools::check_template( trim( $content ) );
280
+ if ( $template_ok ) {
281
+ $mail->setTemplateId( trim( $content ) );
282
+ } elseif ( Sendgrid_Tools::get_template() ) {
283
+ $mail->setTemplateId( Sendgrid_Tools::get_template() );
284
+ }
285
+ break;
286
  default:
287
  // Add it to our grand headers array
288
  $headers[trim( $name )] = trim( $content );
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.3
7
- Stable tag: 1.6.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -22,6 +22,8 @@ To have the SendGrid plugin running after you have activated it, go to the plugi
22
 
23
  You can also set default values for the "Name", "Sending Address" and the "Reply Address", so that you don't need to set these headers every time you want to send an email from your application.
24
 
 
 
25
  Emails are tracked and automatically tagged for statistics within the SendGrid Dashboard. You can also add general tags to every email sent, as well as particular tags based on selected emails defined by your requirements.
26
 
27
  There are a couple levels of integration between your WordPress installation and the SendGrid plugin:
@@ -60,6 +62,7 @@ $headers[] = 'From: Me Myself <me@example.net>';
60
  $headers[] = 'Cc: address4@sendgrid.com';
61
  $headers[] = 'Bcc: address5@sendgrid.com';
62
  $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
 
63
 
64
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
65
 
@@ -93,9 +96,10 @@ To auto install the SendGrid Plugin from the WordPress admin:
93
 
94
  SendGrid settings can optionally be defined as global variables (wp-config.php):
95
 
96
- 1. Set credentials (both need to be set in order to get credentials from variables and not from the database):
97
  * Username: define('SENDGRID_USERNAME', 'sendgrid_username');
98
  * Password: define('SENDGRID_PASSWORD', 'sendgrid_password');
 
99
 
100
  2. Set email related settings:
101
  * Send method ('api' or 'smtp'): define('SENDGRID_SEND_METHOD', 'api');
@@ -103,6 +107,7 @@ SendGrid settings can optionally be defined as global variables (wp-config.php):
103
  * From email: define('SENDGRID_FROM_EMAIL', 'from_email@example.com');
104
  * Reply to email: define('SENDGRID_REPLY_TO', 'reply_to@example.com');
105
  * Categories: define('SENDGRID_CATEGORIES', 'category_1,category_2');
 
106
 
107
  == Frequently asked questions ==
108
 
@@ -121,9 +126,12 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
121
  7. If you click in the right corner from the top of the page on the "Help" button, a popup window with more information will appear.
122
  8. Select the time interval for which you want to see SendGrid statistics and charts.
123
  9. Now you are able to configure port number when using SMTP method.
 
124
 
125
  == Changelog ==
126
 
 
 
127
  = 1.6.6 =
128
  * Remove $plugin variable to avoid conflict with other plugins
129
  = 1.6.5 =
@@ -185,6 +193,8 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
185
 
186
  == Upgrade notice ==
187
 
 
 
188
  = 1.6.6 =
189
  * Remove $plugin variable to avoid conflict with other plugins
190
  = 1.6.5 =
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.3
7
+ Stable tag: 1.6.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
22
 
23
  You can also set default values for the "Name", "Sending Address" and the "Reply Address", so that you don't need to set these headers every time you want to send an email from your application.
24
 
25
+ You can set the template ID to be used in all your emails on the settings page or you can set it for each email in headers.
26
+
27
  Emails are tracked and automatically tagged for statistics within the SendGrid Dashboard. You can also add general tags to every email sent, as well as particular tags based on selected emails defined by your requirements.
28
 
29
  There are a couple levels of integration between your WordPress installation and the SendGrid plugin:
62
  $headers[] = 'Cc: address4@sendgrid.com';
63
  $headers[] = 'Bcc: address5@sendgrid.com';
64
  $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
65
+ $headers[] = 'template: templateID'
66
 
67
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
68
 
96
 
97
  SendGrid settings can optionally be defined as global variables (wp-config.php):
98
 
99
+ 1. Set credentials (You can use credentials or Api key. If using credentials, both need to be set in order to get credentials from variables and not from the database):
100
  * Username: define('SENDGRID_USERNAME', 'sendgrid_username');
101
  * Password: define('SENDGRID_PASSWORD', 'sendgrid_password');
102
+ * API key: define('SENDGRID_API_KEY', 'sendgrid_api_key');
103
 
104
  2. Set email related settings:
105
  * Send method ('api' or 'smtp'): define('SENDGRID_SEND_METHOD', 'api');
107
  * From email: define('SENDGRID_FROM_EMAIL', 'from_email@example.com');
108
  * Reply to email: define('SENDGRID_REPLY_TO', 'reply_to@example.com');
109
  * Categories: define('SENDGRID_CATEGORIES', 'category_1,category_2');
110
+ * Template: define('SENDGRID_TEMPLATE', 'templateID');
111
 
112
  == Frequently asked questions ==
113
 
126
  7. If you click in the right corner from the top of the page on the "Help" button, a popup window with more information will appear.
127
  8. Select the time interval for which you want to see SendGrid statistics and charts.
128
  9. Now you are able to configure port number when using SMTP method.
129
+ 10. You are able to configure what template to use for sending emails.
130
 
131
  == Changelog ==
132
 
133
+ = 1.6.7 =
134
+ * Ability to use email templates, fix category statistics, display sender test form if we only have sending errors
135
  = 1.6.6 =
136
  * Remove $plugin variable to avoid conflict with other plugins
137
  = 1.6.5 =
193
 
194
  == Upgrade notice ==
195
 
196
+ = 1.6.7 =
197
+ * Ability to use email templates, fix category statistics, display sender test form if we only have sending errors
198
  = 1.6.6 =
199
  * Remove $plugin variable to avoid conflict with other plugins
200
  = 1.6.5 =
view/sendgrid_settings.php CHANGED
@@ -109,6 +109,15 @@
109
  Categories must be separated by commas (Example: category1, category2).') ?></p>
110
  </td>
111
  </tr>
 
 
 
 
 
 
 
 
 
112
  <tr valign="top">
113
  <td colspan="2">
114
  <p>
@@ -123,7 +132,7 @@
123
  </p>
124
  </form>
125
  <br />
126
- <?php if ( !isset($status) or 'updated' == $status ): ?>
127
  <h2><?php _e('SendGrid Test') ?></h2>
128
  <h3><?php _e('Send a test email with these settings') ?></h3>
129
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
109
  Categories must be separated by commas (Example: category1, category2).') ?></p>
110
  </td>
111
  </tr>
112
+ <tr valign="top">
113
+ <th scope="row"><?php _e("Template: "); ?></th>
114
+ <td>
115
+ <input type="text" name="sendgrid_template" value="<?php echo $template; ?>" size="20" class="regular-text" <?php disabled( defined('SENDGRID_TEMPLATE') ); ?>>
116
+ <span><small><em><?php _e('Leave blank to send without template.') ?></em></small></span>
117
+ <p class="description"><?php _e('The template ID used to send emails. <br />
118
+ Example: 0b1240a5-188d-4ea7-93c1-19a7a89466b2.') ?></p>
119
+ </td>
120
+ </tr>
121
  <tr valign="top">
122
  <td colspan="2">
123
  <p>
132
  </p>
133
  </form>
134
  <br />
135
+ <?php if ( !isset($status) or ( 'updated' == $status ) or ( 'error' == $status and isset( $error_type ) and 'sending' == $error_type ) ): ?>
136
  <h2><?php _e('SendGrid Test') ?></h2>
137
  <h3><?php _e('Send a test email with these settings') ?></h3>
138
  <form name="sendgrid_test" method="POST" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>">
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.6.6
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified
@@ -20,7 +20,7 @@ if ( version_compare( phpversion(), '5.3.0', '<' ) ) {
20
  */
21
  function php_version_error()
22
  {
23
- echo '<div class="error"><p>' . __('SendGrid: Plugin require PHP >= 5.3.0.') . '</p></div>';
24
  }
25
  }
26
  else
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.6.7
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified
20
  */
21
  function php_version_error()
22
  {
23
+ echo '<div class="error"><p>' . __('SendGrid: Plugin requires PHP >= 5.3.0.') . '</p></div>';
24
  }
25
  }
26
  else