SendGrid - Version 1.10.5

Version Description

  • Added settings page on multisite to give access to self manage SendGrid plugin to each subsite
Download this release

Release Info

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

Code changes from version 1.10.3 to 1.10.5

lib/class-sendgrid-mc-optin.php CHANGED
@@ -60,7 +60,7 @@ class Sendgrid_OptIn_API_Endpoint{
60
  exit();
61
  }
62
 
63
- $transient = ( is_multisite() ? get_site_transient( $token ) : get_transient( $token ) );
64
 
65
  if ( ! $transient or
66
  ! is_array( $transient ) or
@@ -83,9 +83,9 @@ class Sendgrid_OptIn_API_Endpoint{
83
 
84
  if ( $page == false ) {
85
  if ( is_multisite() ) {
86
- set_site_transient( $token, null );
87
  } else {
88
- set_transient( $token, null );
89
  }
90
  wp_redirect( 'sg-subscription-success' );
91
  exit();
@@ -131,28 +131,28 @@ class Sendgrid_OptIn_API_Endpoint{
131
 
132
  $token = Sendgrid_OptIn_API_Endpoint::generate_email_token( $email, $first_name, $last_name );
133
 
134
- $transient = ( is_multisite() ? get_site_transient($token) : get_transient($token) );
135
 
136
  if ( $transient and isset( $transient['email'] ) and ! $from_settings ) {
137
  return false;
138
  }
139
 
140
  if ( is_multisite() ) {
141
- if ( false == set_site_transient( $token,
142
  array(
143
  'email' => $email,
144
  'first_name' => $first_name,
145
  'last_name' => $last_name ),
146
- 24 * 60 * 60 ) and ! $from_settings and $transient ) {
147
- return false;
148
  }
149
- } elseif ( false == set_transient( $token,
150
- array(
151
- 'email' => $email,
152
- 'first_name' => $first_name,
153
- 'last_name' => $last_name ),
154
  24 * 60 * 60 ) and ! $from_settings and $transient ) {
155
- return false;
156
  }
157
 
158
  $confirmation_link = site_url() . '/?__sg_api=1&token=' . $token;
@@ -191,10 +191,10 @@ function register_shortcode_first_name($atts)
191
  }
192
 
193
  $token = $_GET['sg_token'];
194
- $transient = get_transient( $token );
195
 
196
  if ( is_multisite() ) {
197
- $transient = get_site_transient( $token );
198
  }
199
 
200
  if ( ! $transient ||
@@ -221,10 +221,10 @@ function register_shortcode_last_name($atts)
221
  }
222
 
223
  $token = $_GET['sg_token'];
224
- $transient = get_transient( $token );
225
 
226
  if ( is_multisite() ) {
227
- $transient = get_site_transient( $token );
228
  }
229
 
230
  if ( ! $transient or
@@ -251,10 +251,10 @@ function register_shortcode_email($atts)
251
  }
252
 
253
  $token = $_GET['sg_token'];
254
- $transient = get_transient( $token );
255
 
256
  if ( is_multisite() ) {
257
- $transient = get_site_transient( $token );
258
  }
259
 
260
  if ( ! $transient or
@@ -285,17 +285,17 @@ function sg_invalidate_token() {
285
  }
286
 
287
  $token = $_GET['sg_token'];
288
- $transient = get_transient( $token );
289
 
290
  if ( is_multisite() ) {
291
- $transient = get_site_transient( $token );
292
  }
293
 
294
  if ( $token and $transient ) {
295
  if ( is_multisite() ) {
296
- set_site_transient( $token, null );
297
  } else {
298
- set_transient( $token, null );
299
  }
300
  }
301
  }
60
  exit();
61
  }
62
 
63
+ $transient = ( is_multisite() ? Sendgrid_Tools::get_site_transient_sendgrid( $token ) : Sendgrid_Tools::get_transient_sendgrid( $token ) );
64
 
65
  if ( ! $transient or
66
  ! is_array( $transient ) or
83
 
84
  if ( $page == false ) {
85
  if ( is_multisite() ) {
86
+ Sendgrid_Tools::set_site_transient_sendgrid( $token, null );
87
  } else {
88
+ Sendgrid_Tools::set_transient_sendgrid( $token, null );
89
  }
90
  wp_redirect( 'sg-subscription-success' );
91
  exit();
131
 
132
  $token = Sendgrid_OptIn_API_Endpoint::generate_email_token( $email, $first_name, $last_name );
133
 
134
+ $transient = ( is_multisite() ? Sendgrid_Tools::get_site_transient_sendgrid( $token ) : Sendgrid_Tools::get_transient_sendgrid( $token ) );
135
 
136
  if ( $transient and isset( $transient['email'] ) and ! $from_settings ) {
137
  return false;
138
  }
139
 
140
  if ( is_multisite() ) {
141
+ if ( false == Sendgrid_Tools::set_site_transient_sendgrid( $token,
142
  array(
143
  'email' => $email,
144
  'first_name' => $first_name,
145
  'last_name' => $last_name ),
146
+ 24 * 60 * 60 ) and ! $from_settings and $transient ) {
147
+ return false;
148
  }
149
+ } elseif ( false == Sendgrid_Tools::set_transient_sendgrid( $token,
150
+ array(
151
+ 'email' => $email,
152
+ 'first_name' => $first_name,
153
+ 'last_name' => $last_name ),
154
  24 * 60 * 60 ) and ! $from_settings and $transient ) {
155
+ return false;
156
  }
157
 
158
  $confirmation_link = site_url() . '/?__sg_api=1&token=' . $token;
191
  }
192
 
193
  $token = $_GET['sg_token'];
194
+ $transient = Sendgrid_Tools::get_transient_sendgrid( $token );
195
 
196
  if ( is_multisite() ) {
197
+ $transient = Sendgrid_Tools::get_site_transient_sendgrid( $token );
198
  }
199
 
200
  if ( ! $transient ||
221
  }
222
 
223
  $token = $_GET['sg_token'];
224
+ $transient = Sendgrid_Tools::get_transient_sendgrid( $token );
225
 
226
  if ( is_multisite() ) {
227
+ $transient = Sendgrid_Tools::get_site_transient_sendgrid( $token );
228
  }
229
 
230
  if ( ! $transient or
251
  }
252
 
253
  $token = $_GET['sg_token'];
254
+ $transient = Sendgrid_Tools::get_transient_sendgrid( $token );
255
 
256
  if ( is_multisite() ) {
257
+ $transient = Sendgrid_Tools::get_site_transient_sendgrid( $token );
258
  }
259
 
260
  if ( ! $transient or
285
  }
286
 
287
  $token = $_GET['sg_token'];
288
+ $transient = Sendgrid_Tools::get_transient_sendgrid( $token );
289
 
290
  if ( is_multisite() ) {
291
+ $transient = Sendgrid_Tools::get_site_transient_sendgrid( $token );
292
  }
293
 
294
  if ( $token and $transient ) {
295
  if ( is_multisite() ) {
296
+ Sendgrid_Tools::set_site_transient_sendgrid( $token, null );
297
  } else {
298
+ Sendgrid_Tools::set_transient_sendgrid( $token, null );
299
  }
300
  }
301
  }
lib/class-sendgrid-settings.php CHANGED
@@ -37,25 +37,20 @@ class Sendgrid_Settings {
37
  */
38
  public static function set_up_menu()
39
  {
40
- if ( ! is_multisite() and current_user_can('manage_options') ) {
41
  // Add SendGrid settings page in the menu
42
  add_action( 'admin_menu', array( __CLASS__, 'add_settings_menu' ) );
43
  // Add SendGrid settings page in the plugin list
44
  add_filter( 'plugin_action_links_' . self::$plugin_directory, array( __CLASS__, 'add_settings_link' ) );
45
- // Add SendGrid Help contextual menu in the settings page
46
- add_filter( 'contextual_help', array( __CLASS__, 'show_contextual_help' ), 10, 3 );
47
- // Add SendGrid javascripts in header
48
- add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
49
- } elseif ( is_multisite() and is_super_admin() ) {
50
  // Add SendGrid settings page in the network admin menu
51
  add_action( 'network_admin_menu', array( __CLASS__, 'add_network_settings_menu' ) );
52
- // Add SendGrid Help contextual menu in the settings page
53
- add_filter( 'contextual_help', array( __CLASS__, 'show_contextual_help' ), 10, 3 );
54
- // Add SendGrid javascripts in header
55
- add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
56
  }
 
 
 
 
57
  }
58
-
59
  /**
60
  * Add SendGrid settings page in the menu
61
  *
@@ -376,21 +371,43 @@ class Sendgrid_Settings {
376
  * @return mixed response array from the save or send functions
377
  */
378
  private static function do_post( $params ) {
379
- if ( isset($params['mc_settings'] ) and $params['mc_settings'] ) {
380
  return self::save_mc_settings( $params );
381
  }
382
 
383
- if ( isset($params['email_test'] ) and $params['email_test'] ) {
384
  return self::send_test_email( $params );
385
  }
386
 
387
- if ( isset($params['contact_upload_test'] ) and $params['contact_upload_test'] ) {
388
  return self::send_contact_upload_test( $params );
389
  }
390
 
 
 
 
 
391
  return self::save_general_settings( $params );
392
  }
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  /**
395
  * Saves the Marketing Campaigns parameters sent from the settings page
396
  *
37
  */
38
  public static function set_up_menu()
39
  {
40
+ if ( ( ! is_multisite() and current_user_can('manage_options') ) || ( is_multisite() and ! is_main_site() and get_option( 'sendgrid_can_manage_subsite' ) ) ) {
41
  // Add SendGrid settings page in the menu
42
  add_action( 'admin_menu', array( __CLASS__, 'add_settings_menu' ) );
43
  // Add SendGrid settings page in the plugin list
44
  add_filter( 'plugin_action_links_' . self::$plugin_directory, array( __CLASS__, 'add_settings_link' ) );
45
+ } elseif ( is_multisite() and is_main_site() ) {
 
 
 
 
46
  // Add SendGrid settings page in the network admin menu
47
  add_action( 'network_admin_menu', array( __CLASS__, 'add_network_settings_menu' ) );
 
 
 
 
48
  }
49
+ // Add SendGrid Help contextual menu in the settings page
50
+ add_filter( 'contextual_help', array( __CLASS__, 'show_contextual_help' ), 10, 3 );
51
+ // Add SendGrid javascripts in header
52
+ add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
53
  }
 
54
  /**
55
  * Add SendGrid settings page in the menu
56
  *
371
  * @return mixed response array from the save or send functions
372
  */
373
  private static function do_post( $params ) {
374
+ if ( isset( $params['mc_settings'] ) and $params['mc_settings'] ) {
375
  return self::save_mc_settings( $params );
376
  }
377
 
378
+ if ( isset( $params['email_test'] ) and $params['email_test'] ) {
379
  return self::send_test_email( $params );
380
  }
381
 
382
+ if ( isset( $params['contact_upload_test'] ) and $params['contact_upload_test'] ) {
383
  return self::send_contact_upload_test( $params );
384
  }
385
 
386
+ if ( isset( $params['subsite_settings'] ) and $params['subsite_settings'] ) {
387
+ return self::save_subsite_settings( $params );
388
+ }
389
+
390
  return self::save_general_settings( $params );
391
  }
392
 
393
+ /**
394
+ * Saves the Subsite settings sent from the settings page
395
+ *
396
+ * @param mixed $params array of parameters from $_POST
397
+ *
398
+ * @return mixed response array with message and status
399
+ */
400
+ private static function save_subsite_settings( $params ) {
401
+ $sites = get_sites();
402
+ foreach( $sites as $site ) {
403
+ if ( isset( $params['checked_sites'][$site->blog_id] ) and 'on' == $params['checked_sites'][$site->blog_id] ) {
404
+ update_blog_option( $site->blog_id, 'sendgrid_can_manage_subsite', 1 );
405
+ } else {
406
+ update_blog_option( $site->blog_id, 'sendgrid_can_manage_subsite', 0 );
407
+ }
408
+ }
409
+ }
410
+
411
  /**
412
  * Saves the Marketing Campaigns parameters sent from the settings page
413
  *
lib/class-sendgrid-statistics.php CHANGED
@@ -16,7 +16,7 @@ class Sendgrid_Statistics
16
  */
17
  public static function set_up_menu()
18
  {
19
- if ( ! is_multisite() and current_user_can('manage_options') ) {
20
  // Add SendGrid widget in dashboard
21
  add_action( 'wp_dashboard_setup', array( __CLASS__, 'add_dashboard_widget' ) );
22
 
@@ -28,10 +28,10 @@ class Sendgrid_Statistics
28
 
29
  // Add SendGrid page for get statistics through ajax
30
  add_action( 'wp_ajax_sendgrid_get_stats', array( __CLASS__, 'get_ajax_statistics' ) );
31
- } elseif ( is_multisite() and is_super_admin() ) {
32
  // Add SendGrid stats page in menu
33
  add_action( 'network_admin_menu', array( __CLASS__, 'add_network_statistics_menu' ) );
34
-
35
  // Add SendGrid javascripts in header
36
  add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
37
 
16
  */
17
  public static function set_up_menu()
18
  {
19
+ if ( ( ! is_multisite() and current_user_can('manage_options') ) || ( is_multisite() and ! is_main_site() and get_option( 'sendgrid_can_manage_subsite' ) ) ) {
20
  // Add SendGrid widget in dashboard
21
  add_action( 'wp_dashboard_setup', array( __CLASS__, 'add_dashboard_widget' ) );
22
 
28
 
29
  // Add SendGrid page for get statistics through ajax
30
  add_action( 'wp_ajax_sendgrid_get_stats', array( __CLASS__, 'get_ajax_statistics' ) );
31
+ } elseif ( is_multisite() and is_main_site() ) {
32
  // Add SendGrid stats page in menu
33
  add_action( 'network_admin_menu', array( __CLASS__, 'add_network_statistics_menu' ) );
34
+
35
  // Add SendGrid javascripts in header
36
  add_action( 'admin_enqueue_scripts', array( __CLASS__, 'add_headers' ) );
37
 
lib/class-sendgrid-tools.php CHANGED
@@ -12,6 +12,45 @@ class Sendgrid_Tools
12
  public static $allowed_auth_methods = array( 'apikey', 'credentials' );
13
  public static $allowed_content_type = array( 'plaintext', 'html' );
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  /**
16
  * Check username/password
17
  *
@@ -249,16 +288,14 @@ class Sendgrid_Tools
249
  {
250
  if ( defined( 'SENDGRID_USERNAME' ) ) {
251
  return SENDGRID_USERNAME;
252
- } elseif ( is_multisite() ) {
253
- return get_site_option( 'sendgrid_username' );
254
  } else {
255
- $username = get_option( 'sendgrid_user' );
256
  if( $username ) {
257
- delete_option( 'sendgrid_user' );
258
- update_option( 'sendgrid_username', $username );
259
  }
260
 
261
- return get_option( 'sendgrid_username' );
262
  }
263
  }
264
 
@@ -271,19 +308,11 @@ class Sendgrid_Tools
271
  */
272
  public static function set_username( $username )
273
  {
274
- if ( is_multisite() ) {
275
- if( ! isset( $username ) ) {
276
- return update_site_option( 'sendgrid_username', '' );
277
- }
278
-
279
- return update_site_option( 'sendgrid_username', $username );
280
- } else {
281
- if ( ! isset( $username ) ) {
282
- return update_option( 'sendgrid_username', '' );
283
- }
284
-
285
- return update_option( 'sendgrid_username', $username );
286
  }
 
 
287
  }
288
 
289
  /**
@@ -295,18 +324,15 @@ class Sendgrid_Tools
295
  {
296
  if ( defined( 'SENDGRID_PASSWORD' ) ) {
297
  return SENDGRID_PASSWORD;
298
- } elseif ( is_multisite() ) {
299
- return get_site_option( 'sendgrid_pwd' );
300
  } else {
301
- $password = get_option( 'sendgrid_pwd' );
302
- $new_password = get_option( 'sendgrid_password' );
303
  if ( $new_password and ! $password ) {
304
- update_option( 'sendgrid_pwd', self::decrypt( $new_password, AUTH_KEY ) );
305
- delete_option( 'sendgrid_password' );
306
  }
307
 
308
- $password = get_option( 'sendgrid_pwd' );
309
- return $password;
310
  }
311
  }
312
 
@@ -319,11 +345,7 @@ class Sendgrid_Tools
319
  */
320
  public static function set_password( $password )
321
  {
322
- if ( is_multisite() ) {
323
- return update_site_option( 'sendgrid_pwd', $password );
324
- } else {
325
- return update_option( 'sendgrid_pwd', $password );
326
- }
327
  }
328
 
329
  /**
@@ -335,17 +357,15 @@ class Sendgrid_Tools
335
  {
336
  if ( defined( 'SENDGRID_API_KEY' ) ) {
337
  return SENDGRID_API_KEY;
338
- } elseif ( is_multisite() ) {
339
- return get_site_option( 'sendgrid_api_key' );
340
  } else {
341
- $apikey = get_option( 'sendgrid_api_key' );
342
- $new_apikey = get_option( 'sendgrid_apikey' );
343
  if ( $new_apikey and ! $apikey ) {
344
- update_option( 'sendgrid_api_key', self::decrypt( $new_apikey, AUTH_KEY ) );
345
- delete_option( 'sendgrid_apikey' );
346
  }
347
 
348
- $apikey = get_option( 'sendgrid_api_key' );
349
  return $apikey;
350
  }
351
  }
@@ -359,10 +379,8 @@ class Sendgrid_Tools
359
  {
360
  if ( defined( 'SENDGRID_MC_API_KEY' ) ) {
361
  return SENDGRID_MC_API_KEY;
362
- } elseif ( is_multisite() ) {
363
- return get_site_option( 'sendgrid_mc_api_key' );
364
  } else {
365
- return get_option( 'sendgrid_mc_api_key' );
366
  }
367
  }
368
 
@@ -375,10 +393,8 @@ class Sendgrid_Tools
375
  {
376
  if ( defined( 'SENDGRID_MC_LIST_ID' ) ) {
377
  return SENDGRID_MC_LIST_ID;
378
- } elseif ( is_multisite() ) {
379
- return get_site_option( 'sendgrid_mc_list_id' );
380
  } else {
381
- return get_option( 'sendgrid_mc_list_id' );
382
  }
383
  }
384
 
@@ -391,10 +407,8 @@ class Sendgrid_Tools
391
  {
392
  if ( defined( 'SENDGRID_MC_OPT_USE_TRANSACTIONAL' ) ) {
393
  return SENDGRID_MC_OPT_USE_TRANSACTIONAL;
394
- } elseif ( is_multisite() ) {
395
- return get_site_option( 'sendgrid_mc_opt_use_transactional' );
396
  } else {
397
- return get_option( 'sendgrid_mc_opt_use_transactional' );
398
  }
399
  }
400
 
@@ -407,10 +421,8 @@ class Sendgrid_Tools
407
  {
408
  if ( defined( 'SENDGRID_MC_OPT_REQ_FNAME_LNAME' ) ) {
409
  return SENDGRID_MC_OPT_REQ_FNAME_LNAME;
410
- } elseif ( is_multisite() ) {
411
- return get_site_option( 'sendgrid_mc_opt_req_fname_lname' );
412
  } else {
413
- return get_option( 'sendgrid_mc_opt_req_fname_lname' );
414
  }
415
  }
416
 
@@ -423,10 +435,8 @@ class Sendgrid_Tools
423
  {
424
  if ( defined( 'SENDGRID_MC_OPT_INCL_FNAME_LNAME' ) ) {
425
  return SENDGRID_MC_OPT_INCL_FNAME_LNAME;
426
- } elseif ( is_multisite() ) {
427
- return get_site_option( 'sendgrid_mc_opt_incl_fname_lname' );
428
  } else {
429
- return get_option( 'sendgrid_mc_opt_incl_fname_lname' );
430
  }
431
  }
432
 
@@ -439,10 +449,8 @@ class Sendgrid_Tools
439
  {
440
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_SUBJECT' ) ) {
441
  return SENDGRID_MC_SIGNUP_EMAIL_SUBJECT;
442
- } elseif ( is_multisite() ) {
443
- return get_site_option( 'sendgrid_mc_signup_email_subject' );
444
  } else {
445
- return get_option( 'sendgrid_mc_signup_email_subject' );
446
  }
447
  }
448
 
@@ -455,10 +463,8 @@ class Sendgrid_Tools
455
  {
456
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_CONTENT' ) ) {
457
  return SENDGRID_MC_SIGNUP_EMAIL_CONTENT;
458
- } elseif ( is_multisite() ) {
459
- return get_site_option( 'sendgrid_mc_signup_email_content' );
460
  } else {
461
- return get_option( 'sendgrid_mc_signup_email_content' );
462
  }
463
  }
464
 
@@ -471,10 +477,8 @@ class Sendgrid_Tools
471
  {
472
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_CONTENT_TEXT' ) ) {
473
  return SENDGRID_MC_SIGNUP_EMAIL_CONTENT_TEXT;
474
- } elseif ( is_multisite() ) {
475
- return get_site_option( 'sendgrid_mc_signup_email_content_text' );
476
  } else {
477
- return get_option( 'sendgrid_mc_signup_email_content_text' );
478
  }
479
  }
480
 
@@ -487,10 +491,8 @@ class Sendgrid_Tools
487
  {
488
  if ( defined( 'SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE' ) ) {
489
  return SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE;
490
- } elseif ( is_multisite() ) {
491
- return get_site_option( 'sendgrid_mc_signup_confirmation_page' );
492
  } else {
493
- return get_option( 'sendgrid_mc_signup_confirmation_page' );
494
  }
495
  }
496
 
@@ -523,11 +525,7 @@ class Sendgrid_Tools
523
  */
524
  public static function get_mc_auth_valid()
525
  {
526
- if ( is_multisite() ) {
527
- return get_site_option( 'sendgrid_mc_auth_valid' );
528
- } else {
529
- return get_option( 'sendgrid_mc_auth_valid' );
530
- }
531
  }
532
 
533
  /**
@@ -537,11 +535,7 @@ class Sendgrid_Tools
537
  */
538
  public static function get_mc_widget_notice_dismissed()
539
  {
540
- if ( is_multisite() ) {
541
- return get_site_option( 'sendgrid_mc_widget_notice_dismissed' );
542
- } else {
543
- return get_option( 'sendgrid_mc_widget_notice_dismissed' );
544
- }
545
  }
546
 
547
  /**
@@ -553,11 +547,7 @@ class Sendgrid_Tools
553
  */
554
  public static function set_api_key( $apikey )
555
  {
556
- if ( is_multisite() ) {
557
- return update_site_option( 'sendgrid_api_key', $apikey );
558
- } else {
559
- return update_option( 'sendgrid_api_key', $apikey );
560
- }
561
  }
562
 
563
  /**
@@ -569,11 +559,7 @@ class Sendgrid_Tools
569
  */
570
  public static function set_mc_api_key( $apikey )
571
  {
572
- if ( is_multisite() ) {
573
- return update_site_option( 'sendgrid_mc_api_key', $apikey );
574
- } else {
575
- return update_option( 'sendgrid_mc_api_key', $apikey );
576
- }
577
  }
578
 
579
  /**
@@ -585,11 +571,7 @@ class Sendgrid_Tools
585
  */
586
  public static function set_mc_list_id( $list_id )
587
  {
588
- if ( is_multisite() ) {
589
- return update_site_option( 'sendgrid_mc_list_id', $list_id );
590
- } else {
591
- return update_option( 'sendgrid_mc_list_id', $list_id );
592
- }
593
  }
594
 
595
  /**
@@ -601,11 +583,7 @@ class Sendgrid_Tools
601
  */
602
  public static function set_mc_opt_use_transactional( $use_transactional )
603
  {
604
- if ( is_multisite() ) {
605
- return update_site_option( 'sendgrid_mc_opt_use_transactional', $use_transactional );
606
- } else {
607
- return update_option( 'sendgrid_mc_opt_use_transactional', $use_transactional );
608
- }
609
  }
610
 
611
  /**
@@ -617,11 +595,7 @@ class Sendgrid_Tools
617
  */
618
  public static function set_mc_opt_req_fname_lname( $req_fname_lname )
619
  {
620
- if ( is_multisite() ) {
621
- return update_site_option( 'sendgrid_mc_opt_req_fname_lname', $req_fname_lname );
622
- } else {
623
- return update_option( 'sendgrid_mc_opt_req_fname_lname', $req_fname_lname );
624
- }
625
  }
626
 
627
  /**
@@ -633,11 +607,7 @@ class Sendgrid_Tools
633
  */
634
  public static function set_mc_opt_incl_fname_lname( $incl_fname_lname )
635
  {
636
- if ( is_multisite() ) {
637
- return update_site_option( 'sendgrid_mc_opt_incl_fname_lname', $incl_fname_lname );
638
- } else {
639
- return update_option( 'sendgrid_mc_opt_incl_fname_lname', $incl_fname_lname );
640
- }
641
  }
642
 
643
  /**
@@ -649,11 +619,7 @@ class Sendgrid_Tools
649
  */
650
  public static function set_mc_signup_email_subject( $email_subject )
651
  {
652
- if ( is_multisite() ) {
653
- return update_site_option( 'sendgrid_mc_signup_email_subject', $email_subject );
654
- } else {
655
- return update_option( 'sendgrid_mc_signup_email_subject', $email_subject );
656
- }
657
  }
658
 
659
  /**
@@ -665,11 +631,7 @@ class Sendgrid_Tools
665
  */
666
  public static function set_mc_signup_email_content( $email_content )
667
  {
668
- if ( is_multisite() ) {
669
- return update_site_option( 'sendgrid_mc_signup_email_content', $email_content );
670
- } else {
671
- return update_option( 'sendgrid_mc_signup_email_content', $email_content );
672
- }
673
  }
674
 
675
  /**
@@ -681,11 +643,7 @@ class Sendgrid_Tools
681
  */
682
  public static function set_mc_signup_email_content_text( $email_content )
683
  {
684
- if ( is_multisite() ) {
685
- return update_site_option( 'sendgrid_mc_signup_email_content_text', $email_content );
686
- } else {
687
- return update_option( 'sendgrid_mc_signup_email_content_text', $email_content );
688
- }
689
  }
690
 
691
  /**
@@ -697,11 +655,7 @@ class Sendgrid_Tools
697
  */
698
  public static function set_mc_signup_confirmation_page( $confirmation_page )
699
  {
700
- if ( is_multisite() ) {
701
- return update_site_option( 'sendgrid_mc_signup_confirmation_page', $confirmation_page );
702
- } else {
703
- return update_option( 'sendgrid_mc_signup_confirmation_page', $confirmation_page );
704
- }
705
  }
706
 
707
  /**
@@ -713,11 +667,7 @@ class Sendgrid_Tools
713
  */
714
  public static function set_mc_auth_valid( $auth_valid )
715
  {
716
- if ( is_multisite() ) {
717
- return update_site_option( 'sendgrid_mc_auth_valid', $auth_valid );
718
- } else {
719
- return update_option( 'sendgrid_mc_auth_valid', $auth_valid );
720
- }
721
  }
722
 
723
  /**
@@ -729,11 +679,7 @@ class Sendgrid_Tools
729
  */
730
  public static function set_mc_widget_notice_dismissed( $notice_dismissed )
731
  {
732
- if ( is_multisite() ) {
733
- return update_site_option( 'sendgrid_mc_widget_notice_dismissed', $notice_dismissed );
734
- } else {
735
- return update_option( 'sendgrid_mc_widget_notice_dismissed', $notice_dismissed );
736
- }
737
  }
738
 
739
  /**
@@ -745,10 +691,8 @@ class Sendgrid_Tools
745
  {
746
  if ( defined( 'SENDGRID_SEND_METHOD' ) ) {
747
  return SENDGRID_SEND_METHOD;
748
- } elseif ( is_multisite() and get_site_option( 'sendgrid_api' ) ) {
749
- return get_site_option( 'sendgrid_api' );
750
- } elseif ( get_option( 'sendgrid_api' ) ) {
751
- return get_option( 'sendgrid_api' );
752
  } else {
753
  return 'api';
754
  }
@@ -763,11 +707,7 @@ class Sendgrid_Tools
763
  */
764
  public static function set_send_method( $method )
765
  {
766
- if ( is_multisite() ) {
767
- return update_site_option( 'sendgrid_api', $method );
768
- } else {
769
- return update_option( 'sendgrid_api', $method );
770
- }
771
  }
772
 
773
  /**
@@ -779,13 +719,11 @@ class Sendgrid_Tools
779
  {
780
  if ( defined( 'SENDGRID_AUTH_METHOD' ) ) {
781
  return SENDGRID_AUTH_METHOD;
782
- } elseif ( is_multisite() and get_site_option( 'sendgrid_auth_method' ) ) {
783
- return get_site_option( 'sendgrid_auth_method' );
784
- } elseif ( get_option( 'sendgrid_auth_method' ) ) {
785
- $auth_method = get_option( 'sendgrid_auth_method' );
786
  if ( 'username' == $auth_method ) {
787
  $auth_method = 'credentials';
788
- update_option( 'sendgrid_auth_method', $auth_method );
789
  }
790
 
791
  return $auth_method;
@@ -807,11 +745,7 @@ class Sendgrid_Tools
807
  */
808
  public static function set_auth_method( $method )
809
  {
810
- if ( is_multisite() ) {
811
- return update_site_option( 'sendgrid_auth_method', $method );
812
- } else {
813
- return update_option( 'sendgrid_auth_method', $method );
814
- }
815
  }
816
 
817
  /**
@@ -823,10 +757,8 @@ class Sendgrid_Tools
823
  {
824
  if ( defined( 'SENDGRID_PORT' ) ) {
825
  return SENDGRID_PORT;
826
- } elseif ( is_multisite() ) {
827
- return get_site_option( 'sendgrid_port', Sendgrid_SMTP::TLS );
828
  } else {
829
- return get_option( 'sendgrid_port', Sendgrid_SMTP::TLS );
830
  }
831
  }
832
 
@@ -839,11 +771,7 @@ class Sendgrid_Tools
839
  */
840
  public static function set_port( $port )
841
  {
842
- if ( is_multisite() ) {
843
- return update_site_option( 'sendgrid_port', $port );
844
- } else {
845
- return update_option( 'sendgrid_port', $port );
846
- }
847
  }
848
 
849
  /**
@@ -855,10 +783,8 @@ class Sendgrid_Tools
855
  {
856
  if ( defined( 'SENDGRID_FROM_NAME' ) ) {
857
  return SENDGRID_FROM_NAME;
858
- } elseif ( is_multisite() ) {
859
- return get_site_option( 'sendgrid_from_name' );
860
  } else {
861
- return get_option( 'sendgrid_from_name' );
862
  }
863
  }
864
 
@@ -871,11 +797,7 @@ class Sendgrid_Tools
871
  */
872
  public static function set_from_name( $name )
873
  {
874
- if ( is_multisite() ) {
875
- return update_site_option( 'sendgrid_from_name', $name );
876
- } else {
877
- return update_option( 'sendgrid_from_name', $name );
878
- }
879
  }
880
 
881
  /**
@@ -887,10 +809,8 @@ class Sendgrid_Tools
887
  {
888
  if ( defined( 'SENDGRID_FROM_EMAIL' ) ) {
889
  return SENDGRID_FROM_EMAIL;
890
- } elseif ( is_multisite() ) {
891
- return get_site_option( 'sendgrid_from_email' );
892
  } else {
893
- return get_option( 'sendgrid_from_email' );
894
  }
895
  }
896
 
@@ -903,11 +823,7 @@ class Sendgrid_Tools
903
  */
904
  public static function set_from_email( $email )
905
  {
906
- if ( is_multisite() ) {
907
- return update_site_option( 'sendgrid_from_email', $email );
908
- } else {
909
- return update_option( 'sendgrid_from_email', $email );
910
- }
911
  }
912
 
913
  /**
@@ -919,10 +835,8 @@ class Sendgrid_Tools
919
  {
920
  if ( defined( 'SENDGRID_REPLY_TO' ) ) {
921
  return SENDGRID_REPLY_TO;
922
- } elseif ( is_multisite() ) {
923
- return get_site_option( 'sendgrid_reply_to' );
924
  } else {
925
- return get_option( 'sendgrid_reply_to' );
926
  }
927
  }
928
 
@@ -935,11 +849,7 @@ class Sendgrid_Tools
935
  */
936
  public static function set_reply_to( $email )
937
  {
938
- if ( is_multisite() ) {
939
- return update_site_option( 'sendgrid_reply_to', $email );
940
- } else {
941
- return update_option( 'sendgrid_reply_to', $email );
942
- }
943
  }
944
 
945
  /**
@@ -951,10 +861,8 @@ class Sendgrid_Tools
951
  {
952
  if ( defined( 'SENDGRID_CATEGORIES' ) ) {
953
  return SENDGRID_CATEGORIES;
954
- } elseif ( is_multisite() ) {
955
- return get_site_option( 'sendgrid_categories' );
956
  } else {
957
- return get_option( 'sendgrid_categories' );
958
  }
959
  }
960
 
@@ -967,11 +875,7 @@ class Sendgrid_Tools
967
  */
968
  public static function set_categories( $categories )
969
  {
970
- if ( is_multisite() ) {
971
- return update_site_option( 'sendgrid_categories', $categories );
972
- } else {
973
- return update_option( 'sendgrid_categories', $categories );
974
- }
975
  }
976
 
977
  /**
@@ -983,10 +887,8 @@ class Sendgrid_Tools
983
  {
984
  if ( defined( 'SENDGRID_STATS_CATEGORIES' ) ) {
985
  return SENDGRID_STATS_CATEGORIES;
986
- } elseif ( is_multisite() ) {
987
- return get_site_option( 'sendgrid_stats_categories' );
988
  } else {
989
- return get_option( 'sendgrid_stats_categories' );
990
  }
991
  }
992
 
@@ -999,11 +901,7 @@ class Sendgrid_Tools
999
  */
1000
  public static function set_stats_categories( $categories )
1001
  {
1002
- if ( is_multisite() ) {
1003
- return update_site_option( 'sendgrid_stats_categories', $categories );
1004
- } else {
1005
- return update_option( 'sendgrid_stats_categories', $categories );
1006
- }
1007
  }
1008
 
1009
  /**
@@ -1029,10 +927,8 @@ class Sendgrid_Tools
1029
  {
1030
  if ( defined( 'SENDGRID_TEMPLATE' ) ) {
1031
  return SENDGRID_TEMPLATE;
1032
- } elseif ( is_multisite() ) {
1033
- return get_site_option( 'sendgrid_template' );
1034
  } else {
1035
- return get_option( 'sendgrid_template' );
1036
  }
1037
  }
1038
 
@@ -1045,11 +941,7 @@ class Sendgrid_Tools
1045
  */
1046
  public static function set_template( $template )
1047
  {
1048
- if ( is_multisite() ) {
1049
- return update_site_option( 'sendgrid_template', $template );
1050
- } else {
1051
- return update_option( 'sendgrid_template', $template );
1052
- }
1053
  }
1054
 
1055
  /**
@@ -1061,10 +953,8 @@ class Sendgrid_Tools
1061
  {
1062
  if ( defined( 'SENDGRID_CONTENT_TYPE' ) ) {
1063
  return SENDGRID_CONTENT_TYPE;
1064
- } elseif ( is_multisite() ) {
1065
- return get_site_option( 'sendgrid_content_type' );
1066
  } else {
1067
- return get_option( 'sendgrid_content_type' );
1068
  }
1069
  }
1070
 
@@ -1077,11 +967,7 @@ class Sendgrid_Tools
1077
  */
1078
  public static function set_unsubscribe_group( $unsubscribe_group )
1079
  {
1080
- if ( is_multisite() ) {
1081
- return update_site_option( 'sendgrid_unsubscribe_group', $unsubscribe_group );
1082
- } else {
1083
- return update_option( 'sendgrid_unsubscribe_group', $unsubscribe_group );
1084
- }
1085
  }
1086
 
1087
  /**
@@ -1093,10 +979,8 @@ class Sendgrid_Tools
1093
  {
1094
  if ( defined( 'SENDGRID_UNSUBSCRIBE_GROUP' ) ) {
1095
  return SENDGRID_UNSUBSCRIBE_GROUP;
1096
- } elseif ( is_multisite() ) {
1097
- return get_site_option( 'sendgrid_unsubscribe_group' );
1098
  } else {
1099
- return get_option( 'sendgrid_unsubscribe_group' );
1100
  }
1101
  }
1102
 
@@ -1109,11 +993,7 @@ class Sendgrid_Tools
1109
  */
1110
  public static function set_asm_permission( $permission )
1111
  {
1112
- if ( is_multisite() ) {
1113
- return update_site_option( 'sendgrid_asm_permission', $permission );
1114
- } else {
1115
- return update_option( 'sendgrid_asm_permission', $permission );
1116
- }
1117
  }
1118
 
1119
  /**
@@ -1123,11 +1003,7 @@ class Sendgrid_Tools
1123
  */
1124
  public static function get_asm_permission()
1125
  {
1126
- if ( is_multisite() ) {
1127
- return get_site_option( 'sendgrid_asm_permission' );
1128
- } else {
1129
- return get_option( 'sendgrid_asm_permission' );
1130
- }
1131
  }
1132
 
1133
  /**
@@ -1171,11 +1047,7 @@ class Sendgrid_Tools
1171
  */
1172
  public static function set_content_type( $content_type )
1173
  {
1174
- if ( is_multisite() ) {
1175
- return update_site_option( 'sendgrid_content_type', $content_type );
1176
- } else {
1177
- return update_option( 'sendgrid_content_type', $content_type );
1178
- }
1179
  }
1180
 
1181
  /**
@@ -1187,11 +1059,7 @@ class Sendgrid_Tools
1187
  */
1188
  public static function set_mc_email_label( $email_label )
1189
  {
1190
- if ( is_multisite() ) {
1191
- return update_site_option( 'sendgrid_mc_email_label', $email_label );
1192
- } else {
1193
- return update_option( 'sendgrid_mc_email_label', $email_label );
1194
- }
1195
  }
1196
 
1197
  /**
@@ -1203,10 +1071,8 @@ class Sendgrid_Tools
1203
  {
1204
  if ( defined( 'SENDGRID_MC_EMAIL_LABEL' ) ) {
1205
  return SENDGRID_MC_EMAIL_LABEL;
1206
- } elseif ( is_multisite() ) {
1207
- return get_site_option( 'sendgrid_mc_email_label' );
1208
  } else {
1209
- return get_option( 'sendgrid_mc_email_label' );
1210
  }
1211
  }
1212
 
@@ -1219,11 +1085,7 @@ class Sendgrid_Tools
1219
  */
1220
  public static function set_mc_first_name_label( $first_name_label )
1221
  {
1222
- if ( is_multisite() ) {
1223
- return update_site_option( 'sendgrid_mc_first_name_label', $first_name_label );
1224
- } else {
1225
- return update_option( 'sendgrid_mc_first_name_label', $first_name_label );
1226
- }
1227
  }
1228
 
1229
  /**
@@ -1235,10 +1097,8 @@ class Sendgrid_Tools
1235
  {
1236
  if ( defined( 'SENDGRID_MC_FIRST_NAME_LABEL' ) ) {
1237
  return SENDGRID_MC_FIRST_NAME_LABEL;
1238
- } elseif ( is_multisite() ) {
1239
- return get_site_option( 'sendgrid_mc_first_name_label' );
1240
  } else {
1241
- return get_option( 'sendgrid_mc_first_name_label' );
1242
  }
1243
  }
1244
 
@@ -1251,11 +1111,7 @@ class Sendgrid_Tools
1251
  */
1252
  public static function set_mc_last_name_label( $last_name_label )
1253
  {
1254
- if ( is_multisite() ) {
1255
- return update_site_option( 'sendgrid_mc_last_name_label', $last_name_label );
1256
- } else {
1257
- return update_option( 'sendgrid_mc_last_name_label', $last_name_label );
1258
- }
1259
  }
1260
 
1261
  /**
@@ -1267,10 +1123,8 @@ class Sendgrid_Tools
1267
  {
1268
  if ( defined( 'SENDGRID_MC_LAST_NAME_LABEL' ) ) {
1269
  return SENDGRID_MC_LAST_NAME_LABEL;
1270
- } elseif ( is_multisite() ) {
1271
- return get_site_option( 'sendgrid_mc_last_name_label' );
1272
  } else {
1273
- return get_option( 'sendgrid_mc_last_name_label' );
1274
  }
1275
  }
1276
 
@@ -1283,11 +1137,7 @@ class Sendgrid_Tools
1283
  */
1284
  public static function set_mc_subscribe_label( $subscribe_label )
1285
  {
1286
- if ( is_multisite() ) {
1287
- return update_site_option( 'sendgrid_mc_subscribe_label', $subscribe_label );
1288
- } else {
1289
- return update_option( 'sendgrid_mc_subscribe_label', $subscribe_label );
1290
- }
1291
  }
1292
 
1293
  /**
@@ -1299,10 +1149,8 @@ class Sendgrid_Tools
1299
  {
1300
  if ( defined( 'SENDGRID_MC_SUBSCRIBE_LABEL' ) ) {
1301
  return SENDGRID_MC_SUBSCRIBE_LABEL;
1302
- } elseif ( is_multisite() ) {
1303
- return get_site_option( 'sendgrid_mc_subscribe_label' );
1304
  } else {
1305
- return get_option( 'sendgrid_mc_subscribe_label' );
1306
  }
1307
  }
1308
 
@@ -1332,11 +1180,7 @@ class Sendgrid_Tools
1332
  // set the new value
1333
  $values[$position] = $value;
1334
 
1335
- if ( is_multisite() ) {
1336
- return update_site_option( 'sendgrid_mc_input_padding', json_encode( $values ) );
1337
- } else {
1338
- return update_option( 'sendgrid_mc_input_padding', json_encode( $values ) );
1339
- }
1340
  }
1341
 
1342
  /**
@@ -1346,11 +1190,7 @@ class Sendgrid_Tools
1346
  */
1347
  public static function get_mc_input_padding()
1348
  {
1349
- if ( is_multisite() ) {
1350
- return get_site_option( 'sendgrid_mc_input_padding' );
1351
- } else {
1352
- return get_option( 'sendgrid_mc_input_padding' );
1353
- }
1354
  }
1355
 
1356
  /**
@@ -1361,15 +1201,10 @@ class Sendgrid_Tools
1361
  */
1362
  public static function get_mc_input_padding_by_position( $position )
1363
  {
1364
- if ( is_multisite() ) {
1365
- $padding = get_site_option( 'sendgrid_mc_input_padding' );
1366
- } else {
1367
- $padding = get_option( 'sendgrid_mc_input_padding' );
1368
- }
1369
 
1370
  if ( false == $padding ) {
1371
- if ( $position == "top" )
1372
- {
1373
  return 10;
1374
  }
1375
 
@@ -1409,11 +1244,7 @@ class Sendgrid_Tools
1409
  // set the new value
1410
  $values[$position] = $value;
1411
 
1412
- if ( is_multisite() ) {
1413
- return update_site_option( 'sendgrid_mc_button_padding', json_encode( $values ) );
1414
- } else {
1415
- return update_option( 'sendgrid_mc_button_padding', json_encode( $values ) );
1416
- }
1417
  }
1418
 
1419
  /**
@@ -1423,11 +1254,7 @@ class Sendgrid_Tools
1423
  */
1424
  public static function get_mc_button_padding()
1425
  {
1426
- if ( is_multisite() ) {
1427
- return get_site_option( 'sendgrid_mc_button_padding' );
1428
- } else {
1429
- return get_option( 'sendgrid_mc_button_padding' );
1430
- }
1431
  }
1432
 
1433
  /**
@@ -1438,11 +1265,7 @@ class Sendgrid_Tools
1438
  */
1439
  public static function get_mc_button_padding_by_position( $position )
1440
  {
1441
- if ( is_multisite() ) {
1442
- $padding = get_site_option( 'sendgrid_mc_button_padding' );
1443
- } else {
1444
- $padding = get_option( 'sendgrid_mc_button_padding' );
1445
- }
1446
 
1447
  if ( false == $padding ) {
1448
  if ( $position == "top" )
@@ -1634,6 +1457,80 @@ class Sendgrid_Tools
1634
  {
1635
  return preg_replace('/<(https?:\/\/[^>]*)>/im', '$1', $content);
1636
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1637
  }
1638
 
1639
  /**
12
  public static $allowed_auth_methods = array( 'apikey', 'credentials' );
13
  public static $allowed_content_type = array( 'plaintext', 'html' );
14
 
15
+ /**
16
+ * Returns a sendgrid plugin option
17
+ *
18
+ * @return string
19
+ */
20
+ public static function get_sendgrid_option( $option, $default = false ) {
21
+ if ( ! is_multisite() || ( is_multisite() and ! is_main_site() and get_option( 'sendgrid_can_manage_subsite' ) ) ) {
22
+ return get_option( "sendgrid_$option", $default );
23
+ } else {
24
+ return get_site_option( "sendgrid_$option", $default );
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Updates a sendgrid plugin option
30
+ *
31
+ * @return string
32
+ */
33
+ public static function update_sendgrid_option( $option, $value ) {
34
+ if ( ! is_multisite() || ( is_multisite() and ! is_main_site() and get_option( 'sendgrid_can_manage_subsite' ) ) ) {
35
+ return update_option( "sendgrid_$option", $value );
36
+ } else {
37
+ return update_site_option( "sendgrid_$option", $value );
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Deletes a sendgrid plugin option
43
+ *
44
+ * @return string
45
+ */
46
+ public static function delete_sendgrid_option( $option ) {
47
+ if ( ! is_multisite() || ( is_multisite() and ! is_main_site() and get_option( 'sendgrid_can_manage_subsite' ) ) ) {
48
+ return delete_option( "sendgrid_$option" );
49
+ } else {
50
+ return delete_site_option( "sendgrid_$option" );
51
+ }
52
+ }
53
+
54
  /**
55
  * Check username/password
56
  *
288
  {
289
  if ( defined( 'SENDGRID_USERNAME' ) ) {
290
  return SENDGRID_USERNAME;
 
 
291
  } else {
292
+ $username = Sendgrid_Tools::get_sendgrid_option( 'user' );
293
  if( $username ) {
294
+ Sendgrid_Tools::delete_sendgrid_option( 'user' );
295
+ Sendgrid_Tools::update_sendgrid_option( 'username', $username );
296
  }
297
 
298
+ return Sendgrid_Tools::get_sendgrid_option( 'username' );
299
  }
300
  }
301
 
308
  */
309
  public static function set_username( $username )
310
  {
311
+ if( ! isset( $username ) ) {
312
+ return Sendgrid_Tools::update_sendgrid_option( 'username', '' );
 
 
 
 
 
 
 
 
 
 
313
  }
314
+
315
+ return Sendgrid_Tools::update_sendgrid_option( 'username', $username );
316
  }
317
 
318
  /**
324
  {
325
  if ( defined( 'SENDGRID_PASSWORD' ) ) {
326
  return SENDGRID_PASSWORD;
 
 
327
  } else {
328
+ $password = Sendgrid_Tools::get_sendgrid_option( 'pwd' );
329
+ $new_password = Sendgrid_Tools::get_sendgrid_option( 'password' );
330
  if ( $new_password and ! $password ) {
331
+ Sendgrid_Tools::update_sendgrid_option( 'pwd', self::decrypt( $new_password, AUTH_KEY ) );
332
+ Sendgrid_Tools::delete_sendgrid_option( 'password' );
333
  }
334
 
335
+ return Sendgrid_Tools::get_sendgrid_option( 'pwd' );
 
336
  }
337
  }
338
 
345
  */
346
  public static function set_password( $password )
347
  {
348
+ return Sendgrid_Tools::update_sendgrid_option( 'pwd', $password );
 
 
 
 
349
  }
350
 
351
  /**
357
  {
358
  if ( defined( 'SENDGRID_API_KEY' ) ) {
359
  return SENDGRID_API_KEY;
 
 
360
  } else {
361
+ $apikey = Sendgrid_Tools::get_sendgrid_option( 'api_key' );
362
+ $new_apikey = Sendgrid_Tools::get_sendgrid_option( 'apikey' );
363
  if ( $new_apikey and ! $apikey ) {
364
+ Sendgrid_Tools::update_sendgrid_option( 'api_key', self::decrypt( $new_apikey, AUTH_KEY ) );
365
+ Sendgrid_Tools::delete_sendgrid_option( 'apikey' );
366
  }
367
 
368
+ $apikey = Sendgrid_Tools::get_sendgrid_option( 'api_key' );
369
  return $apikey;
370
  }
371
  }
379
  {
380
  if ( defined( 'SENDGRID_MC_API_KEY' ) ) {
381
  return SENDGRID_MC_API_KEY;
 
 
382
  } else {
383
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_api_key' );
384
  }
385
  }
386
 
393
  {
394
  if ( defined( 'SENDGRID_MC_LIST_ID' ) ) {
395
  return SENDGRID_MC_LIST_ID;
 
 
396
  } else {
397
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_list_id' );
398
  }
399
  }
400
 
407
  {
408
  if ( defined( 'SENDGRID_MC_OPT_USE_TRANSACTIONAL' ) ) {
409
  return SENDGRID_MC_OPT_USE_TRANSACTIONAL;
 
 
410
  } else {
411
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_opt_use_transactional' );
412
  }
413
  }
414
 
421
  {
422
  if ( defined( 'SENDGRID_MC_OPT_REQ_FNAME_LNAME' ) ) {
423
  return SENDGRID_MC_OPT_REQ_FNAME_LNAME;
 
 
424
  } else {
425
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_opt_req_fname_lname' );
426
  }
427
  }
428
 
435
  {
436
  if ( defined( 'SENDGRID_MC_OPT_INCL_FNAME_LNAME' ) ) {
437
  return SENDGRID_MC_OPT_INCL_FNAME_LNAME;
 
 
438
  } else {
439
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_opt_incl_fname_lname' );
440
  }
441
  }
442
 
449
  {
450
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_SUBJECT' ) ) {
451
  return SENDGRID_MC_SIGNUP_EMAIL_SUBJECT;
 
 
452
  } else {
453
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_signup_email_subject' );
454
  }
455
  }
456
 
463
  {
464
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_CONTENT' ) ) {
465
  return SENDGRID_MC_SIGNUP_EMAIL_CONTENT;
 
 
466
  } else {
467
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_signup_email_content' );
468
  }
469
  }
470
 
477
  {
478
  if ( defined( 'SENDGRID_MC_SIGNUP_EMAIL_CONTENT_TEXT' ) ) {
479
  return SENDGRID_MC_SIGNUP_EMAIL_CONTENT_TEXT;
 
 
480
  } else {
481
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_signup_email_content_text' );
482
  }
483
  }
484
 
491
  {
492
  if ( defined( 'SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE' ) ) {
493
  return SENDGRID_MC_SIGNUP_CONFIRMATION_PAGE;
 
 
494
  } else {
495
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_signup_confirmation_page' );
496
  }
497
  }
498
 
525
  */
526
  public static function get_mc_auth_valid()
527
  {
528
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_auth_valid' );
 
 
 
 
529
  }
530
 
531
  /**
535
  */
536
  public static function get_mc_widget_notice_dismissed()
537
  {
538
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_widget_notice_dismissed' );
 
 
 
 
539
  }
540
 
541
  /**
547
  */
548
  public static function set_api_key( $apikey )
549
  {
550
+ return Sendgrid_Tools::update_sendgrid_option( 'api_key', $apikey );
 
 
 
 
551
  }
552
 
553
  /**
559
  */
560
  public static function set_mc_api_key( $apikey )
561
  {
562
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_api_key', $apikey );
 
 
 
 
563
  }
564
 
565
  /**
571
  */
572
  public static function set_mc_list_id( $list_id )
573
  {
574
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_list_id', $list_id );
 
 
 
 
575
  }
576
 
577
  /**
583
  */
584
  public static function set_mc_opt_use_transactional( $use_transactional )
585
  {
586
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_opt_use_transactional', $use_transactional );
 
 
 
 
587
  }
588
 
589
  /**
595
  */
596
  public static function set_mc_opt_req_fname_lname( $req_fname_lname )
597
  {
598
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_opt_req_fname_lname', $req_fname_lname );
 
 
 
 
599
  }
600
 
601
  /**
607
  */
608
  public static function set_mc_opt_incl_fname_lname( $incl_fname_lname )
609
  {
610
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_opt_incl_fname_lname', $incl_fname_lname );
 
 
 
 
611
  }
612
 
613
  /**
619
  */
620
  public static function set_mc_signup_email_subject( $email_subject )
621
  {
622
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_signup_email_subject', $email_subject );
 
 
 
 
623
  }
624
 
625
  /**
631
  */
632
  public static function set_mc_signup_email_content( $email_content )
633
  {
634
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_signup_email_content', $email_content );
 
 
 
 
635
  }
636
 
637
  /**
643
  */
644
  public static function set_mc_signup_email_content_text( $email_content )
645
  {
646
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_signup_email_content_text', $email_content );
 
 
 
 
647
  }
648
 
649
  /**
655
  */
656
  public static function set_mc_signup_confirmation_page( $confirmation_page )
657
  {
658
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_signup_confirmation_page', $confirmation_page );
 
 
 
 
659
  }
660
 
661
  /**
667
  */
668
  public static function set_mc_auth_valid( $auth_valid )
669
  {
670
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_auth_valid', $auth_valid );
 
 
 
 
671
  }
672
 
673
  /**
679
  */
680
  public static function set_mc_widget_notice_dismissed( $notice_dismissed )
681
  {
682
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_widget_notice_dismissed', $notice_dismissed );
 
 
 
 
683
  }
684
 
685
  /**
691
  {
692
  if ( defined( 'SENDGRID_SEND_METHOD' ) ) {
693
  return SENDGRID_SEND_METHOD;
694
+ } elseif ( Sendgrid_Tools::get_sendgrid_option( 'api', false ) ) {
695
+ return Sendgrid_Tools::get_sendgrid_option( 'api' );
 
 
696
  } else {
697
  return 'api';
698
  }
707
  */
708
  public static function set_send_method( $method )
709
  {
710
+ return Sendgrid_Tools::update_sendgrid_option( 'api', $method );
 
 
 
 
711
  }
712
 
713
  /**
719
  {
720
  if ( defined( 'SENDGRID_AUTH_METHOD' ) ) {
721
  return SENDGRID_AUTH_METHOD;
722
+ } elseif ( Sendgrid_Tools::get_sendgrid_option( 'auth_method', false ) ) {
723
+ $auth_method = Sendgrid_Tools::get_sendgrid_option( 'auth_method' );
 
 
724
  if ( 'username' == $auth_method ) {
725
  $auth_method = 'credentials';
726
+ Sendgrid_Tools::update_sendgrid_option( 'auth_method', $auth_method );
727
  }
728
 
729
  return $auth_method;
745
  */
746
  public static function set_auth_method( $method )
747
  {
748
+ return Sendgrid_Tools::update_sendgrid_option( 'auth_method', $method );
 
 
 
 
749
  }
750
 
751
  /**
757
  {
758
  if ( defined( 'SENDGRID_PORT' ) ) {
759
  return SENDGRID_PORT;
 
 
760
  } else {
761
+ return Sendgrid_Tools::get_sendgrid_option( 'port', Sendgrid_SMTP::TLS );
762
  }
763
  }
764
 
771
  */
772
  public static function set_port( $port )
773
  {
774
+ return Sendgrid_Tools::update_sendgrid_option( 'port', $port );
 
 
 
 
775
  }
776
 
777
  /**
783
  {
784
  if ( defined( 'SENDGRID_FROM_NAME' ) ) {
785
  return SENDGRID_FROM_NAME;
 
 
786
  } else {
787
+ return Sendgrid_Tools::get_sendgrid_option( 'from_name' );
788
  }
789
  }
790
 
797
  */
798
  public static function set_from_name( $name )
799
  {
800
+ return Sendgrid_Tools::update_sendgrid_option( 'from_name', $name );
 
 
 
 
801
  }
802
 
803
  /**
809
  {
810
  if ( defined( 'SENDGRID_FROM_EMAIL' ) ) {
811
  return SENDGRID_FROM_EMAIL;
 
 
812
  } else {
813
+ return Sendgrid_Tools::get_sendgrid_option( 'from_email' );
814
  }
815
  }
816
 
823
  */
824
  public static function set_from_email( $email )
825
  {
826
+ return Sendgrid_Tools::update_sendgrid_option( 'from_email', $email );
 
 
 
 
827
  }
828
 
829
  /**
835
  {
836
  if ( defined( 'SENDGRID_REPLY_TO' ) ) {
837
  return SENDGRID_REPLY_TO;
 
 
838
  } else {
839
+ return Sendgrid_Tools::get_sendgrid_option( 'reply_to' );
840
  }
841
  }
842
 
849
  */
850
  public static function set_reply_to( $email )
851
  {
852
+ return Sendgrid_Tools::update_sendgrid_option( 'reply_to', $email );
 
 
 
 
853
  }
854
 
855
  /**
861
  {
862
  if ( defined( 'SENDGRID_CATEGORIES' ) ) {
863
  return SENDGRID_CATEGORIES;
 
 
864
  } else {
865
+ return Sendgrid_Tools::get_sendgrid_option( 'categories' );
866
  }
867
  }
868
 
875
  */
876
  public static function set_categories( $categories )
877
  {
878
+ return Sendgrid_Tools::update_sendgrid_option( 'categories', $categories );
 
 
 
 
879
  }
880
 
881
  /**
887
  {
888
  if ( defined( 'SENDGRID_STATS_CATEGORIES' ) ) {
889
  return SENDGRID_STATS_CATEGORIES;
 
 
890
  } else {
891
+ return Sendgrid_Tools::get_sendgrid_option( 'stats_categories' );
892
  }
893
  }
894
 
901
  */
902
  public static function set_stats_categories( $categories )
903
  {
904
+ return Sendgrid_Tools::update_sendgrid_option( 'stats_categories', $categories );
 
 
 
 
905
  }
906
 
907
  /**
927
  {
928
  if ( defined( 'SENDGRID_TEMPLATE' ) ) {
929
  return SENDGRID_TEMPLATE;
 
 
930
  } else {
931
+ return Sendgrid_Tools::get_sendgrid_option( 'template' );
932
  }
933
  }
934
 
941
  */
942
  public static function set_template( $template )
943
  {
944
+ return Sendgrid_Tools::update_sendgrid_option( 'template', $template );
 
 
 
 
945
  }
946
 
947
  /**
953
  {
954
  if ( defined( 'SENDGRID_CONTENT_TYPE' ) ) {
955
  return SENDGRID_CONTENT_TYPE;
 
 
956
  } else {
957
+ return Sendgrid_Tools::get_sendgrid_option( 'content_type' );
958
  }
959
  }
960
 
967
  */
968
  public static function set_unsubscribe_group( $unsubscribe_group )
969
  {
970
+ return Sendgrid_Tools::update_sendgrid_option( 'unsubscribe_group', $unsubscribe_group );
 
 
 
 
971
  }
972
 
973
  /**
979
  {
980
  if ( defined( 'SENDGRID_UNSUBSCRIBE_GROUP' ) ) {
981
  return SENDGRID_UNSUBSCRIBE_GROUP;
 
 
982
  } else {
983
+ return Sendgrid_Tools::get_sendgrid_option( 'unsubscribe_group' );
984
  }
985
  }
986
 
993
  */
994
  public static function set_asm_permission( $permission )
995
  {
996
+ return Sendgrid_Tools::update_sendgrid_option( 'asm_permission', $permission );
 
 
 
 
997
  }
998
 
999
  /**
1003
  */
1004
  public static function get_asm_permission()
1005
  {
1006
+ return Sendgrid_Tools::get_sendgrid_option( 'asm_permission' );
 
 
 
 
1007
  }
1008
 
1009
  /**
1047
  */
1048
  public static function set_content_type( $content_type )
1049
  {
1050
+ return Sendgrid_Tools::update_sendgrid_option( 'content_type', $content_type );
 
 
 
 
1051
  }
1052
 
1053
  /**
1059
  */
1060
  public static function set_mc_email_label( $email_label )
1061
  {
1062
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_email_label', $email_label );
 
 
 
 
1063
  }
1064
 
1065
  /**
1071
  {
1072
  if ( defined( 'SENDGRID_MC_EMAIL_LABEL' ) ) {
1073
  return SENDGRID_MC_EMAIL_LABEL;
 
 
1074
  } else {
1075
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_email_label' );
1076
  }
1077
  }
1078
 
1085
  */
1086
  public static function set_mc_first_name_label( $first_name_label )
1087
  {
1088
+ return update_option( 'mc_first_name_label', $first_name_label );
 
 
 
 
1089
  }
1090
 
1091
  /**
1097
  {
1098
  if ( defined( 'SENDGRID_MC_FIRST_NAME_LABEL' ) ) {
1099
  return SENDGRID_MC_FIRST_NAME_LABEL;
 
 
1100
  } else {
1101
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_first_name_label' );
1102
  }
1103
  }
1104
 
1111
  */
1112
  public static function set_mc_last_name_label( $last_name_label )
1113
  {
1114
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_last_name_label', $last_name_label );
 
 
 
 
1115
  }
1116
 
1117
  /**
1123
  {
1124
  if ( defined( 'SENDGRID_MC_LAST_NAME_LABEL' ) ) {
1125
  return SENDGRID_MC_LAST_NAME_LABEL;
 
 
1126
  } else {
1127
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_last_name_label' );
1128
  }
1129
  }
1130
 
1137
  */
1138
  public static function set_mc_subscribe_label( $subscribe_label )
1139
  {
1140
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_subscribe_label', $subscribe_label );
 
 
 
 
1141
  }
1142
 
1143
  /**
1149
  {
1150
  if ( defined( 'SENDGRID_MC_SUBSCRIBE_LABEL' ) ) {
1151
  return SENDGRID_MC_SUBSCRIBE_LABEL;
 
 
1152
  } else {
1153
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_subscribe_label' );
1154
  }
1155
  }
1156
 
1180
  // set the new value
1181
  $values[$position] = $value;
1182
 
1183
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_input_padding', json_encode( $values ) );
 
 
 
 
1184
  }
1185
 
1186
  /**
1190
  */
1191
  public static function get_mc_input_padding()
1192
  {
1193
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_input_padding' );
 
 
 
 
1194
  }
1195
 
1196
  /**
1201
  */
1202
  public static function get_mc_input_padding_by_position( $position )
1203
  {
1204
+ $padding = Sendgrid_Tools::get_sendgrid_option( 'mc_input_padding' );
 
 
 
 
1205
 
1206
  if ( false == $padding ) {
1207
+ if ( $position == "top" ) {
 
1208
  return 10;
1209
  }
1210
 
1244
  // set the new value
1245
  $values[$position] = $value;
1246
 
1247
+ return Sendgrid_Tools::update_sendgrid_option( 'mc_button_padding', json_encode( $values ) );
 
 
 
 
1248
  }
1249
 
1250
  /**
1254
  */
1255
  public static function get_mc_button_padding()
1256
  {
1257
+ return Sendgrid_Tools::get_sendgrid_option( 'mc_button_padding' );
 
 
 
 
1258
  }
1259
 
1260
  /**
1265
  */
1266
  public static function get_mc_button_padding_by_position( $position )
1267
  {
1268
+ $padding = Sendgrid_Tools::get_sendgrid_option( 'mc_button_padding' );
 
 
 
 
1269
 
1270
  if ( false == $padding ) {
1271
  if ( $position == "top" )
1457
  {
1458
  return preg_replace('/<(https?:\/\/[^>]*)>/im', '$1', $content);
1459
  }
1460
+
1461
+ /**
1462
+ * Set/update the value of a transient using database.
1463
+ *
1464
+ * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
1465
+ * 172 characters or fewer in length.
1466
+ * @param mixed $value Transient value. Must be serializable if non-scalar.
1467
+ * Expected to not be SQL-escaped.
1468
+ * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
1469
+ * @return bool False if value was not set and true if value was set.
1470
+ */
1471
+ public static function set_transient_sendgrid( $transient, $value, $expiration = 0 ) {
1472
+ $old_cache_value = wp_using_ext_object_cache();
1473
+ wp_using_ext_object_cache( false );
1474
+ $set_transient_result = set_transient( $transient, $value, $expiration );
1475
+ wp_using_ext_object_cache( $old_cache_value );
1476
+
1477
+ return $set_transient_result;
1478
+ }
1479
+
1480
+ /**
1481
+ * Set/update the value of a site transient using database.
1482
+ *
1483
+ * @param string $transient Transient name. Expected to not be SQL-escaped. Must be
1484
+ * 172 characters or fewer in length.
1485
+ * @param mixed $value Transient value. Must be serializable if non-scalar.
1486
+ * Expected to not be SQL-escaped.
1487
+ * @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
1488
+ * @return bool False if value was not set and true if value was set.
1489
+ */
1490
+ public static function set_site_transient_sendgrid( $transient, $value, $expiration = 0 ) {
1491
+ $old_cache_value = wp_using_ext_object_cache();
1492
+ wp_using_ext_object_cache( false );
1493
+ $set_transient_result = set_site_transient( $transient, $value, $expiration );
1494
+ wp_using_ext_object_cache( $old_cache_value );
1495
+
1496
+ return $set_transient_result;
1497
+ }
1498
+
1499
+ /**
1500
+ * Get the value of a transient from database.
1501
+ *
1502
+ * If the transient does not exist, does not have a value, or has expired,
1503
+ * then the return value will be false.
1504
+ *
1505
+ * @param string $transient Transient name. Expected to not be SQL-escaped.
1506
+ * @return mixed Value of transient.
1507
+ */
1508
+ function get_transient_sendgrid( $transient ) {
1509
+ $old_cache_value = wp_using_ext_object_cache();
1510
+ wp_using_ext_object_cache( false );
1511
+ $value = get_transient( $transient );
1512
+ wp_using_ext_object_cache( $old_cache_value );
1513
+
1514
+ return $value;
1515
+ }
1516
+
1517
+ /**
1518
+ * Get the value of a site transient from database.
1519
+ *
1520
+ * If the transient does not exist, does not have a value, or has expired,
1521
+ * then the return value will be false.
1522
+ *
1523
+ * @param string $transient Transient name. Expected to not be SQL-escaped.
1524
+ * @return mixed Value of transient.
1525
+ */
1526
+ function get_site_transient_sendgrid( $transient ) {
1527
+ $old_cache_value = wp_using_ext_object_cache();
1528
+ wp_using_ext_object_cache( false );
1529
+ $value = get_site_transient( $transient );
1530
+ wp_using_ext_object_cache( $old_cache_value );
1531
+
1532
+ return $value;
1533
+ }
1534
  }
1535
 
1536
  /**
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.7
7
- Stable tag: 1.10.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -255,6 +255,10 @@ The settings for all sites in the network can be configured only by the Network
255
 
256
  == Changelog ==
257
 
 
 
 
 
258
  = 1.10.3 =
259
  * Add option to configure text version using setText() function from the header
260
  * Tested up to 4.7
@@ -390,6 +394,10 @@ The settings for all sites in the network can be configured only by the Network
390
 
391
  == Upgrade notice ==
392
 
 
 
 
 
393
  = 1.10.3 =
394
  * Add option to configure text version using setText() function from the header
395
  * Tested up to 4.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: 4.2
6
  Tested up to: 4.7
7
+ Stable tag: 1.10.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
255
 
256
  == Changelog ==
257
 
258
+ = 1.10.5 =
259
+ * Added settings page on multisite to give access to self manage SendGrid plugin to each subsite
260
+ = 1.10.4 =
261
+ * Set transient token for Marketing Campaign in database
262
  = 1.10.3 =
263
  * Add option to configure text version using setText() function from the header
264
  * Tested up to 4.7
394
 
395
  == Upgrade notice ==
396
 
397
+ = 1.10.5 =
398
+ * Added settings page on multisite to give access to self manage SendGrid plugin to each subsite
399
+ = 1.10.4 =
400
+ * Set transient token for Marketing Campaign in database
401
  = 1.10.3 =
402
  * Add option to configure text version using setText() function from the header
403
  * Tested up to 4.7
view/js/sendgrid.settings-v1.7.3.js CHANGED
@@ -149,4 +149,8 @@ jQuery(document).ready(function($) {
149
  $('#send_method').select2({
150
  minimumResultsForSearch: Infinity
151
  });
 
 
 
 
152
  });
149
  $('#send_method').select2({
150
  minimumResultsForSearch: Infinity
151
  });
152
+
153
+ $('#sg-check-all-sites').click(function () {
154
+ $('#subsites-table-sg input:checkbox').prop('checked', this.checked);
155
+ });
156
  });
view/sendgrid_settings.php CHANGED
@@ -13,6 +13,11 @@
13
  <?php
14
  $tabs = array( 'general' => 'General', 'marketing' => 'Subscription Widget' );
15
 
 
 
 
 
 
16
  $active_tab = current( array_keys( $tabs ) );
17
  if ( isset( $_GET[ 'tab' ] ) ) {
18
  $selected_tab = $_GET[ 'tab' ];
@@ -28,5 +33,6 @@
28
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_test_email.php';
29
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_nlvx.php';
30
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_test_contact.php';
 
31
  ?>
32
  </div>
13
  <?php
14
  $tabs = array( 'general' => 'General', 'marketing' => 'Subscription Widget' );
15
 
16
+ // If network settings display settings for subsites
17
+ if ( is_multisite() and is_main_site() ) {
18
+ $tabs['multisite'] = 'Multisite Settings';
19
+ }
20
+
21
  $active_tab = current( array_keys( $tabs ) );
22
  if ( isset( $_GET[ 'tab' ] ) ) {
23
  $selected_tab = $_GET[ 'tab' ];
33
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_test_email.php';
34
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_nlvx.php';
35
  require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_test_contact.php';
36
+ require_once plugin_dir_path( __FILE__ ) . 'sendgrid_settings_multisite.php';
37
  ?>
38
  </div>
view/sendgrid_settings_multisite.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ( $active_tab == 'multisite' ): ?>
2
+ <?php $sites = get_sites(); ?>
3
+ <p class="description">
4
+ On this page you can grant each subsite the ability to manage SendGrid settings. </br>
5
+ If the checkbox is unchecked then that site will not see the SendGrid settings page and will use the settings set on the network.</br>
6
+ <strong> Warning! </strong> When you activate the management for a subsite, that site will not be able to send emails until the subsite admin updates his SendGrid settings.
7
+ </p>
8
+ <form method="POST" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI'] ); ?>">
9
+ <table class="widefat fixed" id="subsites-table-sg" cellspacing="0">
10
+ <thead>
11
+ <tr valign="top">
12
+ <th scope="col" class="manage-column column-columnname num">ID</th>
13
+ <th scope="col" class="manage-column column-columnname">Name</th>
14
+ <th scope="col" class="manage-column column-columnname">Public</th>
15
+ <th scope="col" class="manage-column column-columnname">Site Url</th>
16
+ <th scope="col" class="manage-column"><input style="margin:0 0 0 0px;" type="checkbox" id="sg-check-all-sites"/> Self-Managed?</th>
17
+ </tr>
18
+ </thead>
19
+ <tbody>
20
+ <?php foreach ($sites as $index => $site): ?>
21
+ <?php if (!is_main_site($site->blog_id)): ?>
22
+ <?php $site_info = get_blog_details($site->blog_id); ?>
23
+ <tr <?php echo ($index%2 == 1)? 'class="alternate"':''?>>
24
+ <td class="column-columnname num" scope="row"><?php echo $site_info->blog_id; ?></td>
25
+ <td class="column-columnname" scope="row"><?php echo $site_info->blogname; ?></td>
26
+ <td class="column-columnname" scope="row"><?php echo $site_info->public? "true":"false"; ?></td>
27
+ <td class="column-columnname" scope="row">
28
+ <a href="<?php echo $site_info->siteurl; ?>"><?php echo $site_info->siteurl; ?><a>
29
+ </td>
30
+ <td class="column-columnname" scope="row" aligh="center">
31
+ <input type="checkbox" id="check-can-manage-sg" name="checked_sites[<?php echo $site_info->blog_id ?>]"
32
+ <?php echo (get_blog_option( $site_info->blog_id, 'sendgrid_can_manage_subsite', 0 )? "checked":"") ?> />
33
+ </td>
34
+ </tr>
35
+ <?php endif; ?>
36
+ <?php endforeach; ?>
37
+ </tbody>
38
+ </table>
39
+ <p class="submit">
40
+ <input type="submit" id="doaction" class="button button-primary" value="Save Settings">
41
+ </p>
42
+ <input type="hidden" name="subsite_settings" value="true"/>
43
+ </form>
44
+ <?php endif; ?>
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.10.3
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified
@@ -74,7 +74,8 @@ if ( isset( $_POST['sg_dismiss_widget_notice'] ) ) {
74
  }
75
 
76
  // Display widget notice
77
- if ( 'true' != Sendgrid_Tools::get_mc_widget_notice_dismissed() ) {
 
78
  add_action( 'admin_notices', 'sg_subscription_widget_admin_notice' );
79
  }
80
 
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.10.5
7
  Author: SendGrid
8
  Author URI: http://sendgrid.com
9
  Text Domain: sendgrid-email-delivery-simplified
74
  }
75
 
76
  // Display widget notice
77
+ if ( 'true' != Sendgrid_Tools::get_mc_widget_notice_dismissed() and
78
+ ( !is_multisite() or ( is_multisite() and ( get_option( 'sendgrid_can_manage_subsite' ) or is_main_site() ) ) ) ) {
79
  add_action( 'admin_notices', 'sg_subscription_widget_admin_notice' );
80
  }
81