SendGrid - Version 1.6.9

Version Description

  • Add categories in headers, add errror message on statistics page if API key is not having permissions
Download this release

Release Info

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

Code changes from version 1.6.8 to 1.6.9

lib/class-sendgrid-statistics.php CHANGED
@@ -25,8 +25,12 @@ class Sendgrid_Statistics
25
  */
26
  public static function add_dashboard_widget()
27
  {
28
- if ( ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() )
29
- and ! Sendgrid_Tools::check_api_key( Sendgrid_Tools::get_api_key() ) ) {
 
 
 
 
30
  return;
31
  }
32
 
@@ -51,8 +55,9 @@ class Sendgrid_Statistics
51
  */
52
  public static function add_statistics_menu()
53
  {
54
- if ( ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() )
55
- and ! Sendgrid_Tools::check_api_key( Sendgrid_Tools::get_api_key() ) ) {
 
56
  return;
57
  }
58
 
@@ -67,6 +72,14 @@ class Sendgrid_Statistics
67
  */
68
  public static function show_statistics_page()
69
  {
 
 
 
 
 
 
 
 
70
  require plugin_dir_path( __FILE__ ) . '../view/sendgrid_stats.php';
71
  }
72
 
@@ -116,7 +129,13 @@ class Sendgrid_Statistics
116
 
117
  $parameters['api_user'] = Sendgrid_Tools::get_username();
118
  $parameters['api_key'] = Sendgrid_Tools::get_password();
119
- $parameters['apikey'] = Sendgrid_Tools::get_api_key();
 
 
 
 
 
 
120
 
121
  $parameters['data_type'] = 'global';
122
 
25
  */
26
  public static function add_dashboard_widget()
27
  {
28
+ $api_key = Sendgrid_Tools::get_api_key();
29
+
30
+ if ( ( Sendgrid_Tools::get_auth_method() == "apikey" and
31
+ ( ! Sendgrid_Tools::check_api_key( Sendgrid_Tools::get_api_key() ) or ! Sendgrid_Tools::check_api_key_stats( $api_key ) ) ) or
32
+ ( Sendgrid_Tools::get_auth_method() == "username" and
33
+ ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() ) ) ) {
34
  return;
35
  }
36
 
55
  */
56
  public static function add_statistics_menu()
57
  {
58
+ if ( ( Sendgrid_Tools::get_auth_method() == "apikey" and ! Sendgrid_Tools::check_api_key( Sendgrid_Tools::get_api_key() ) ) or
59
+ ( Sendgrid_Tools::get_auth_method() == "username" and
60
+ ! Sendgrid_Tools::check_username_password( Sendgrid_Tools::get_username(), Sendgrid_Tools::get_password() ) ) ) {
61
  return;
62
  }
63
 
72
  */
73
  public static function show_statistics_page()
74
  {
75
+ $api_key = Sendgrid_Tools::get_api_key();
76
+
77
+ if ( ( "apikey" == Sendgrid_Tools::get_auth_method() ) and isset( $api_key ) and ! Sendgrid_Tools::check_api_key_stats( $api_key ) )
78
+ {
79
+ $message = 'Your Api key is not having statistics permissions';
80
+ $status = 'error';
81
+ }
82
+
83
  require plugin_dir_path( __FILE__ ) . '../view/sendgrid_stats.php';
84
  }
85
 
129
 
130
  $parameters['api_user'] = Sendgrid_Tools::get_username();
131
  $parameters['api_key'] = Sendgrid_Tools::get_password();
132
+
133
+ $api_key = Sendgrid_Tools::get_api_key();
134
+ if ( "apikey" == Sendgrid_Tools::get_auth_method() )
135
+ {
136
+ $parameters['apikey'] = $api_key;
137
+ }
138
+
139
 
140
  $parameters['data_type'] = 'global';
141
 
lib/class-sendgrid-tools.php CHANGED
@@ -63,6 +63,36 @@ class Sendgrid_Tools
63
  return true;
64
  }
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  /**
67
  * Check template
68
  *
@@ -104,7 +134,7 @@ class Sendgrid_Tools
104
  public static function curl_request( $api = 'v3/stats', $parameters = array() )
105
  {
106
  $args = array();
107
- if ( ! $parameters['apikey'] ) {
108
  $creds = base64_encode($parameters['api_user'] . ':' . $parameters['api_key']);
109
 
110
  $args = array(
63
  return true;
64
  }
65
 
66
+ /**
67
+ * Check api_key stats permissions
68
+ *
69
+ * @param string $api_key sendgrid api_key
70
+ * @return bool
71
+ */
72
+ public static function check_api_key_stats( $api_key )
73
+ {
74
+ $url = 'https://api.sendgrid.com/v3/stats';
75
+
76
+ $args = array(
77
+ 'headers' => array(
78
+ 'Authorization' => 'Bearer ' . $api_key )
79
+ );
80
+
81
+ $response = wp_remote_get( $url, $args );
82
+
83
+ if ( ! is_array( $response ) or ! isset( $response['body'] ) ) {
84
+ return false;
85
+ }
86
+
87
+ $response = json_decode( $response['body'], true );
88
+
89
+ if ( isset( $response['errors'] ) and ( 'access forbidden' == $response['errors'][0]['message'] ) ) {
90
+ return false;
91
+ }
92
+
93
+ return true;
94
+ }
95
+
96
  /**
97
  * Check template
98
  *
134
  public static function curl_request( $api = 'v3/stats', $parameters = array() )
135
  {
136
  $args = array();
137
+ if ( ! isset( $parameters['apikey'] ) ) {
138
  $creds = base64_encode($parameters['api_user'] . ':' . $parameters['api_key']);
139
 
140
  $args = array(
lib/overwrite-sendgrid-methods.php CHANGED
@@ -283,6 +283,13 @@ if ( ! function_exists('wp_mail'))
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 );
283
  $mail->setTemplateId( Sendgrid_Tools::get_template() );
284
  }
285
  break;
286
+ case 'categories':
287
+ $categories = explode( ',', trim( $content ) );
288
+ foreach ( $categories as $category )
289
+ {
290
+ $mail->addCategory( $category );
291
+ }
292
+ break;
293
  default:
294
  // Add it to our grand headers array
295
  $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.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -62,6 +62,7 @@ $headers[] = 'From: Me Myself <me@example.net>';
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');
@@ -130,6 +131,8 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
130
 
131
  == Changelog ==
132
 
 
 
133
  = 1.6.8 =
134
  * Update api_key validation
135
  = 1.6.7 =
@@ -195,6 +198,8 @@ Create a SendGrid account at <a href="http://sendgrid.com/partner/wordpress" tar
195
 
196
  == Upgrade notice ==
197
 
 
 
198
  = 1.6.8 =
199
  * Update api_key validation
200
  = 1.6.7 =
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.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
62
  $headers[] = 'Cc: address4@sendgrid.com';
63
  $headers[] = 'Bcc: address5@sendgrid.com';
64
  $headers[] = 'unique-args:customer=mycustomer;location=mylocation'
65
+ $headers[] = 'categories: category1, category2'
66
  $headers[] = 'template: templateID'
67
 
68
  $attachments = array('/tmp/img1.jpg', '/tmp/img2.jpg');
131
 
132
  == Changelog ==
133
 
134
+ = 1.6.9 =
135
+ * Add categories in headers, add errror message on statistics page if API key is not having permissions
136
  = 1.6.8 =
137
  * Update api_key validation
138
  = 1.6.7 =
198
 
199
  == Upgrade notice ==
200
 
201
+ = 1.6.9 =
202
+ * Add categories in headers, add errror message on statistics page if API key is not having permissions
203
  = 1.6.8 =
204
  * Update api_key validation
205
  = 1.6.7 =
view/css/sendgrid.css CHANGED
@@ -378,4 +378,8 @@
378
 
379
  .creds {
380
  display: none;
 
 
 
 
381
  }
378
 
379
  .creds {
380
  display: none;
381
+ }
382
+
383
+ #sendgrid-statistics-page .error {
384
+ width: 1660px;
385
  }
view/sendgrid_stats.php CHANGED
@@ -3,6 +3,13 @@
3
  <div id="icon-sendgrid" class="icon32"><br></div>
4
  <h2 id="sendgrid-wordpress-statistics-header" class="sendgrid-statistics-header-toggle">SendGrid Wordpress Statistics</h2>
5
  <h2 id="sendgrid-general-statistics-header" class="sendgrid-statistics-header-toggle" style="display: none;">SendGrid General Statistics</h2>
 
 
 
 
 
 
 
6
  <a href="https://app.sendgrid.com/statistics" target="_blank" class="more-statistics">SendGrid Portal</a>
7
  </div>
8
  <div class="pull-right sendgrid-statistics-change-type">
3
  <div id="icon-sendgrid" class="icon32"><br></div>
4
  <h2 id="sendgrid-wordpress-statistics-header" class="sendgrid-statistics-header-toggle">SendGrid Wordpress Statistics</h2>
5
  <h2 id="sendgrid-general-statistics-header" class="sendgrid-statistics-header-toggle" style="display: none;">SendGrid General Statistics</h2>
6
+ <?php if ( isset( $status ) and ( 'error' == $status ) ): ?>
7
+ <div id="message" class="<?php echo $status ?>">
8
+ <p>
9
+ <strong><?php echo $message ?></strong>
10
+ </p>
11
+ </div>
12
+ <?php endif; ?>
13
  <a href="https://app.sendgrid.com/statistics" target="_blank" class="more-statistics">SendGrid Portal</a>
14
  </div>
15
  <div class="pull-right sendgrid-statistics-change-type">
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.8
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.6.9
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified