SendinBlue Subscribe Form And WP SMTP - Version 3.0.2

Version Description

  • Bug fixes & improvements
Download this release

Release Info

Developer neeraj_slit
Plugin Icon 128x128 SendinBlue Subscribe Form And WP SMTP
Version 3.0.2
Comparing to
See all releases

Code changes from version 3.0.1 to 3.0.2

inc/SendinblueApiClient.php CHANGED
@@ -11,6 +11,7 @@ class SendinblueApiClient
11
  const CAMPAIGN_TYPE_EMAIL = 'email';
12
  const CAMPAIGN_TYPE_SMS = 'sms';
13
  const RESPONSE_CODE_OK = 200;
 
14
  const RESPONSE_CODE_ACCEPTED = 202;
15
 
16
  private $apiKey;
@@ -266,6 +267,7 @@ class SendinblueApiClient
266
  $url = self::API_BASE_URL . $endpoint;
267
 
268
  $args = [
 
269
  'method' => $method,
270
  'headers' => [
271
  'api-key' => $this->apiKey,
@@ -281,10 +283,18 @@ class SendinblueApiClient
281
  }
282
 
283
  $response = wp_remote_request($url, $args);
284
- $data = wp_remote_retrieve_body($response);
285
  $this->lastResponseCode = wp_remote_retrieve_response_code($response);
286
 
287
- return json_decode($data, true);
 
 
 
 
 
 
 
 
 
288
  }
289
 
290
  /**
11
  const CAMPAIGN_TYPE_EMAIL = 'email';
12
  const CAMPAIGN_TYPE_SMS = 'sms';
13
  const RESPONSE_CODE_OK = 200;
14
+ const RESPONSE_CODE_CREATED = 201;
15
  const RESPONSE_CODE_ACCEPTED = 202;
16
 
17
  private $apiKey;
267
  $url = self::API_BASE_URL . $endpoint;
268
 
269
  $args = [
270
+ 'timeout' => 10000,
271
  'method' => $method,
272
  'headers' => [
273
  'api-key' => $this->apiKey,
283
  }
284
 
285
  $response = wp_remote_request($url, $args);
 
286
  $this->lastResponseCode = wp_remote_retrieve_response_code($response);
287
 
288
+ if (is_wp_error($response)) {
289
+ $data = [
290
+ 'code' => $response->get_error_code(),
291
+ 'message' => $response->get_error_message()
292
+ ];
293
+ } else {
294
+ $data = json_decode(wp_remote_retrieve_body($response), true);
295
+ }
296
+
297
+ return $data;
298
  }
299
 
300
  /**
inc/sib-api-manager.php CHANGED
@@ -243,7 +243,38 @@ if ( ! class_exists( 'SIB_API_Manager' ) ) {
243
  */
244
  public static function send_email( $data ) {
245
  $mailin = new SendinblueApiClient( );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  $result = $mailin->sendEmail( $data );
 
 
 
 
247
  return $result;
248
  }
249
 
@@ -832,29 +863,30 @@ if ( ! class_exists( 'SIB_API_Manager' ) ) {
832
  $isEmpty = false;
833
  $ret = $mailin->getAttributes();
834
 
835
- foreach ($ret["attributes"] as $key => $value) {
836
- if($value["category"] == "category" && 'DOUBLE_OPT-IN' == $value['name'] && ! empty( $value['enumeration'] ) ) {
837
- $isEmpty = true;
838
- }
839
- }
 
840
 
841
- if ( ! $isEmpty ) {
842
- $data = [
843
- 'type' => 'category',
844
- 'enumeration' => [
845
- [
846
- 'value' => 1,
847
- 'label' => 'Yes'
848
- ],
849
- [
850
- 'value' => 2,
851
- 'label' => 'No'
852
- ],
853
- ]
854
- ];
855
- $mailin->createAttribute('category', 'DOUBLE_OPT', $data);
856
- }
 
857
  }
858
-
859
  }
860
  }
243
  */
244
  public static function send_email( $data ) {
245
  $mailin = new SendinblueApiClient( );
246
+ try {
247
+ if (isset($data['headers'])) {
248
+ $emailHeaders = explode("\r\n", $data['headers']);
249
+ unset($data['headers']);
250
+ $preparedHeaders = [];
251
+ foreach ($emailHeaders as $header) {
252
+ $header = explode(': ', $header);
253
+ if (is_array($header) && 2 == count($header)) {
254
+ if ($header[0] == 'X-Mailin-Tag') {
255
+ $data['tags'][] = $header[1];
256
+ }
257
+ $preparedHeaders[$header[0]] = $header[1];
258
+ }
259
+ }
260
+ $data['headers'] = $preparedHeaders;
261
+ }
262
+ } catch (Exception $exception) {
263
+
264
+ }
265
+ $home_options = get_option( SIB_Manager::HOME_OPTION_NAME);
266
+ if (!empty($home_options['from_email'])) {
267
+ $data['sender']['email'] = $home_options['from_email'];
268
+ if (!empty($home_options['from_name'])) {
269
+ $data['sender']['name'] = $home_options['from_name'];
270
+ }
271
+ }
272
+
273
  $result = $mailin->sendEmail( $data );
274
+ if (SendinblueApiClient::RESPONSE_CODE_CREATED == $mailin->getLastResponseCode()) {
275
+ return ['code' => 'success'];
276
+ }
277
+
278
  return $result;
279
  }
280
 
863
  $isEmpty = false;
864
  $ret = $mailin->getAttributes();
865
 
866
+ if (isset($ret["attributes"])) {
867
+ foreach ($ret["attributes"] as $key => $value) {
868
+ if($value["category"] == "category" && 'DOUBLE_OPT-IN' == $value['name'] && ! empty( $value['enumeration'] ) ) {
869
+ $isEmpty = true;
870
+ }
871
+ }
872
 
873
+ if ( ! $isEmpty ) {
874
+ $data = [
875
+ 'type' => 'category',
876
+ 'enumeration' => [
877
+ [
878
+ 'value' => 1,
879
+ 'label' => 'Yes'
880
+ ],
881
+ [
882
+ 'value' => 2,
883
+ 'label' => 'No'
884
+ ],
885
+ ]
886
+ ];
887
+ $mailin->createAttribute('category', 'DOUBLE_OPT', $data);
888
+ }
889
+ }
890
  }
 
891
  }
892
  }
js/admin.js CHANGED
@@ -580,7 +580,7 @@ $jQ(document).ready(function(){
580
  }
581
  else {
582
  sib_access_key.addClass('error');
583
- $jQ('#failure-alert').html($jQ('#general_error').val()).show();
584
  }
585
  });
586
  });
580
  }
581
  else {
582
  sib_access_key.addClass('error');
583
+ $jQ('#failure-alert').html(respond).show();
584
  }
585
  });
586
  });
page/page-form.php CHANGED
@@ -59,10 +59,8 @@ if ( ! class_exists( 'SIB_Page_Form' ) ) {
59
  * Init Process
60
  */
61
  function Init() {
62
- if ( SIB_Manager::is_done_validation() ) {
63
- $this->forms = new SIB_Forms_List();
64
- $this->forms->prepare_items();
65
- }
66
  }
67
 
68
  /**
@@ -102,7 +100,7 @@ if ( ! class_exists( 'SIB_Page_Form' ) ) {
102
  <h1><img id="logo-img" src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/logo.png' ); ?>">
103
  <?php
104
  $return_btn = 'none';
105
- if ( SIB_Manager::is_done_validation() && isset( $_GET['id'] ) ) {
106
  $return_btn = 'inline-block';
107
  }
108
  ?>
@@ -111,7 +109,7 @@ if ( ! class_exists( 'SIB_Page_Form' ) ) {
111
  <div id="wrap-left" class="box-border-box col-md-9 ">
112
  <input type="hidden" class="sib-dateformat" value="<?php echo esc_attr( 'yyyy-mm-dd' ); ?>">
113
  <?php
114
- if ( SIB_Manager::is_done_validation() ) {
115
  if ( ( isset( $_GET['action'] ) && 'edit' === sanitize_text_field($_GET['action'] )) || ( isset( $_GET['action'] ) && 'duplicate' === sanitize_text_field($_GET['action'] )) ) {
116
  $this->formID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : 'new';
117
  $this->generate_form_edit();
59
  * Init Process
60
  */
61
  function Init() {
62
+ $this->forms = new SIB_Forms_List();
63
+ $this->forms->prepare_items();
 
 
64
  }
65
 
66
  /**
100
  <h1><img id="logo-img" src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/logo.png' ); ?>">
101
  <?php
102
  $return_btn = 'none';
103
+ if (isset( $_GET['id'] ) ) {
104
  $return_btn = 'inline-block';
105
  }
106
  ?>
109
  <div id="wrap-left" class="box-border-box col-md-9 ">
110
  <input type="hidden" class="sib-dateformat" value="<?php echo esc_attr( 'yyyy-mm-dd' ); ?>">
111
  <?php
112
+ if ( SIB_Manager::is_api_key_set() ) {
113
  if ( ( isset( $_GET['action'] ) && 'edit' === sanitize_text_field($_GET['action'] )) || ( isset( $_GET['action'] ) && 'duplicate' === sanitize_text_field($_GET['action'] )) ) {
114
  $this->formID = isset( $_GET['id'] ) ? sanitize_text_field( $_GET['id'] ) : 'new';
115
  $this->generate_form_edit();
page/page-home.php CHANGED
@@ -177,7 +177,7 @@ if ( ! class_exists( 'SIB_Page_Home' ) ) {
177
  }
178
  // set default sender info.
179
  $senders = SIB_API_Manager::get_sender_lists();
180
- if (SIB_Manager::is_done_validation() && is_array( $senders) && (!isset( $home_settings['sender'] ) || (count($senders) == 1 && $home_settings['from_email'] != $senders[0]['from_email']))) {
181
  $home_settings['sender'] = $senders[0]['id'];
182
  $home_settings['from_name'] = $senders[0]['from_name'];
183
  $home_settings['from_email'] = $senders[0]['from_email'];
@@ -566,7 +566,7 @@ if ( ! class_exists( 'SIB_Page_Home' ) ) {
566
  try {
567
  update_option(SIB_Manager::API_KEY_V3_OPTION_NAME, $access_key);
568
  $apiClient = new SendinblueApiClient();
569
- $apiClient->getAccount();
570
  if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
571
  // create tables for users and forms.
572
  SIB_Model_Users::createTable();
@@ -577,7 +577,7 @@ if ( ! class_exists( 'SIB_Page_Home' ) ) {
577
  $message = 'success';
578
  } else {
579
  delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
580
- $message = 'fail';
581
  }
582
  } catch ( Exception $e ) {
583
  $message = $e->getMessage();
177
  }
178
  // set default sender info.
179
  $senders = SIB_API_Manager::get_sender_lists();
180
+ if (is_array( $senders) && (!isset( $home_settings['sender'] ) || (count($senders) == 1 && $home_settings['from_email'] != $senders[0]['from_email']))) {
181
  $home_settings['sender'] = $senders[0]['id'];
182
  $home_settings['from_name'] = $senders[0]['from_name'];
183
  $home_settings['from_email'] = $senders[0]['from_email'];
566
  try {
567
  update_option(SIB_Manager::API_KEY_V3_OPTION_NAME, $access_key);
568
  $apiClient = new SendinblueApiClient();
569
+ $response = $apiClient->getAccount();
570
  if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
571
  // create tables for users and forms.
572
  SIB_Model_Users::createTable();
577
  $message = 'success';
578
  } else {
579
  delete_option(SIB_Manager::API_KEY_V3_OPTION_NAME);
580
+ $message = isset($response['code']) ? $response['code'] . ': ' . $response['message'] :'Please input a valid API v3 key';
581
  }
582
  } catch ( Exception $e ) {
583
  $message = $e->getMessage();
page/page-scenarios.php CHANGED
@@ -80,11 +80,7 @@ if ( ! class_exists( 'SIB_Page_Scenarios' ) ) {
80
  <h2><img id="logo-img" src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/logo.png' ); ?>"></h2>
81
  <div id="wrap-left" class="box-border-box col-md-9 ">
82
  <?php
83
- if ( SIB_Manager::is_done_validation() ) {
84
  $this->generate_main_page();
85
- } else {
86
- $this->generate_welcome_page();
87
- }
88
  ?>
89
  </div>
90
  <div id="wrap-right-side" class="box-border-box col-md-3">
80
  <h2><img id="logo-img" src="<?php echo esc_url( SIB_Manager::$plugin_url . '/img/logo.png' ); ?>"></h2>
81
  <div id="wrap-left" class="box-border-box col-md-9 ">
82
  <?php
 
83
  $this->generate_main_page();
 
 
 
84
  ?>
85
  </div>
86
  <div id="wrap-right-side" class="box-border-box col-md-3">
page/page-statistics.php CHANGED
@@ -74,6 +74,7 @@ if ( ! class_exists( 'SIB_Page_Statistics' ) ) {
74
  wp_enqueue_style( 'sib-bootstrap-css' );
75
  wp_enqueue_style( 'sib-fontawesome-css' );
76
  wp_enqueue_style( 'thickbox' );
 
77
  }
78
 
79
  /** Generate page script */
74
  wp_enqueue_style( 'sib-bootstrap-css' );
75
  wp_enqueue_style( 'sib-fontawesome-css' );
76
  wp_enqueue_style( 'thickbox' );
77
+ wp_enqueue_style( 'sib-jquery-ui-datepicker', SIB_Manager::$plugin_url . '/css/datepicker.css', false, false, false );
78
  }
79
 
80
  /** Generate page script */
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: neeraj_slit
3
  Tags: sendinblue, marketing automation, email marketing, email campaign, newsletter, wordpress smtp, subscription form, phpmailer, SMTP, wp_mail, massive email, sendmail, ssl, tls, wp-phpmailer, mail smtp, mailchimp, newsletters, email plugin, signup form, email widget, widget, plugin, sidebar, shortcode
4
  Requires at least: 4.4
5
- Tested up to: 5.2.2
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -112,12 +112,18 @@ In order to create a signup form, you need to:
112
  2. Integrate the form in a sidebar using a widget from WP panel > Appearance > Widgets. The Sendinblue widget form should appear in your widgets list, you just to have to drag and drop the widget into the sidebar of your choice.
113
 
114
  == Changelog ==
 
 
 
115
  = 3.0.1 =
116
  * Fix login process with api v3 key
117
 
118
  = 3.0.0 =
119
- * migrate to API v3
120
- * remove iframe depended views
 
 
 
121
 
122
  = 2.9.18 =
123
  * Bug and Security fix
2
  Contributors: neeraj_slit
3
  Tags: sendinblue, marketing automation, email marketing, email campaign, newsletter, wordpress smtp, subscription form, phpmailer, SMTP, wp_mail, massive email, sendmail, ssl, tls, wp-phpmailer, mail smtp, mailchimp, newsletters, email plugin, signup form, email widget, widget, plugin, sidebar, shortcode
4
  Requires at least: 4.4
5
+ Tested up to: 5.4.2
6
  Stable tag: trunk
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
112
  2. Integrate the form in a sidebar using a widget from WP panel > Appearance > Widgets. The Sendinblue widget form should appear in your widgets list, you just to have to drag and drop the widget into the sidebar of your choice.
113
 
114
  == Changelog ==
115
+ = 3.0.2 =
116
+ * Bug fixes & improvements
117
+
118
  = 3.0.1 =
119
  * Fix login process with api v3 key
120
 
121
  = 3.0.0 =
122
+ * [Improvement] Migrated the plugin from API v2 to API v3
123
+ * [Improvement] Removed iframe (due to security reasons)
124
+ * [More details] No changes in features (Contact sync, transactional mailing, marketing automation, forms)
125
+ * [More details] New version has only 3 tabs: Home, Forms, Statistics
126
+ * [More details] Tabs with iframe (lists, campaigns) were removed
127
 
128
  = 2.9.18 =
129
  * Bug and Security fix
sendinblue.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Sendinblue Subscribe Form And WP SMTP
4
  * Plugin URI: https://www.sendinblue.com/?r=wporg
5
  * Description: Easily send emails from your WordPress blog using Sendinblue SMTP and easily add a subscribe form to your site
6
- * Version: 3.0.1
7
  * Author: Sendinblue
8
  * Author URI: https://www.sendinblue.com/?r=wporg
9
  * License: GPLv2 or later
@@ -349,7 +349,6 @@ if ( ! class_exists( 'SIB_Manager' ) ) {
349
  wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), null, 'all' );
350
  wp_register_style( 'sib-chosen-css', self::$plugin_url . '/css/chosen.min.css' );
351
  wp_register_style( 'sib-admin-css', self::$plugin_url . '/css/admin.css', array(), filemtime( self::$plugin_dir . '/css/admin.css' ), 'all' );
352
- wp_enqueue_style( 'sib-jquery-ui-datepicker', self::$plugin_url . '/css/datepicker.css', false, false, false );
353
  }
354
 
355
  /**
@@ -442,17 +441,25 @@ if ( ! class_exists( 'SIB_Manager' ) ) {
442
  * Check that have done validation process already.
443
  */
444
  static function is_done_validation() {
445
- if (get_option(SIB_Manager::API_KEY_V3_OPTION_NAME)) {
446
  $apiClient = new SendinblueApiClient();
447
- $apiClient->getAccount();
448
  if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
449
  return true;
450
  }
 
 
 
 
451
  }
452
 
453
  return false;
454
  }
455
 
 
 
 
 
456
  /**
457
  * Install marketing automation script in header
458
  */
3
  * Plugin Name: Sendinblue Subscribe Form And WP SMTP
4
  * Plugin URI: https://www.sendinblue.com/?r=wporg
5
  * Description: Easily send emails from your WordPress blog using Sendinblue SMTP and easily add a subscribe form to your site
6
+ * Version: 3.0.2
7
  * Author: Sendinblue
8
  * Author URI: https://www.sendinblue.com/?r=wporg
9
  * License: GPLv2 or later
349
  wp_register_style( 'sib-fontawesome-css', self::$plugin_url . '/css/fontawesome/css/font-awesome.css', array(), null, 'all' );
350
  wp_register_style( 'sib-chosen-css', self::$plugin_url . '/css/chosen.min.css' );
351
  wp_register_style( 'sib-admin-css', self::$plugin_url . '/css/admin.css', array(), filemtime( self::$plugin_dir . '/css/admin.css' ), 'all' );
 
352
  }
353
 
354
  /**
441
  * Check that have done validation process already.
442
  */
443
  static function is_done_validation() {
444
+ if (self::is_api_key_set()) {
445
  $apiClient = new SendinblueApiClient();
446
+ $response = $apiClient->getAccount();
447
  if ( $apiClient->getLastResponseCode() === SendinblueApiClient::RESPONSE_CODE_OK ) {
448
  return true;
449
  }
450
+
451
+ if (isset($response['error'])) {
452
+ echo sprintf('<div class="error"><p>%s: %s</p></div>', $response['code'], $response['error']);
453
+ }
454
  }
455
 
456
  return false;
457
  }
458
 
459
+ static function is_api_key_set() {
460
+ return !empty(get_option(SIB_Manager::API_KEY_V3_OPTION_NAME));
461
+ }
462
+
463
  /**
464
  * Install marketing automation script in header
465
  */