Email Subscribers & Newsletters - Version 4.2.1

Version Description

(10.10.2019) = * Update: Added per page screen option for Contacts, Forms, Lists & Campaigns

Download this release

Release Info

Developer Icegram
Plugin Icon 128x128 Email Subscribers & Newsletters
Version 4.2.1
Comparing to
See all releases

Code changes from version 4.2.0 to 4.2.1

Files changed (40) hide show
  1. admin/class-email-subscribers-admin.php +96 -37
  2. admin/partials/dashboard.php +2 -2
  3. email-subscribers.php +22 -4
  4. includes/admin/class-es-actions.php +17 -4
  5. includes/admin/class-es-campaigns-table.php +40 -41
  6. includes/admin/{class-es-subscribers-table.php → class-es-contacts-table.php} +57 -64
  7. includes/admin/class-es-cron.php +3 -0
  8. includes/admin/class-es-export-subscribers.php +1 -1
  9. includes/admin/class-es-forms-table.php +35 -29
  10. includes/admin/class-es-handle-post-notification.php +1 -1
  11. includes/admin/class-es-handle-subscription.php +7 -2
  12. includes/admin/class-es-info.php +6 -7
  13. includes/admin/class-es-lists-table.php +95 -63
  14. includes/admin/class-es-newsletters.php +3 -4
  15. includes/admin/class-es-old-widget.php +2 -2
  16. includes/admin/class-es-post-notifications.php +1 -1
  17. includes/admin/class-es-queue.php +408 -37
  18. includes/admin/class-es-reports-table.php +2 -2
  19. includes/admin/class-es-tracking.php +0 -1
  20. includes/class-email-subscribers.php +486 -176
  21. includes/class-es-common.php +8 -8
  22. includes/class-es-install.php +87 -25
  23. includes/class-es-mailer.php +25 -20
  24. includes/db/class-es-db-actions.php +79 -0
  25. includes/db/class-es-db-campaigns.php +186 -91
  26. includes/db/class-es-db-contacts.php +65 -8
  27. includes/db/class-es-db-forms.php +2 -2
  28. includes/db/class-es-db-links.php +15 -12
  29. includes/db/class-es-db-lists.php +255 -52
  30. includes/db/class-es-db-mailing-queue.php +14 -0
  31. includes/db/class-es-db-queue.php +67 -0
  32. includes/db/class-es-db.php +244 -7
  33. includes/es-backward.php +3 -3
  34. includes/feedback/class-ig-feedback.php +1 -1
  35. includes/feedback/class-ig-tracker.php +2 -2
  36. includes/pro-features.php +1 -1
  37. includes/upgrade/es-update-functions.php +54 -8
  38. public/class-email-subscribers-public.php +2 -2
  39. public/partials/class-es-shortcode.php +3 -3
  40. readme.txt +4 -1
admin/class-email-subscribers-admin.php CHANGED
@@ -47,7 +47,7 @@ class Email_Subscribers_Admin {
47
 
48
  /**
49
  * Initialize the class and set its properties.
50
- *
51
  * @param string $email_subscribers The name of this plugin.
52
  * @param string $version The version of this plugin.
53
  *
@@ -62,7 +62,6 @@ class Email_Subscribers_Admin {
62
  // Reorder ES Submenu
63
  add_filter( 'custom_menu_order', array( $this, 'submenu_order' ) );
64
 
65
-
66
  add_action( 'admin_menu', array( $this, 'email_subscribers_admin_menu' ) );
67
  add_action( 'wp_ajax_es_klawoo_subscribe', array( $this, 'klawoo_subscribe' ) );
68
  add_action( 'admin_footer', array( $this, 'remove_submenu' ) );
@@ -157,7 +156,7 @@ class Email_Subscribers_Admin {
157
  ?>
158
  <script type="text/javascript">
159
  jQuery(document).ready(function () {
160
- var removeSubmenu = ['ig-es-broadcast', 'ig-es-lists', 'ig-es-post-notifications'];
161
  jQuery.each(removeSubmenu, function (key, id) {
162
  jQuery("#" + id).parent('a').parent('li').hide();
163
  });
@@ -172,14 +171,27 @@ class Email_Subscribers_Admin {
172
 
173
  // Submenu
174
  add_submenu_page( 'es_dashboard', __( 'Dashboard', 'email-subscribers' ), __( 'Dashboard', 'email-subscribers' ), 'edit_posts', 'es_dashboard', array( $this, 'es_dashboard_callback' ) );
175
- add_submenu_page( 'es_dashboard', __( 'Lists', 'email-subscribers' ), '<span id="ig-es-lists">' . __( 'Lists', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_lists', array( $this, 'load_lists' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  add_submenu_page( 'es_dashboard', __( 'Post Notifications', 'email-subscribers' ), '<span id="ig-es-post-notifications">' . __( 'Post Notifications', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_notifications', array( $this, 'load_post_notifications' ) );
177
  add_submenu_page( 'es_dashboard', __( 'Broadcast', 'email-subscribers' ), '<span id="ig-es-broadcast">' . __( 'Broadcast', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_newsletters', array( $this, 'load_newsletters' ) );
178
  add_submenu_page( 'es_dashboard', __( 'Reports', 'email-subscribers' ), __( 'Reports', 'email-subscribers' ), 'edit_posts', 'es_reports', array( $this, 'load_reports' ) );
179
- add_submenu_page( 'es_dashboard', __( 'Audience', 'email-subscribers' ), __( 'Audience', 'email-subscribers' ), 'edit_posts', 'es_subscribers', array( $this, 'load_audience' ) );
180
- add_submenu_page( 'es_dashboard', __( 'Campaigns', 'email-subscribers' ), __( 'Campaigns', 'email-subscribers' ), 'edit_posts', 'es_campaigns', array( $this, 'load_campaigns' ) );
181
  add_submenu_page( 'es_dashboard', __( 'Settings', 'email-subscribers' ), __( 'Settings', 'email-subscribers' ), 'edit_posts', 'es_settings', array( $this, 'load_settings' ) );
182
- add_submenu_page( 'es_dashboard', __( 'Forms', 'email-subscribers' ), __( 'Forms', 'email-subscribers' ), 'edit_posts', 'es_forms', array( $this, 'load_forms' ) );
183
  add_submenu_page( null, __( 'Template Preview', 'email-subscribers' ), __( 'Template Preview', 'email-subscribers' ), 'edit_posts', 'es_template_preview', array( $this, 'load_preview' ) );
184
  }
185
 
@@ -192,7 +204,6 @@ class Email_Subscribers_Admin {
192
  ES_Info::get_instance();
193
  ES_Newsletters::get_instance();
194
  ES_Tools::get_instance();
195
- new ES_Actions();
196
  new ES_Tracking();
197
  }
198
 
@@ -244,9 +255,44 @@ class Email_Subscribers_Admin {
244
  exit();
245
  }
246
 
247
- public function load_lists() {
248
- $list = ES_Lists_Table::get_instance();
249
- $list->es_lists_callback();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  }
251
 
252
  public function load_post_notifications() {
@@ -264,27 +310,11 @@ class Email_Subscribers_Admin {
264
  $reports->es_reports_callback();
265
  }
266
 
267
- public function load_audience() {
268
- $contacts = ES_Subscribers_Table::get_instance();
269
- $contacts->plugin_settings_page();
270
- }
271
-
272
- public function load_campaigns() {
273
- $campaigns = ES_Campaigns_Table::get_instance();
274
- $campaigns->es_campaigns_callback();
275
- }
276
-
277
-
278
  public function load_settings() {
279
  $settings = ES_Admin_Settings::get_instance();
280
  $settings->es_settings_callback();
281
  }
282
 
283
- public function load_forms() {
284
- $forms = ES_Forms_Table::get_instance();
285
- $forms->es_forms_callback();
286
- }
287
-
288
  public function load_preview() {
289
  $preview = ES_Templates_Table::get_instance();
290
  $preview->es_template_preview_callback();
@@ -303,16 +333,16 @@ class Email_Subscribers_Admin {
303
  $email_template = $data['email_template'];
304
  $headers = $data['headers'];
305
 
306
- $result = array( 'status' => 'SUCCESS' );
307
- $ig_es_mailer_settings = get_option('ig_es_mailer_settings');
308
- $mailer = $ig_es_mailer_settings['mailer'];
309
 
310
- $mailer_classname = 'ES_'.ucfirst($mailer).'_Mailer';
311
  $is_mailer_file_exist = ( class_exists( $mailer_classname ) ) ? true : false;
312
- if( $mailer != 'wpmail' && $is_mailer_file_exist ){
313
  $mailer_instance = new $mailer_classname();
314
- $send_mail = $mailer_instance->send( $response, $data );
315
- }else{
316
  $send_mail = wp_mail( $to_email, $subject, $email_template, $headers );
317
  }
318
 
@@ -320,7 +350,7 @@ class Email_Subscribers_Admin {
320
 
321
  $result = array(
322
  'status' => 'ERROR',
323
- 'message' => !empty($send_mail['message']) ? $send_mail['message'] : wp_strip_all_tags( $phpmailer->ErrorInfo )
324
  );
325
 
326
  }
@@ -344,11 +374,13 @@ class Email_Subscribers_Admin {
344
  'edit.php?post_type=es_template',
345
  'es_notifications',
346
  'es_newsletters',
 
 
347
  'es_reports',
348
  'es_tools',
349
  'es_settings',
350
  'es_general_information',
351
- 'es_pricing'
352
  );
353
 
354
  $order = array_flip( $es_menu_order );
@@ -407,7 +439,7 @@ class Email_Subscribers_Admin {
407
 
408
  $emails = ig_es_get_request_data( 'emails', array() );
409
  if ( is_array( $emails ) && count( $emails ) > 0 ) {
410
- $default_list = ES_DB_Lists::get_list_by_name( IG_DEFAULT_LIST );
411
  $list_id = $default_list['id'];
412
  //add to the default list
413
  foreach ( $emails as $email ) {
@@ -478,4 +510,31 @@ class Email_Subscribers_Admin {
478
  die( json_encode( array( 'total' => $total_count ) ) );
479
  }
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  }
47
 
48
  /**
49
  * Initialize the class and set its properties.
50
+ *
51
  * @param string $email_subscribers The name of this plugin.
52
  * @param string $version The version of this plugin.
53
  *
62
  // Reorder ES Submenu
63
  add_filter( 'custom_menu_order', array( $this, 'submenu_order' ) );
64
 
 
65
  add_action( 'admin_menu', array( $this, 'email_subscribers_admin_menu' ) );
66
  add_action( 'wp_ajax_es_klawoo_subscribe', array( $this, 'klawoo_subscribe' ) );
67
  add_action( 'admin_footer', array( $this, 'remove_submenu' ) );
156
  ?>
157
  <script type="text/javascript">
158
  jQuery(document).ready(function () {
159
+ var removeSubmenu = ['ig-es-broadcast', 'ig-es-lists', 'ig-es-post-notifications', 'ig-es-sequence'];
160
  jQuery.each(removeSubmenu, function (key, id) {
161
  jQuery("#" + id).parent('a').parent('li').hide();
162
  });
171
 
172
  // Submenu
173
  add_submenu_page( 'es_dashboard', __( 'Dashboard', 'email-subscribers' ), __( 'Dashboard', 'email-subscribers' ), 'edit_posts', 'es_dashboard', array( $this, 'es_dashboard_callback' ) );
174
+
175
+ // Add Campaigns Submenu
176
+ $hook = add_submenu_page( 'es_dashboard', __( 'Campaigns', 'email-subscribers' ), __( 'Campaigns', 'email-subscribers' ), 'edit_posts', 'es_campaigns', array( $this, 'render_campaigns' ) );
177
+ add_action( "load-$hook", array( 'ES_Campaigns_Table', 'screen_options' ) );
178
+
179
+ // Add Forms Submenu
180
+ $hook = add_submenu_page( 'es_dashboard', __( 'Forms', 'email-subscribers' ), __( 'Forms', 'email-subscribers' ), 'edit_posts', 'es_forms', array( $this, 'render_forms' ) );
181
+ add_action( "load-$hook", array( 'ES_Forms_Table', 'screen_options' ) );
182
+
183
+ // Add Contacts Submenu
184
+ $hook = add_submenu_page( 'es_dashboard', __( 'Audience', 'email-subscribers' ), __( 'Audience', 'email-subscribers' ), 'edit_posts', 'es_subscribers', array( $this, 'render_contacts' ) );
185
+ add_action( "load-$hook", array( 'ES_Contacts_Table', 'screen_options' ) );
186
+
187
+ // Add Lists Submenu
188
+ $hook = add_submenu_page( 'es_dashboard', __( 'Lists', 'email-subscribers' ), '<span id="ig-es-lists">' . __( 'Lists', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_lists', array( $this, 'render_lists' ) );
189
+ add_action( "load-$hook", array( 'ES_Lists_Table', 'screen_options' ) );
190
+
191
  add_submenu_page( 'es_dashboard', __( 'Post Notifications', 'email-subscribers' ), '<span id="ig-es-post-notifications">' . __( 'Post Notifications', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_notifications', array( $this, 'load_post_notifications' ) );
192
  add_submenu_page( 'es_dashboard', __( 'Broadcast', 'email-subscribers' ), '<span id="ig-es-broadcast">' . __( 'Broadcast', 'email-subscribers' ) . '</span>', 'edit_posts', 'es_newsletters', array( $this, 'load_newsletters' ) );
193
  add_submenu_page( 'es_dashboard', __( 'Reports', 'email-subscribers' ), __( 'Reports', 'email-subscribers' ), 'edit_posts', 'es_reports', array( $this, 'load_reports' ) );
 
 
194
  add_submenu_page( 'es_dashboard', __( 'Settings', 'email-subscribers' ), __( 'Settings', 'email-subscribers' ), 'edit_posts', 'es_settings', array( $this, 'load_settings' ) );
 
195
  add_submenu_page( null, __( 'Template Preview', 'email-subscribers' ), __( 'Template Preview', 'email-subscribers' ), 'edit_posts', 'es_template_preview', array( $this, 'load_preview' ) );
196
  }
197
 
204
  ES_Info::get_instance();
205
  ES_Newsletters::get_instance();
206
  ES_Tools::get_instance();
 
207
  new ES_Tracking();
208
  }
209
 
255
  exit();
256
  }
257
 
258
+ /**
259
+ * Render Campaigns Screen
260
+ *
261
+ * @since 4.2.1
262
+ */
263
+ public function render_campaigns() {
264
+ $campaigns = new ES_Campaigns_Table();
265
+ $campaigns->render();
266
+ }
267
+
268
+ /**
269
+ * Render Contacts Screen
270
+ *
271
+ * @since 4.2.1
272
+ */
273
+ public function render_contacts() {
274
+ $campaigns = new ES_Contacts_Table();
275
+ $campaigns->render();
276
+ }
277
+
278
+ /**
279
+ * Render Forms Screen
280
+ *
281
+ * @since 4.2.1
282
+ */
283
+ public function render_forms() {
284
+ $campaigns = new ES_Forms_Table();
285
+ $campaigns->render();
286
+ }
287
+
288
+ /**
289
+ * Render Lists Screen
290
+ *
291
+ * @since 4.2.1
292
+ */
293
+ public function render_lists() {
294
+ $campaigns = new ES_Lists_Table();
295
+ $campaigns->render();
296
  }
297
 
298
  public function load_post_notifications() {
310
  $reports->es_reports_callback();
311
  }
312
 
 
 
 
 
 
 
 
 
 
 
 
313
  public function load_settings() {
314
  $settings = ES_Admin_Settings::get_instance();
315
  $settings->es_settings_callback();
316
  }
317
 
 
 
 
 
 
318
  public function load_preview() {
319
  $preview = ES_Templates_Table::get_instance();
320
  $preview->es_template_preview_callback();
333
  $email_template = $data['email_template'];
334
  $headers = $data['headers'];
335
 
336
+ $result = array( 'status' => 'SUCCESS' );
337
+ $ig_es_mailer_settings = get_option( 'ig_es_mailer_settings' );
338
+ $mailer = $ig_es_mailer_settings['mailer'];
339
 
340
+ $mailer_classname = 'ES_' . ucfirst( $mailer ) . '_Mailer';
341
  $is_mailer_file_exist = ( class_exists( $mailer_classname ) ) ? true : false;
342
+ if ( $mailer != 'wpmail' && $is_mailer_file_exist ) {
343
  $mailer_instance = new $mailer_classname();
344
+ $send_mail = $mailer_instance->send( $response, $data );
345
+ } else {
346
  $send_mail = wp_mail( $to_email, $subject, $email_template, $headers );
347
  }
348
 
350
 
351
  $result = array(
352
  'status' => 'ERROR',
353
+ 'message' => ! empty( $send_mail['message'] ) ? $send_mail['message'] : wp_strip_all_tags( $phpmailer->ErrorInfo )
354
  );
355
 
356
  }
374
  'edit.php?post_type=es_template',
375
  'es_notifications',
376
  'es_newsletters',
377
+ 'es_sequence',
378
+ 'es_integrations',
379
  'es_reports',
380
  'es_tools',
381
  'es_settings',
382
  'es_general_information',
383
+ 'es_pricing',
384
  );
385
 
386
  $order = array_flip( $es_menu_order );
439
 
440
  $emails = ig_es_get_request_data( 'emails', array() );
441
  if ( is_array( $emails ) && count( $emails ) > 0 ) {
442
+ $default_list = ES()->lists_db->get_list_by_name( IG_DEFAULT_LIST );
443
  $list_id = $default_list['id'];
444
  //add to the default list
445
  foreach ( $emails as $email ) {
510
  die( json_encode( array( 'total' => $total_count ) ) );
511
  }
512
 
513
+ /**
514
+ * Hooked to 'set-screen-options' filter
515
+ *
516
+ * @param $status
517
+ * @param $option
518
+ * @param $value
519
+ *
520
+ * @return mixed
521
+ *
522
+ * @since 4.2.1
523
+ */
524
+ public function save_screen_options( $status, $option, $value ) {
525
+
526
+ $ig_es_options = array(
527
+ 'es_campaigns_per_page',
528
+ 'es_contacts_per_page',
529
+ 'es_lists_per_page',
530
+ 'es_forms_per_page'
531
+ );
532
+
533
+ if ( in_array( $option, $ig_es_options ) ) {
534
+ return $value;
535
+ }
536
+
537
+ return $status;
538
+ }
539
+
540
  }
admin/partials/dashboard.php CHANGED
@@ -79,8 +79,8 @@ $current_user_email = $current_user->user_email;
79
  <div class="es-quick-stats" >
80
  <?php $sub_count = ES_DB_Contacts::count_active_subscribers_by_list_id();
81
  $total_forms = ES_DB_Forms::count_forms();
82
- $total_lists = ES_DB_Lists::count_lists();
83
- $total_campaigns = ES_DB_Campaigns::count_campaigns();
84
  ?>
85
  </div>
86
  <div class="es-quick-links-wrapper" >
79
  <div class="es-quick-stats" >
80
  <?php $sub_count = ES_DB_Contacts::count_active_subscribers_by_list_id();
81
  $total_forms = ES_DB_Forms::count_forms();
82
+ $total_lists = ES()->lists_db->count_lists();
83
+ $total_campaigns = ES()->campaigns_db->get_total_campaigns();
84
  ?>
85
  </div>
86
  <div class="es-quick-links-wrapper" >
email-subscribers.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Email Subscribers & Newsletters
4
  * Plugin URI: https://www.icegram.com/
5
  * Description: Add subscription forms on website, send HTML newsletters & automatically notify subscribers about new blog posts once it is published.
6
- * Version: 4.2.0
7
  * Author: Icegram
8
  * Author URI: https://www.icegram.com/
9
  * Requires at least: 3.9
@@ -23,8 +23,12 @@ if ( ! defined( 'WPINC' ) ) {
23
  /**
24
  * Define constants
25
  */
26
- define( 'ES_PLUGIN_DIR', dirname( __FILE__ ) );
27
- define( 'ES_PLUGIN_VERSION', '4.2.0' );
 
 
 
 
28
  define( 'ES_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
29
  define( 'IG_ES_FEEDBACK_VERSION', '1.0.10' );
30
 
@@ -135,4 +139,18 @@ function run_email_subscribers() {
135
  $plugin->run();
136
  }
137
 
138
- run_email_subscribers();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  * Plugin Name: Email Subscribers & Newsletters
4
  * Plugin URI: https://www.icegram.com/
5
  * Description: Add subscription forms on website, send HTML newsletters & automatically notify subscribers about new blog posts once it is published.
6
+ * Version: 4.2.1
7
  * Author: Icegram
8
  * Author URI: https://www.icegram.com/
9
  * Requires at least: 3.9
23
  /**
24
  * Define constants
25
  */
26
+ //define( 'ES_PLUGIN_DIR', dirname( __FILE__ ) );
27
+ // Plugin Folder Path.
28
+ if ( ! defined( 'ES_PLUGIN_DIR' ) ) {
29
+ define( 'ES_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
30
+ }
31
+ define( 'ES_PLUGIN_VERSION', '4.2.1' );
32
  define( 'ES_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
33
  define( 'IG_ES_FEEDBACK_VERSION', '1.0.10' );
34
 
139
  $plugin->run();
140
  }
141
 
142
+ //run_email_subscribers();
143
+
144
+ /**
145
+ * @return Email_Subscribers
146
+ *
147
+ * @since 4.2.1
148
+ */
149
+ function ES() {
150
+ return Email_Subscribers::instance();
151
+ }
152
+
153
+ // Start ES
154
+ ES();
155
+
156
+ ES()->run();
includes/admin/class-es-actions.php CHANGED
@@ -19,16 +19,27 @@ if ( ! class_exists( 'ES_Actions' ) ) {
19
  * IG_MESSAGE_HARD_BOUNCE => 7,
20
  * IG_MESSAGE_ERROR => 8
21
  *
22
- *
23
  * @since 4.2.0
24
  */
25
  class ES_Actions {
 
 
 
 
 
 
 
 
 
26
  /**
27
  * ES_Actions constructor.
28
  *
29
  * @since 4.2.0
30
  */
31
  public function __construct() {
 
 
 
32
  add_action( 'init', array( &$this, 'init' ), 1 );
33
  }
34
 
@@ -40,7 +51,7 @@ if ( ! class_exists( 'ES_Actions' ) ) {
40
  * @since 4.2.0
41
  */
42
  add_action( 'ig_es_contact_subscribe', array( &$this, 'subscribe' ), 10, 2 );
43
- add_action( 'ig_es_message_sent', array( &$this, 'sent' ), 10, 2 );
44
  add_action( 'ig_es_message_open', array( &$this, 'open' ), 10, 3 );
45
  add_action( 'ig_es_message_click', array( &$this, 'click' ), 10, 4 );
46
  add_action( 'ig_es_contact_unsubscribe', array( &$this, 'unsubscribe' ), 10, 4 );
@@ -139,7 +150,7 @@ if ( ! class_exists( 'ES_Actions' ) ) {
139
  *
140
  * @since 4.2.0
141
  */
142
- public function subscribe( $contact_id, $list_ids = array(), $explicit = true ) {
143
  if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
144
  foreach ( $list_ids as $list_id ) {
145
  $this->add_action( array(
@@ -149,6 +160,7 @@ if ( ! class_exists( 'ES_Actions' ) ) {
149
  ) );
150
  }
151
  }
 
152
  }
153
 
154
  /**
@@ -162,10 +174,11 @@ if ( ! class_exists( 'ES_Actions' ) ) {
162
  *
163
  * @since 4.2.0
164
  */
165
- public function sent( $contact_id, $campaign_id ) {
166
  return $this->add_action( array(
167
  'contact_id' => $contact_id,
168
  'campaign_id' => $campaign_id,
 
169
  'type' => IG_MESSAGE_SENT,
170
  ) );
171
  }
19
  * IG_MESSAGE_HARD_BOUNCE => 7,
20
  * IG_MESSAGE_ERROR => 8
21
  *
 
22
  * @since 4.2.0
23
  */
24
  class ES_Actions {
25
+ /**
26
+ * ES_DB_Actions object
27
+ *
28
+ * @since 4.2.1
29
+ * @var $db
30
+ *
31
+ */
32
+ protected $db;
33
+
34
  /**
35
  * ES_Actions constructor.
36
  *
37
  * @since 4.2.0
38
  */
39
  public function __construct() {
40
+
41
+ $this->db = new ES_DB_Actions();
42
+
43
  add_action( 'init', array( &$this, 'init' ), 1 );
44
  }
45
 
51
  * @since 4.2.0
52
  */
53
  add_action( 'ig_es_contact_subscribe', array( &$this, 'subscribe' ), 10, 2 );
54
+ add_action( 'ig_es_message_sent', array( &$this, 'sent' ), 10, 3 );
55
  add_action( 'ig_es_message_open', array( &$this, 'open' ), 10, 3 );
56
  add_action( 'ig_es_message_click', array( &$this, 'click' ), 10, 4 );
57
  add_action( 'ig_es_contact_unsubscribe', array( &$this, 'unsubscribe' ), 10, 4 );
150
  *
151
  * @since 4.2.0
152
  */
153
+ public function subscribe( $contact_id, $list_ids = array() ) {
154
  if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
155
  foreach ( $list_ids as $list_id ) {
156
  $this->add_action( array(
160
  ) );
161
  }
162
  }
163
+
164
  }
165
 
166
  /**
174
  *
175
  * @since 4.2.0
176
  */
177
+ public function sent( $contact_id, $campaign_id = 0, $message_id = 0 ) {
178
  return $this->add_action( array(
179
  'contact_id' => $contact_id,
180
  'campaign_id' => $campaign_id,
181
+ 'message_id' => $message_id,
182
  'type' => IG_MESSAGE_SENT,
183
  ) );
184
  }
includes/admin/class-es-campaigns-table.php CHANGED
@@ -10,9 +10,18 @@ if ( ! class_exists( 'WP_List_Table' ) ) {
10
  }
11
 
12
  class ES_Campaigns_Table extends WP_List_Table {
 
 
 
 
 
 
13
 
14
- static $instance;
15
-
 
 
 
16
  public function __construct() {
17
 
18
  parent::__construct( array(
@@ -21,28 +30,32 @@ class ES_Campaigns_Table extends WP_List_Table {
21
  'ajax' => false, //does this table support ajax?
22
  'screen' => 'es_campaigns'
23
  ) );
24
-
25
- add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
26
  }
27
 
28
- public function set_screen( $status, $option, $value ) {
29
- return $value;
30
- }
31
-
32
- public function screen_option() {
 
33
 
34
  $option = 'per_page';
35
  $args = array(
36
- 'label' => __( 'Campaigns', 'email-subscribers' ),
37
  'default' => 20,
38
- 'option' => 'campaigns_per_page'
39
  );
40
 
41
  add_screen_option( $option, $args );
42
- }
43
 
44
- public function es_campaigns_callback() {
45
 
 
 
 
 
 
 
46
  $action = ig_es_get_request_data( 'action' );
47
 
48
  ?>
@@ -50,7 +63,9 @@ class ES_Campaigns_Table extends WP_List_Table {
50
  <h1 class="wp-heading-inline"><?php _e( 'Campaigns', 'email-subscribers' ) ?>
51
  <a href="admin.php?page=es_notifications&action=new" class="page-title-action"><?php _e( 'Create Post Notification', 'email-subscribers' ) ?></a>
52
  <a href="admin.php?page=es_newsletters" class="page-title-action"><?php _e( 'Send Broadcast', 'email-subscribers' ) ?></a>
53
- <a href="edit.php?post_type=es_template" class="page-title-action es-imp-button"><?php _e( 'Manage Templates', 'email-subscribers' ) ?></a></h1>
 
 
54
  <?php Email_Subscribers_Admin::es_feedback(); ?>
55
  <div id="poststuff">
56
  <div id="post-body" class="metabox-holder column-1">
@@ -105,11 +120,14 @@ class ES_Campaigns_Table extends WP_List_Table {
105
 
106
  $query[] = "( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' )";
107
 
 
108
  if ( ! empty( $search ) ) {
109
  $query[] = " name LIKE %s ";
110
  $args[] = "%" . $wpdb->esc_like( $search ) . "%";
111
  }
112
 
 
 
113
  if ( $add_where_clause ) {
114
  $sql .= " WHERE ";
115
 
@@ -153,26 +171,14 @@ class ES_Campaigns_Table extends WP_List_Table {
153
  }
154
 
155
  /**
156
- * Returns the count of records in the database.
157
  *
158
- * @return null|string
159
  */
160
- public function record_count() {
161
- global $wpdb;
162
-
163
- $campaigns_table = IG_CAMPAIGNS_TABLE;
164
- $sql = "SELECT COUNT(*) FROM {$campaigns_table}";
165
-
166
- return $wpdb->get_var( $sql );
167
- }
168
-
169
-
170
- /** Text displayed when no list data is available */
171
  public function no_items() {
172
  _e( 'No Campaigns Found.', 'email-subscribers' );
173
  }
174
 
175
-
176
  /**
177
  * Render a column when no column specific method exist.
178
  *
@@ -186,7 +192,7 @@ class ES_Campaigns_Table extends WP_List_Table {
186
 
187
  case 'list_ids':
188
  if ( ! empty( $item[ $column_name ] ) ) {
189
- return ES_DB_Lists::get_list_id_name_map( $item[ $column_name ] );
190
  } else {
191
  return '-';
192
  }
@@ -252,10 +258,10 @@ class ES_Campaigns_Table extends WP_List_Table {
252
  if ( $template instanceof WP_Post ) {
253
  $title = '<strong>' . $template->post_title . '</strong>';
254
  } else {
255
- $title = '';
256
  }
257
 
258
- $slug = esc_attr( 'es_notifications' );
259
 
260
  $actions ['edit'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), $slug, 'edit', absint( $item['id'] ), $nonce );
261
  $actions['delete'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( 'es_campaigns' ), 'delete', absint( $item['id'] ), $nonce );
@@ -339,7 +345,8 @@ class ES_Campaigns_Table extends WP_List_Table {
339
  $search = ig_es_get_request_data( 's' );
340
  $this->search_box( $search, 'notification-search-input' );
341
 
342
- $per_page = $this->get_items_per_page( 'campaigns_per_page', 25 );
 
343
  $current_page = $this->get_pagenum();
344
  $total_items = $this->get_lists( 0, 0, true );
345
 
@@ -404,7 +411,7 @@ class ES_Campaigns_Table extends WP_List_Table {
404
  public function delete_list( $ids ) {
405
  global $wpdb;
406
 
407
- if ( is_array($ids) && count( $ids ) > 0 ) {
408
 
409
  $campaigns_table = IG_CAMPAIGNS_TABLE;
410
 
@@ -423,12 +430,4 @@ class ES_Campaigns_Table extends WP_List_Table {
423
  return false;
424
  }
425
 
426
- public static function get_instance() {
427
- if ( ! isset( self::$instance ) ) {
428
- self::$instance = new self();
429
- }
430
-
431
- return self::$instance;
432
- }
433
-
434
  }
10
  }
11
 
12
  class ES_Campaigns_Table extends WP_List_Table {
13
+ /**
14
+ * @since 4.2.1
15
+ * @var string
16
+ *
17
+ */
18
+ public static $option_per_page = 'es_campaigns_per_page';
19
 
20
+ /**
21
+ * ES_Campaigns_Table constructor.
22
+ *
23
+ * @since 4.0
24
+ */
25
  public function __construct() {
26
 
27
  parent::__construct( array(
30
  'ajax' => false, //does this table support ajax?
31
  'screen' => 'es_campaigns'
32
  ) );
 
 
33
  }
34
 
35
+ /**
36
+ * Add Screen Option
37
+ *
38
+ * @since 4.2.1
39
+ */
40
+ public static function screen_options() {
41
 
42
  $option = 'per_page';
43
  $args = array(
44
+ 'label' => __( 'Number of campaigns per page', 'email-subscribers' ),
45
  'default' => 20,
46
+ 'option' => self::$option_per_page
47
  );
48
 
49
  add_screen_option( $option, $args );
 
50
 
51
+ }
52
 
53
+ /**
54
+ * Render Campaigns table
55
+ *
56
+ * @since 4.0
57
+ */
58
+ public function render() {
59
  $action = ig_es_get_request_data( 'action' );
60
 
61
  ?>
63
  <h1 class="wp-heading-inline"><?php _e( 'Campaigns', 'email-subscribers' ) ?>
64
  <a href="admin.php?page=es_notifications&action=new" class="page-title-action"><?php _e( 'Create Post Notification', 'email-subscribers' ) ?></a>
65
  <a href="admin.php?page=es_newsletters" class="page-title-action"><?php _e( 'Send Broadcast', 'email-subscribers' ) ?></a>
66
+ <?php do_action( 'ig_es_after_campaign_type_buttons' ) ?>
67
+ <a href="edit.php?post_type=es_template" class="page-title-action es-imp-button"><?php _e( 'Manage Templates', 'email-subscribers' ) ?></a>
68
+ </h1>
69
  <?php Email_Subscribers_Admin::es_feedback(); ?>
70
  <div id="poststuff">
71
  <div id="post-body" class="metabox-holder column-1">
120
 
121
  $query[] = "( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' )";
122
 
123
+
124
  if ( ! empty( $search ) ) {
125
  $query[] = " name LIKE %s ";
126
  $args[] = "%" . $wpdb->esc_like( $search ) . "%";
127
  }
128
 
129
+ $query = apply_filters( 'ig_es_campaign_list_where_caluse', $query );
130
+
131
  if ( $add_where_clause ) {
132
  $sql .= " WHERE ";
133
 
171
  }
172
 
173
  /**
174
+ * Text Display when no items available
175
  *
176
+ * @since 4.0
177
  */
 
 
 
 
 
 
 
 
 
 
 
178
  public function no_items() {
179
  _e( 'No Campaigns Found.', 'email-subscribers' );
180
  }
181
 
 
182
  /**
183
  * Render a column when no column specific method exist.
184
  *
192
 
193
  case 'list_ids':
194
  if ( ! empty( $item[ $column_name ] ) ) {
195
+ return ES()->lists_db->get_list_id_name_map( $item[ $column_name ] );
196
  } else {
197
  return '-';
198
  }
258
  if ( $template instanceof WP_Post ) {
259
  $title = '<strong>' . $template->post_title . '</strong>';
260
  } else {
261
+ $title = ! empty( $item['name'] ) ? $item['name'] : '';
262
  }
263
 
264
+ $slug = ( in_array( $item['type'], array( 'post_notification', 'post_digets' ) ) ) ? esc_attr( 'es_notifications' ) : 'es_' . $item['type'];
265
 
266
  $actions ['edit'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s">Edit</a>', 'email-subscribers' ), $slug, 'edit', absint( $item['id'] ), $nonce );
267
  $actions['delete'] = sprintf( __( '<a href="?page=%s&action=%s&list=%s&_wpnonce=%s" onclick="return checkDelete()">Delete</a>', 'email-subscribers' ), esc_attr( 'es_campaigns' ), 'delete', absint( $item['id'] ), $nonce );
345
  $search = ig_es_get_request_data( 's' );
346
  $this->search_box( $search, 'notification-search-input' );
347
 
348
+ $per_page = $this->get_items_per_page( self::$option_per_page, 25 );
349
+
350
  $current_page = $this->get_pagenum();
351
  $total_items = $this->get_lists( 0, 0, true );
352
 
411
  public function delete_list( $ids ) {
412
  global $wpdb;
413
 
414
+ if ( is_array( $ids ) && count( $ids ) > 0 ) {
415
 
416
  $campaigns_table = IG_CAMPAIGNS_TABLE;
417
 
430
  return false;
431
  }
432
 
 
 
 
 
 
 
 
 
433
  }
includes/admin/{class-es-subscribers-table.php → class-es-contacts-table.php} RENAMED
@@ -9,12 +9,17 @@ if ( ! class_exists( 'WP_List_Table' ) ) {
9
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
10
  }
11
 
12
- class ES_Subscribers_Table extends WP_List_Table {
13
-
14
- static $instance;
15
 
16
  public $contact_lists_statuses = array();
17
 
 
 
 
 
 
 
 
18
  public $list_ids = array();
19
 
20
  public $lists_id_name_map = array();
@@ -29,12 +34,36 @@ class ES_Subscribers_Table extends WP_List_Table {
29
  'screen' => 'es_subscribers'
30
  ) );
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
34
- add_filter( 'ig_es_audience_tab_main_navigation', array( $this, 'get_audience_main_tabs' ), 10, 3 );
35
  }
36
 
37
- public function get_audience_main_tabs( $active_tab, $audience_main_tabs ) {
 
 
38
 
39
  $audience_tab_main_navigation = array(
40
  'new_contact' => array(
@@ -85,18 +114,20 @@ class ES_Subscribers_Table extends WP_List_Table {
85
  );
86
 
87
  $audience_main_tabs = $audience_main_tabs + $audience_tab_main_navigation;
88
- if ( ! empty( $active_tab ) ) {
 
89
  unset( $audience_main_tabs[ $active_tab ] );
90
  }
91
 
92
  return $audience_main_tabs;
93
  }
94
 
95
- public function set_screen( $status, $option, $value ) {
96
- return $value;
97
- }
98
-
99
- public function plugin_settings_page() {
 
100
 
101
  ?>
102
  <div class="wrap">
@@ -164,24 +195,6 @@ class ES_Subscribers_Table extends WP_List_Table {
164
  $sync->prepare_sync_user();
165
  }
166
 
167
- public function manage_lists() {
168
- $list = ES_Lists_Table::get_instance();
169
- $list->es_lists_callback();
170
- }
171
-
172
- public function screen_option() {
173
-
174
- $option = 'per_page';
175
- $args = array(
176
- 'label' => __( 'Contacts', 'email-subscribers' ),
177
- 'default' => 150,
178
- 'option' => 'subscribers_per_page'
179
- );
180
-
181
- add_screen_option( $option, $args );
182
-
183
- }
184
-
185
  public function save_contact( $id = 0 ) {
186
  global $wpdb;
187
 
@@ -525,7 +538,7 @@ class ES_Subscribers_Table extends WP_List_Table {
525
  $selected_list_ids = ! empty( $data['selected_list_ids'] ) ? $data['selected_list_ids'] : array();
526
  $send_welcome_email = ! empty( $data['send_welcome_email'] ) ? true : false;
527
 
528
- $lists_id_name_map = ES_DB_Lists::get_list_id_name_map();
529
 
530
  if ( count( $lists_id_name_map ) ) {
531
  $list_html = ES_Shortcode::prepare_lists_checkboxes( $lists_id_name_map, array_keys( $lists_id_name_map ), 4, $selected_list_ids, $id, 'contact_data[lists][]' );
@@ -749,14 +762,12 @@ class ES_Subscribers_Table extends WP_List_Table {
749
  return $columns;
750
  }
751
 
752
-
753
  /**
754
  * Columns to make sortable.
755
  *
756
  * @return array
757
  */
758
- public
759
- function get_sortable_columns() {
760
  $sortable_columns = array(
761
  'name' => array( 'first_name', true ),
762
  'email' => array( 'email', false ),
@@ -772,8 +783,7 @@ class ES_Subscribers_Table extends WP_List_Table {
772
  *
773
  * @return array
774
  */
775
- public
776
- function get_bulk_actions() {
777
  $actions = array(
778
  'bulk_delete' => __( 'Delete', 'email-subscribers' ),
779
  'bulk_list_update' => __( 'Move To List', 'email-subscribers' ),
@@ -785,11 +795,9 @@ class ES_Subscribers_Table extends WP_List_Table {
785
  }
786
 
787
 
788
- public
789
- function search_box(
790
- $text,
791
- $input_id
792
- ) { ?>
793
  <p class="search-box box-ma10">
794
  <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
795
  <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
@@ -814,8 +822,7 @@ class ES_Subscribers_Table extends WP_List_Table {
814
  /**
815
  * Handles data query and filter, sorting, and pagination.
816
  */
817
- public
818
- function prepare_items() {
819
 
820
  $this->_column_headers = $this->get_column_info();
821
 
@@ -825,7 +832,7 @@ class ES_Subscribers_Table extends WP_List_Table {
825
  $this->edit_group();
826
  $this->edit_status();
827
 
828
- $per_page = $this->get_items_per_page( 'contacts_per_page', 200 );
829
  $current_page = $this->get_pagenum();
830
  $total_items = $this->get_subscribers( 0, 0, true );
831
 
@@ -847,22 +854,20 @@ class ES_Subscribers_Table extends WP_List_Table {
847
 
848
  $this->contact_lists_statuses = $contact_lists_statuses;
849
 
850
- $lists_id_name_map = ES_DB_Lists::get_list_id_name_map();
851
 
852
  $this->lists_id_name_map = $lists_id_name_map;
853
 
854
  }
855
  }
856
 
857
- public
858
- function get_contact_id(
859
  $contact
860
  ) {
861
  return $contact['id'];
862
  }
863
 
864
- public
865
- function edit_group() {
866
  $data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="list_id" id="list_id" class="groupsselect" style="display: none">';
867
  $data .= ES_Common::prepare_list_dropdown_options();
868
  $data .= '</select>';
@@ -870,8 +875,7 @@ class ES_Subscribers_Table extends WP_List_Table {
870
  echo $data;
871
  }
872
 
873
- public
874
- function edit_status() {
875
  $data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="status_select" id="status_select" class="statusesselect" style="display:none;">';
876
  $data .= ES_Common::prepare_statuses_dropdown_options();
877
  $data .= '</select>';
@@ -879,8 +883,7 @@ class ES_Subscribers_Table extends WP_List_Table {
879
  echo $data;
880
  }
881
 
882
- public
883
- function process_bulk_action() {
884
 
885
  //Detect when a bulk action is being triggered...
886
  if ( 'delete' === $this->current_action() ) {
@@ -1027,17 +1030,7 @@ class ES_Subscribers_Table extends WP_List_Table {
1027
  }
1028
  }
1029
 
1030
- public
1031
- function no_items() {
1032
  _e( 'No contacts avaliable.', 'email-subscribers' );
1033
  }
1034
-
1035
- public
1036
- static function get_instance() {
1037
- if ( ! isset( self::$instance ) ) {
1038
- self::$instance = new self();
1039
- }
1040
-
1041
- return self::$instance;
1042
- }
1043
  }
9
  require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
10
  }
11
 
12
+ class ES_Contacts_Table extends WP_List_Table {
 
 
13
 
14
  public $contact_lists_statuses = array();
15
 
16
+ /**
17
+ * @since 4.2.1
18
+ * @var string
19
+ *
20
+ */
21
+ public static $option_per_page = 'es_contacts_per_page';
22
+
23
  public $list_ids = array();
24
 
25
  public $lists_id_name_map = array();
34
  'screen' => 'es_subscribers'
35
  ) );
36
 
37
+ add_filter( 'ig_es_audience_tab_main_navigation', array( $this, 'get_audience_main_tabs' ), 10, 2 );
38
+ }
39
+
40
+ /**
41
+ * Add Screen Option
42
+ *
43
+ * @since 4.2.1
44
+ */
45
+ public static function screen_options() {
46
+
47
+ // Don't show screen option on Import/ Export subscribers page.
48
+ $action = ig_es_get_request_data( 'action' );
49
+
50
+ if ( '' === $action ) {
51
+
52
+ $option = 'per_page';
53
+ $args = array(
54
+ 'label' => __( 'Number of contacts per page', 'email-subscribers' ),
55
+ 'default' => 100,
56
+ 'option' => self::$option_per_page
57
+ );
58
+
59
+ add_screen_option( $option, $args );
60
+ }
61
 
 
 
62
  }
63
 
64
+
65
+
66
+ public function get_audience_main_tabs( $active_tab, $audience_main_tabs = array() ) {
67
 
68
  $audience_tab_main_navigation = array(
69
  'new_contact' => array(
114
  );
115
 
116
  $audience_main_tabs = $audience_main_tabs + $audience_tab_main_navigation;
117
+
118
+ if ( ! empty( $active_tab ) && isset( $audience_main_tabs[ $active_tab ] ) ) {
119
  unset( $audience_main_tabs[ $active_tab ] );
120
  }
121
 
122
  return $audience_main_tabs;
123
  }
124
 
125
+ /**
126
+ * Render Audience View
127
+ *
128
+ * @since 4.2.1
129
+ */
130
+ public function render() {
131
 
132
  ?>
133
  <div class="wrap">
195
  $sync->prepare_sync_user();
196
  }
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  public function save_contact( $id = 0 ) {
199
  global $wpdb;
200
 
538
  $selected_list_ids = ! empty( $data['selected_list_ids'] ) ? $data['selected_list_ids'] : array();
539
  $send_welcome_email = ! empty( $data['send_welcome_email'] ) ? true : false;
540
 
541
+ $lists_id_name_map = ES()->lists_db->get_list_id_name_map();
542
 
543
  if ( count( $lists_id_name_map ) ) {
544
  $list_html = ES_Shortcode::prepare_lists_checkboxes( $lists_id_name_map, array_keys( $lists_id_name_map ), 4, $selected_list_ids, $id, 'contact_data[lists][]' );
762
  return $columns;
763
  }
764
 
 
765
  /**
766
  * Columns to make sortable.
767
  *
768
  * @return array
769
  */
770
+ public function get_sortable_columns() {
 
771
  $sortable_columns = array(
772
  'name' => array( 'first_name', true ),
773
  'email' => array( 'email', false ),
783
  *
784
  * @return array
785
  */
786
+ public function get_bulk_actions() {
 
787
  $actions = array(
788
  'bulk_delete' => __( 'Delete', 'email-subscribers' ),
789
  'bulk_list_update' => __( 'Move To List', 'email-subscribers' ),
795
  }
796
 
797
 
798
+ public function search_box( $text, $input_id ) {
799
+
800
+ ?>
 
 
801
  <p class="search-box box-ma10">
802
  <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
803
  <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>"/>
822
  /**
823
  * Handles data query and filter, sorting, and pagination.
824
  */
825
+ public function prepare_items() {
 
826
 
827
  $this->_column_headers = $this->get_column_info();
828
 
832
  $this->edit_group();
833
  $this->edit_status();
834
 
835
+ $per_page = $this->get_items_per_page( self::$option_per_page, 200 );
836
  $current_page = $this->get_pagenum();
837
  $total_items = $this->get_subscribers( 0, 0, true );
838
 
854
 
855
  $this->contact_lists_statuses = $contact_lists_statuses;
856
 
857
+ $lists_id_name_map = ES()->lists_db->get_list_id_name_map();
858
 
859
  $this->lists_id_name_map = $lists_id_name_map;
860
 
861
  }
862
  }
863
 
864
+ public function get_contact_id(
 
865
  $contact
866
  ) {
867
  return $contact['id'];
868
  }
869
 
870
+ public function edit_group() {
 
871
  $data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="list_id" id="list_id" class="groupsselect" style="display: none">';
872
  $data .= ES_Common::prepare_list_dropdown_options();
873
  $data .= '</select>';
875
  echo $data;
876
  }
877
 
878
+ public function edit_status() {
 
879
  $data = '<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label><select name="status_select" id="status_select" class="statusesselect" style="display:none;">';
880
  $data .= ES_Common::prepare_statuses_dropdown_options();
881
  $data .= '</select>';
883
  echo $data;
884
  }
885
 
886
+ public function process_bulk_action() {
 
887
 
888
  //Detect when a bulk action is being triggered...
889
  if ( 'delete' === $this->current_action() ) {
1030
  }
1031
  }
1032
 
1033
+ public function no_items() {
 
1034
  _e( 'No contacts avaliable.', 'email-subscribers' );
1035
  }
 
 
 
 
 
 
 
 
 
1036
  }
includes/admin/class-es-cron.php CHANGED
@@ -64,6 +64,9 @@ class ES_Cron {
64
  // Queue Auto Responder
65
  do_action('ig_es_cron_auto_responder');
66
 
 
 
 
67
  $es_process_request = true;
68
 
69
  // filter request
64
  // Queue Auto Responder
65
  do_action('ig_es_cron_auto_responder');
66
 
67
+ // Worker
68
+ do_action('ig_es_cron_worker');
69
+
70
  $es_process_request = true;
71
 
72
  // filter request
includes/admin/class-es-export-subscribers.php CHANGED
@@ -300,7 +300,7 @@ class Export_Subscribers {
300
  __( 'Created On', 'email-subscribers' )
301
  );
302
 
303
- $lists_id_name_map = ES_DB_Lists::get_list_id_name_map();
304
  $csv_output .= '"' . implode( '", "', $headers ) . '"';
305
  $csv_output .= "\n";
306
 
300
  __( 'Created On', 'email-subscribers' )
301
  );
302
 
303
+ $lists_id_name_map = ES()->lists_db->get_list_id_name_map();
304
  $csv_output .= '"' . implode( '", "', $headers ) . '"';
305
  $csv_output .= "\n";
306
 
includes/admin/class-es-forms-table.php CHANGED
@@ -11,8 +11,18 @@ if ( ! class_exists( 'WP_List_Table' ) ) {
11
 
12
  class ES_Forms_Table extends WP_List_Table {
13
 
14
- static $instance;
 
 
 
 
 
15
 
 
 
 
 
 
16
  public function __construct() {
17
 
18
  parent::__construct( array(
@@ -21,15 +31,32 @@ class ES_Forms_Table extends WP_List_Table {
21
  'ajax' => false, //does this table support ajax?,
22
  'screen' => 'es_forms'
23
  ) );
24
-
25
- add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
26
  }
27
 
28
- public function set_screen( $status, $option, $value ) {
29
- return $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
- public function es_forms_callback() {
 
 
 
 
 
 
33
 
34
  $action = ig_es_get_request_data( 'action' );
35
  ?>
@@ -61,19 +88,6 @@ class ES_Forms_Table extends WP_List_Table {
61
  <?php }
62
  }
63
 
64
- public function screen_option() {
65
-
66
- $option = 'per_page';
67
- $args = array(
68
- 'label' => __( 'Forms', 'email-subscribers' ),
69
- 'default' => 10,
70
- 'option' => 'forms_per_page'
71
- );
72
-
73
- add_screen_option( $option, $args );
74
-
75
- }
76
-
77
  public function validate_data( $data ) {
78
 
79
  $nonce = $data['nonce'];
@@ -220,7 +234,7 @@ class ES_Forms_Table extends WP_List_Table {
220
  $form_data['af_id'] = ! empty( $data['af_id'] ) ? $data['af_id'] : 0;
221
  $form_data['desc'] = ! empty( $data['desc'] ) ? sanitize_text_field( $data['desc'] ) : '';
222
 
223
- $lists = ES_DB_Lists::get_list_id_name_map();
224
  $nonce = wp_create_nonce( 'es_form' );
225
 
226
  ?>
@@ -739,7 +753,7 @@ class ES_Forms_Table extends WP_List_Table {
739
  $search_str = ig_es_get_request_data( 's' );
740
  $this->search_box( $search_str, 'form-search-input' );
741
 
742
- $per_page = $this->get_items_per_page( 'forms_per_page', 25 );
743
  $current_page = $this->get_pagenum();
744
  $total_items = $this->get_lists( 0, 0, true );
745
 
@@ -810,12 +824,4 @@ class ES_Forms_Table extends WP_List_Table {
810
  public function no_items() {
811
  _e( 'No Forms avaliable.', 'email-subscribers' );
812
  }
813
-
814
- public static function get_instance() {
815
- if ( ! isset( self::$instance ) ) {
816
- self::$instance = new self();
817
- }
818
-
819
- return self::$instance;
820
- }
821
  }
11
 
12
  class ES_Forms_Table extends WP_List_Table {
13
 
14
+ /**
15
+ * @var string
16
+ *
17
+ * @since 4.2.1
18
+ */
19
+ public static $option_per_page = 'es_forms_per_page';
20
 
21
+ /**
22
+ * ES_Forms_Table constructor.
23
+ *
24
+ * @since 4.0
25
+ */
26
  public function __construct() {
27
 
28
  parent::__construct( array(
31
  'ajax' => false, //does this table support ajax?,
32
  'screen' => 'es_forms'
33
  ) );
 
 
34
  }
35
 
36
+ /**
37
+ * Add Screen Option
38
+ *
39
+ * @since 4.2.1
40
+ */
41
+ public static function screen_options() {
42
+
43
+ $option = 'per_page';
44
+ $args = array(
45
+ 'label' => __( 'Number of forms per page', 'email-subscribers' ),
46
+ 'default' => 20,
47
+ 'option' => self::$option_per_page
48
+ );
49
+
50
+ add_screen_option( $option, $args );
51
  }
52
 
53
+
54
+ /**
55
+ * Render Forms list view
56
+ *
57
+ * @since 4.0
58
+ */
59
+ public function render() {
60
 
61
  $action = ig_es_get_request_data( 'action' );
62
  ?>
88
  <?php }
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  public function validate_data( $data ) {
92
 
93
  $nonce = $data['nonce'];
234
  $form_data['af_id'] = ! empty( $data['af_id'] ) ? $data['af_id'] : 0;
235
  $form_data['desc'] = ! empty( $data['desc'] ) ? sanitize_text_field( $data['desc'] ) : '';
236
 
237
+ $lists = ES()->lists_db->get_list_id_name_map();
238
  $nonce = wp_create_nonce( 'es_form' );
239
 
240
  ?>
753
  $search_str = ig_es_get_request_data( 's' );
754
  $this->search_box( $search_str, 'form-search-input' );
755
 
756
+ $per_page = $this->get_items_per_page( self::$option_per_page, 25 );
757
  $current_page = $this->get_pagenum();
758
  $total_items = $this->get_lists( 0, 0, true );
759
 
824
  public function no_items() {
825
  _e( 'No Forms avaliable.', 'email-subscribers' );
826
  }
 
 
 
 
 
 
 
 
827
  }
includes/admin/class-es-handle-post-notification.php CHANGED
@@ -251,7 +251,7 @@ class ES_Handle_Post_Notification {
251
  $campaign_id = $args['campaign_id'];
252
  $post_id = $args['post_id'];
253
  $post = get_post( $post_id );
254
- $template_id = ES_DB_Campaigns::get_templateid_by_campaign( $campaign_id );
255
  $template = get_post( $template_id );
256
  $template_content = $template->post_content;
257
  $content['subject'] = self::prepare_subject( $post, $template );
251
  $campaign_id = $args['campaign_id'];
252
  $post_id = $args['post_id'];
253
  $post = get_post( $post_id );
254
+ $template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
255
  $template = get_post( $template_id );
256
  $template_content = $template->post_content;
257
  $content['subject'] = self::prepare_subject( $post, $template );
includes/admin/class-es-handle-subscription.php CHANGED
@@ -126,7 +126,8 @@ class ES_Handle_Subscription {
126
 
127
  $contact_id = ES_DB_Contacts::add_subscriber( $data );
128
 
129
- do_action( 'ig_es_contact_added', $data );
 
130
  }
131
 
132
  if ( count( $this->list_ids ) > 0 ) {
@@ -149,6 +150,10 @@ class ES_Handle_Subscription {
149
  ES_DB_Lists_Contacts::add_lists_contacts( $list_contact_data );
150
 
151
  if ( $contact_id ) {
 
 
 
 
152
  $this->db_id = $contact_id;
153
  if ( $this->is_double_optin ) {
154
  $this->send_double_optin_notification();
@@ -249,7 +254,7 @@ class ES_Handle_Subscription {
249
 
250
  $admin_emails = explode( ',', $admin_email_addresses );
251
 
252
- $list_id_name_map = ES_DB_Lists::get_list_id_name_map();
253
 
254
  $list_name = '';
255
  if ( count( $this->list_ids ) > 0 ) {
126
 
127
  $contact_id = ES_DB_Contacts::add_subscriber( $data );
128
 
129
+ //do_action( 'ig_es_contact_added', $data);
130
+
131
  }
132
 
133
  if ( count( $this->list_ids ) > 0 ) {
150
  ES_DB_Lists_Contacts::add_lists_contacts( $list_contact_data );
151
 
152
  if ( $contact_id ) {
153
+
154
+ error_log('Firing ig_es_contact_subscribe');
155
+ do_action( 'ig_es_contact_subscribe', $contact_id, $this->list_ids );
156
+
157
  $this->db_id = $contact_id;
158
  if ( $this->is_double_optin ) {
159
  $this->send_double_optin_notification();
254
 
255
  $admin_emails = explode( ',', $admin_email_addresses );
256
 
257
+ $list_id_name_map = ES()->lists_db->get_list_id_name_map();
258
 
259
  $list_name = '';
260
  if ( count( $this->list_ids ) > 0 ) {
includes/admin/class-es-info.php CHANGED
@@ -14,12 +14,12 @@ class ES_Info {
14
  }
15
 
16
  public function plugin_menu() {
17
- $help_title = __('Help & Info', 'email-subscribers');
18
  add_submenu_page( 'es_dashboard', $help_title, $help_title, 'edit_posts', 'es_general_information', array( $this, 'es_information_callback' ) );
19
 
20
- // $pro_title = __('Go Pro', 'email-subscribers');
21
  $active_plugins = (array) get_option( 'active_plugins', array() );
22
- $pro_title = __('<span class="es-fire-sale"> 🔥 </span> Go Pro', 'email-subscribers');
23
  if ( is_multisite() ) {
24
  $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
25
  }
@@ -31,16 +31,15 @@ class ES_Info {
31
 
32
  public function es_information_callback() {
33
 
34
- $is_option_exists = get_option('current_sa_email_subscribers_db_version', false);
35
  $enable_manual_update = false;
36
- if($is_option_exists) {
37
  $enable_manual_update = true;
38
  }
39
 
40
  $update_url = add_query_arg( 'do_update_ig_es', 'true', admin_url( 'admin.php?page=es_general_information' ) );
41
  $update_url = add_query_arg( 'from_db_version', '3.5.18', $update_url );
42
- $update_url = wp_nonce_url( $update_url, 'ig_es_db_update','ig_es_db_update_nonce');
43
-
44
 
45
  include_once( EMAIL_SUBSCRIBERS_DIR . '/admin/partials/help.php' );
46
  }
14
  }
15
 
16
  public function plugin_menu() {
17
+ $help_title = __( 'Help & Info', 'email-subscribers' );
18
  add_submenu_page( 'es_dashboard', $help_title, $help_title, 'edit_posts', 'es_general_information', array( $this, 'es_information_callback' ) );
19
 
20
+ // $pro_title = __('Go Pro', 'email-subscribers');
21
  $active_plugins = (array) get_option( 'active_plugins', array() );
22
+ $pro_title = __( '<span class="es-fire-sale"> 🔥 </span> Go Pro', 'email-subscribers' );
23
  if ( is_multisite() ) {
24
  $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
25
  }
31
 
32
  public function es_information_callback() {
33
 
34
+ $is_option_exists = get_option( 'current_sa_email_subscribers_db_version', false );
35
  $enable_manual_update = false;
36
+ if ( $is_option_exists ) {
37
  $enable_manual_update = true;
38
  }
39
 
40
  $update_url = add_query_arg( 'do_update_ig_es', 'true', admin_url( 'admin.php?page=es_general_information' ) );
41
  $update_url = add_query_arg( 'from_db_version', '3.5.18', $update_url );
42
+ $update_url = wp_nonce_url( $update_url, 'ig_es_db_update', 'ig_es_db_update_nonce' );
 
43
 
44
  include_once( EMAIL_SUBSCRIBERS_DIR . '/admin/partials/help.php' );
45
  }
includes/admin/class-es-lists-table.php CHANGED
@@ -10,9 +10,26 @@ if ( ! class_exists( 'WP_List_Table' ) ) {
10
  }
11
 
12
  class ES_Lists_Table extends WP_List_Table {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- static $instance;
15
-
 
 
 
16
  public function __construct() {
17
 
18
  parent::__construct( array(
@@ -22,16 +39,31 @@ class ES_Lists_Table extends WP_List_Table {
22
  'screen' => 'es_lists'
23
  ) );
24
 
25
- add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
26
  }
27
 
28
- public function set_screen( $status, $option, $value ) {
29
- return $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
- public function es_lists_callback() {
33
 
34
  $action = ig_es_get_request_data( 'action' );
 
35
  ?>
36
  <div class="wrap">
37
  <?php if ( 'new' === $action ) {
@@ -60,19 +92,13 @@ class ES_Lists_Table extends WP_List_Table {
60
  <?php }
61
  }
62
 
63
- public function screen_option() {
64
-
65
- $option = 'per_page';
66
- $args = array(
67
- 'label' => __( 'Lists', 'email-subscribers' ),
68
- 'default' => 10,
69
- 'option' => 'lists_per_page'
70
- );
71
-
72
- add_screen_option( $option, $args );
73
-
74
- }
75
-
76
  public function validate_data( $data ) {
77
 
78
  $nonce = $data['nonce'];
@@ -84,6 +110,8 @@ class ES_Lists_Table extends WP_List_Table {
84
  $message = __( 'You do not have permission to edit list', 'email-subscribers' );
85
  } elseif ( empty( $list_name ) ) {
86
  $message = __( 'Please add list name', 'email-subscribers' );
 
 
87
  } else {
88
  $status = 'success';
89
  }
@@ -103,8 +131,7 @@ class ES_Lists_Table extends WP_List_Table {
103
 
104
  if ( 'submitted' === $submitted ) {
105
 
106
- $nonce = ig_es_get_request_data( '_wpnonce' );
107
-
108
  $list_name = ig_es_get_request_data( 'list_name' );
109
 
110
  $validate_data = array(
@@ -126,19 +153,29 @@ class ES_Lists_Table extends WP_List_Table {
126
  'list_name' => $list_name,
127
  );
128
 
129
- $this->save_list( null, $data );
130
- $message = __( 'List has been added successfully!', 'email-subscribers' );
131
- ES_Common::show_message( $message, 'success' );
 
 
 
 
 
132
  }
133
 
134
  $this->prepare_list_form();
135
  }
136
 
137
-
 
 
 
 
 
 
138
  public function edit_list( $id ) {
139
- global $wpdb;
140
 
141
- $list = $wpdb->get_results( "SELECT * FROM " . IG_LISTS_TABLE . " WHERE id = $id" );
142
 
143
  $submitted = ig_es_get_request_data( 'submitted' );
144
 
@@ -166,14 +203,19 @@ class ES_Lists_Table extends WP_List_Table {
166
  'list_name' => $list_name,
167
  );
168
 
169
- $this->save_list( $id, $data );
170
- $message = __( 'List has been updated successfully!', 'email-subscribers' );
171
- ES_Common::show_message( $message, 'success' );
 
 
 
 
172
  } else {
173
- $id = $list[0]->id;
 
174
 
175
  $data = array(
176
- 'list_name' => $list[0]->name,
177
  );
178
 
179
  }
@@ -238,10 +280,26 @@ class ES_Lists_Table extends WP_List_Table {
238
 
239
  }
240
 
 
 
 
 
 
 
 
 
 
 
241
  public function save_list( $id, $data ) {
 
242
 
243
- global $wpdb;
 
 
 
 
244
 
 
245
  $list_data['name'] = sanitize_text_field( $data['list_name'] );
246
  $list_data['slug'] = sanitize_title( $list_data['name'] );
247
  $list_data['created_at'] = ig_get_current_date_time();
@@ -251,6 +309,7 @@ class ES_Lists_Table extends WP_List_Table {
251
  } else {
252
  $return = $wpdb->insert( IG_LISTS_TABLE, $list_data );
253
  }
 
254
 
255
  return $return;
256
  }
@@ -332,24 +391,6 @@ class ES_Lists_Table extends WP_List_Table {
332
  }
333
 
334
 
335
- /**
336
- * Delete a list record.
337
- *
338
- * @param int $id list ID
339
- */
340
- public function delete_list( $ids ) {
341
- global $wpdb;
342
-
343
- $ids = implode( ',', array_map( 'absint', $ids ) );
344
- $current_date = ig_get_current_date_time();
345
- $query = "UPDATE " . IG_LISTS_TABLE . " SET deleted_at = %s WHERE id IN ($ids)";
346
- $query = $wpdb->prepare( $query, array( $current_date ) );
347
- $wpdb->query( $query );
348
- $del_query = "DELETE FROM " . IG_LISTS_CONTACTS_TABLE . " WHERE list_id IN ($ids)";
349
- // $del_query = $wpdb->prepare( $del_query, array($ids) );
350
- $wpdb->query( $del_query );
351
- }
352
-
353
  /**
354
  * Returns the count of records in the database.
355
  *
@@ -506,7 +547,7 @@ class ES_Lists_Table extends WP_List_Table {
506
  $this->process_bulk_action();
507
  $this->search_box( ig_es_get_request_data( 's' ), 'list-search-input' );
508
 
509
- $per_page = $this->get_items_per_page( 'lists_per_page', 10 );
510
  $current_page = $this->get_pagenum();
511
  $total_items = $this->get_lists( 0, 0, true );
512
 
@@ -549,7 +590,7 @@ class ES_Lists_Table extends WP_List_Table {
549
  $list = ig_es_get_request_data( 'list' );
550
  if ( $list != 1 ) {
551
  $list = ig_es_get_request_data( 'list' );
552
- $this->delete_list( array( $list ) );
553
  $message = __( 'List has been deleted successfully!', 'email-subscribers' );
554
  ES_Common::show_message( $message, 'success' );
555
  }
@@ -564,7 +605,7 @@ class ES_Lists_Table extends WP_List_Table {
564
  $lists = ig_es_get_request_data( 'lists' );
565
 
566
  if ( ! empty( $lists ) > 0 ) {
567
- $this->delete_list( $lists );
568
  $message = __( 'List(s) have been deleted successfully', 'email-subscribers' );
569
  ES_Common::show_message( $message, 'success' );
570
  } else {
@@ -595,13 +636,4 @@ class ES_Lists_Table extends WP_List_Table {
595
  _e( 'No lists avaliable.', 'email-subscribers' );
596
  }
597
 
598
- public static function get_instance() {
599
- if ( ! isset( self::$instance ) ) {
600
- self::$instance = new self();
601
- }
602
-
603
- return self::$instance;
604
- }
605
-
606
-
607
  }
10
  }
11
 
12
  class ES_Lists_Table extends WP_List_Table {
13
+ /**
14
+ * ES_DB_Lists object
15
+ *
16
+ * @since 4.2.1
17
+ * @var $db
18
+ *
19
+ */
20
+ protected $db;
21
+ /**
22
+ * @since 4.2.1
23
+ * @var string
24
+ *
25
+ */
26
+ public static $option_per_page = 'es_lists_per_page';
27
 
28
+ /**
29
+ * ES_Lists_Table constructor.
30
+ *
31
+ * @since 4.0
32
+ */
33
  public function __construct() {
34
 
35
  parent::__construct( array(
39
  'screen' => 'es_lists'
40
  ) );
41
 
42
+ $this->db = new ES_DB_Lists();
43
  }
44
 
45
+ /**
46
+ * Add Screen Option
47
+ *
48
+ * @since 4.2.1
49
+ */
50
+ public static function screen_options() {
51
+
52
+ $option = 'per_page';
53
+ $args = array(
54
+ 'label' => __( 'Number of lists per page', 'email-subscribers' ),
55
+ 'default' => 20,
56
+ 'option' => self::$option_per_page
57
+ );
58
+
59
+ add_screen_option( $option, $args );
60
+
61
  }
62
 
63
+ public function render() {
64
 
65
  $action = ig_es_get_request_data( 'action' );
66
+
67
  ?>
68
  <div class="wrap">
69
  <?php if ( 'new' === $action ) {
92
  <?php }
93
  }
94
 
95
+ /**
96
+ * Validate data
97
+ *
98
+ * @param $data
99
+ *
100
+ * @return array
101
+ */
 
 
 
 
 
 
102
  public function validate_data( $data ) {
103
 
104
  $nonce = $data['nonce'];
110
  $message = __( 'You do not have permission to edit list', 'email-subscribers' );
111
  } elseif ( empty( $list_name ) ) {
112
  $message = __( 'Please add list name', 'email-subscribers' );
113
+ } elseif ($this->db->is_list_exists($list_name)) {
114
+ $message = __( 'List already exists. Please choose different name', 'email-subscribers' );
115
  } else {
116
  $status = 'success';
117
  }
131
 
132
  if ( 'submitted' === $submitted ) {
133
 
134
+ $nonce = ig_es_get_request_data( '_wpnonce' );
 
135
  $list_name = ig_es_get_request_data( 'list_name' );
136
 
137
  $validate_data = array(
153
  'list_name' => $list_name,
154
  );
155
 
156
+ $save = $this->save_list( null, $data );
157
+
158
+ if ( $save ) {
159
+ $message = __( 'List has been added successfully!', 'email-subscribers' );
160
+ ES_Common::show_message( $message, 'success' );
161
+ } else {
162
+
163
+ }
164
  }
165
 
166
  $this->prepare_list_form();
167
  }
168
 
169
+ /**
170
+ * Edit List
171
+ *
172
+ * @param $id
173
+ *
174
+ * @since 4.0.0
175
+ */
176
  public function edit_list( $id ) {
 
177
 
178
+ $list = $this->db->get($id);
179
 
180
  $submitted = ig_es_get_request_data( 'submitted' );
181
 
203
  'list_name' => $list_name,
204
  );
205
 
206
+ $save = $this->save_list( $id, $data );
207
+ if ( $save ) {
208
+ $message = __( 'List has been updated successfully!', 'email-subscribers' );
209
+ ES_Common::show_message( $message, 'success' );
210
+ } else {
211
+
212
+ }
213
  } else {
214
+
215
+ $id = $list['id'];
216
 
217
  $data = array(
218
+ 'list_name' => $list['name'],
219
  );
220
 
221
  }
280
 
281
  }
282
 
283
+ /**
284
+ * Save list
285
+ *
286
+ * @param $id
287
+ * @param $data
288
+ *
289
+ * @return bool|int|void
290
+ *
291
+ * @since 4.0.0
292
+ */
293
  public function save_list( $id, $data ) {
294
+ $name = sanitize_text_field( $data['list_name'] );
295
 
296
+ if ( ! empty( $id ) ) {
297
+ $return = $this->db->update_list( $id, $name );
298
+ } else {
299
+ $return = $this->db->add_list( $name );
300
+ }
301
 
302
+ /*
303
  $list_data['name'] = sanitize_text_field( $data['list_name'] );
304
  $list_data['slug'] = sanitize_title( $list_data['name'] );
305
  $list_data['created_at'] = ig_get_current_date_time();
309
  } else {
310
  $return = $wpdb->insert( IG_LISTS_TABLE, $list_data );
311
  }
312
+ */
313
 
314
  return $return;
315
  }
391
  }
392
 
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  /**
395
  * Returns the count of records in the database.
396
  *
547
  $this->process_bulk_action();
548
  $this->search_box( ig_es_get_request_data( 's' ), 'list-search-input' );
549
 
550
+ $per_page = $this->get_items_per_page( self::$option_per_page, 10 );
551
  $current_page = $this->get_pagenum();
552
  $total_items = $this->get_lists( 0, 0, true );
553
 
590
  $list = ig_es_get_request_data( 'list' );
591
  if ( $list != 1 ) {
592
  $list = ig_es_get_request_data( 'list' );
593
+ $this->db->delete_lists( array( $list ) );
594
  $message = __( 'List has been deleted successfully!', 'email-subscribers' );
595
  ES_Common::show_message( $message, 'success' );
596
  }
605
  $lists = ig_es_get_request_data( 'lists' );
606
 
607
  if ( ! empty( $lists ) > 0 ) {
608
+ $this->db->delete_lists( $lists );
609
  $message = __( 'List(s) have been deleted successfully', 'email-subscribers' );
610
  ES_Common::show_message( $message, 'success' );
611
  } else {
636
  _e( 'No lists avaliable.', 'email-subscribers' );
637
  }
638
 
 
 
 
 
 
 
 
 
 
639
  }
includes/admin/class-es-newsletters.php CHANGED
@@ -21,7 +21,7 @@ class ES_Newsletters {
21
 
22
  // class constructor
23
  public function __construct() {
24
- add_filter( 'set-screen-option', array( __CLASS__, 'set_screen' ), 10, 3 );
25
  add_action( 'admin_init', array( $this, 'setup_sections' ) );
26
  add_filter( 'ig_es_refresh_newsletter_content', array( $this, 'refresh_newsletter_content' ), 10, 2 );
27
  }
@@ -224,8 +224,7 @@ class ES_Newsletters {
224
 
225
  $post_temp_arr = get_post( $template_id );
226
 
227
- $campaign_id = ES_DB_Campaigns::save_campaign( $data );
228
-
229
 
230
  if ( is_object( $post_temp_arr ) ) {
231
 
@@ -268,7 +267,7 @@ class ES_Newsletters {
268
 
269
  public static function refresh_newsletter_content( $content, $args) {
270
  $campaign_id = $args['campaign_id'];
271
- $template_id = ES_DB_Campaigns::get_templateid_by_campaign( $campaign_id );
272
  $template = get_post( $template_id );
273
  $content['subject'] = ! empty( $template->post_title ) ? $template->post_title : '';
274
  $content['body'] = ! empty( $template->post_content ) ? $template->post_content : '';
21
 
22
  // class constructor
23
  public function __construct() {
24
+ //add_filter( 'set-screen-option', array( __CLASS__, 'set_screen' ), 10, 3 );
25
  add_action( 'admin_init', array( $this, 'setup_sections' ) );
26
  add_filter( 'ig_es_refresh_newsletter_content', array( $this, 'refresh_newsletter_content' ), 10, 2 );
27
  }
224
 
225
  $post_temp_arr = get_post( $template_id );
226
 
227
+ $campaign_id = ES()->campaigns_db->save_campaign( $data );
 
228
 
229
  if ( is_object( $post_temp_arr ) ) {
230
 
267
 
268
  public static function refresh_newsletter_content( $content, $args) {
269
  $campaign_id = $args['campaign_id'];
270
+ $template_id = ES()->campaigns_db->get_template_id_by_campaign( $campaign_id );
271
  $template = get_post( $template_id );
272
  $content['subject'] = ! empty( $template->post_title ) ? $template->post_title : '';
273
  $content['body'] = ! empty( $template->post_content ) ? $template->post_content : '';
includes/admin/class-es-old-widget.php CHANGED
@@ -28,7 +28,7 @@ class ES_Old_Widget extends WP_Widget {
28
 
29
  $name = strtolower( $display_name ) != 'no' ? 'yes' : '';
30
 
31
- $list = ES_DB_Lists::get_list_by_name($subscribers_group);
32
  if(!empty($list)) {
33
  $list_id = $list['id'];
34
  }
@@ -87,7 +87,7 @@ class ES_Old_Widget extends WP_Widget {
87
  <label for="<?php echo $this->get_field_id( 'es_group' ); ?>"><?php echo __( 'Subscriber Group', 'email-subscribers' ); ?></label>
88
  <select class="widefat" name="<?php echo $this->get_field_name( 'es_group' ); ?>" id="<?php echo $this->get_field_id( 'es_group' ); ?>">
89
  <?php
90
- $groups = ES_DB_Lists::get_list_id_name_map();
91
  if ( count( $groups ) > 0 ) {
92
  $i = 1;
93
  foreach ( $groups as $group ) {
28
 
29
  $name = strtolower( $display_name ) != 'no' ? 'yes' : '';
30
 
31
+ $list = ES()->lists_db->get_list_by_name($subscribers_group);
32
  if(!empty($list)) {
33
  $list_id = $list['id'];
34
  }
87
  <label for="<?php echo $this->get_field_id( 'es_group' ); ?>"><?php echo __( 'Subscriber Group', 'email-subscribers' ); ?></label>
88
  <select class="widefat" name="<?php echo $this->get_field_name( 'es_group' ); ?>" id="<?php echo $this->get_field_id( 'es_group' ); ?>">
89
  <?php
90
+ $groups = ES()->lists_db->get_list_id_name_map();
91
  if ( count( $groups ) > 0 ) {
92
  $i = 1;
93
  foreach ( $groups as $group ) {
includes/admin/class-es-post-notifications.php CHANGED
@@ -109,7 +109,7 @@ class ES_Post_Notifications_Table {
109
  }
110
 
111
  public function save_list( $data, $id = null ) {
112
- return ES_DB_Campaigns::save_campaign( $data, $id );
113
  }
114
 
115
  /**
109
  }
110
 
111
  public function save_list( $data, $id = null ) {
112
+ return ES()->campaigns_db->save_campaign( $data, $id );
113
  }
114
 
115
  /**
includes/admin/class-es-queue.php CHANGED
@@ -10,16 +10,32 @@ if ( ! class_exists( 'ES_Queue' ) ) {
10
  *
11
  * Manage Mailing Queue
12
  *
 
 
 
 
13
  *
14
  * @since 4.2.0
15
  */
16
  class ES_Queue {
 
 
 
 
 
 
 
 
 
17
  /**
18
  * ES_Queue constructor.
19
  *
20
  * @since 4.2.0
21
  */
22
  public function __construct() {
 
 
 
23
  add_action( 'plugins_loaded', array( &$this, 'init' ), 1 );
24
  }
25
 
@@ -30,6 +46,9 @@ if ( ! class_exists( 'ES_Queue' ) ) {
30
  */
31
  public function init() {
32
  add_action( 'ig_es_cron_auto_responder', array( &$this, 'queue_time_based_campaigns' ), 30 );
 
 
 
33
  }
34
 
35
  /**
@@ -52,10 +71,10 @@ if ( ! class_exists( 'ES_Queue' ) ) {
52
  }
53
 
54
  if ( $campaign_id ) {
55
- $campaign = ES_DB_Campaigns::get_campaign_by_id( $campaign_id );
56
  $campaigns = array( $campaign );
57
  } else {
58
- $campaigns = ES_DB_Campaigns::get_active_campaigns( IG_CAMPAIGN_TYPE_POST_DIGEST );
59
  }
60
 
61
  if ( empty( $campaigns ) ) {
@@ -105,8 +124,24 @@ if ( ! class_exists( 'ES_Queue' ) ) {
105
 
106
  $campaign['start_at'] = date( 'Y-m-d H:i:s', $start_time );
107
 
108
- // Create a new mailing queue using this campaign
109
- $this->add_campaign_to_queue( $campaign );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
111
 
112
  $time_frame = ! empty( $rules['time_frame'] ) ? $rules['time_frame'] : '';
@@ -136,11 +171,132 @@ if ( ! class_exists( 'ES_Queue' ) ) {
136
  $meta_data['scheduled'] = 1;
137
  }
138
 
139
- ES_DB_Campaigns::update_campaign_meta( $campaign_id, $meta_data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
 
141
  }
142
  }
143
 
 
144
  }
145
 
146
  /**
@@ -148,66 +304,281 @@ if ( ! class_exists( 'ES_Queue' ) ) {
148
  *
149
  * @param $campaign
150
  *
151
- * @return int
152
  *
153
  * @since 4.2.0
154
  */
155
- public function add_campaign_to_queue( $campaign ) {
156
 
157
  $campaign_id = $campaign['id'];
158
  $template_id = $campaign['base_template_id'];
159
  $template = get_post( $template_id );
160
  $queue_id = 0;
161
- if ( $template instanceof WP_Post ) {
162
 
163
  $subject = ! empty( $template->post_title ) ? $template->post_title : '';
164
  $content = ! empty( $template->post_content ) ? $template->post_content : '';
165
  $content = ES_Common::es_process_template_body( $content, $template_id );
166
 
167
- $list_id = $campaign['list_ids'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
- // Do we have active subscribers?
170
 
171
- $subscribers = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
 
172
 
173
- if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
 
 
 
 
 
 
 
 
 
 
174
 
175
- $guid = ES_Common::generate_guid( 6 );
 
 
 
 
176
 
177
- $data = array(
178
- 'hash' => $guid,
179
- 'campaign_id' => $campaign_id,
180
- 'subject' => $subject,
181
- 'body' => $content,
182
- 'count' => count( $subscribers ),
183
- 'status' => 'In Queue',
184
- 'start_at' => ! empty( $campaign['start_at'] ) ? $campaign['start_at'] : '',
185
- 'finish_at' => '',
186
- 'created_at' => ig_get_current_date_time(),
187
- 'updated_at' => ig_get_current_date_time(),
188
- 'meta' => maybe_serialize( array( 'type' => $campaign['type'] ) )
189
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
- $queue_id = ES_DB_Mailing_Queue::add_notification( $data );
192
 
193
- $delivery_data = array();
194
- $delivery_data['hash'] = $guid;
195
- $delivery_data['subscribers'] = $subscribers;
196
- $delivery_data['campaign_id'] = $campaign_id;
197
- $delivery_data['mailing_queue_id'] = $queue_id;
198
 
199
- ES_DB_Sending_Queue::do_batch_insert( $delivery_data );
 
 
 
 
 
 
 
 
200
  }
 
 
 
 
 
 
 
 
 
 
 
201
  }
202
 
203
- return $queue_id;
 
204
  }
205
 
206
- }
 
 
 
 
 
 
 
 
 
 
207
 
208
- new ES_Queue();
209
- }
210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
 
213
 
10
  *
11
  * Manage Mailing Queue
12
  *
13
+ * Actions
14
+ * ig_es_time_based_campaign - Immediately, Daily, Weekly, Monthly
15
+ * ig_es_contact_insert - Time after contact subscribe
16
+ * ig_es_campaign_open - Time after specific campaign open
17
  *
18
  * @since 4.2.0
19
  */
20
  class ES_Queue {
21
+ /**
22
+ * ES_DB_Queue object
23
+ *
24
+ * @since 4.2.1
25
+ * @var $db
26
+ *
27
+ */
28
+ protected $db;
29
+
30
  /**
31
  * ES_Queue constructor.
32
  *
33
  * @since 4.2.0
34
  */
35
  public function __construct() {
36
+
37
+ $this->db = new ES_DB_Queue();
38
+
39
  add_action( 'plugins_loaded', array( &$this, 'init' ), 1 );
40
  }
41
 
46
  */
47
  public function init() {
48
  add_action( 'ig_es_cron_auto_responder', array( &$this, 'queue_time_based_campaigns' ), 30 );
49
+ add_action( 'ig_es_cron_auto_responder', array( &$this, 'queue_sequences' ), 30 );
50
+
51
+ add_action( 'ig_es_cron_worker', array( &$this, 'process_queue' ), 30 );
52
  }
53
 
54
  /**
71
  }
72
 
73
  if ( $campaign_id ) {
74
+ $campaign = ES()->campaigns_db->get_campaign_by_id( $campaign_id );
75
  $campaigns = array( $campaign );
76
  } else {
77
+ $campaigns = ES()->campaigns_db->get_active_campaigns( IG_CAMPAIGN_TYPE_POST_DIGEST );
78
  }
79
 
80
  if ( empty( $campaigns ) ) {
124
 
125
  $campaign['start_at'] = date( 'Y-m-d H:i:s', $start_time );
126
 
127
+ $list_id = $campaign['list_ids'];
128
+
129
+ // Do we have active subscribers?
130
+ $contacts = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
131
+ $total_contacts = count( $contacts );
132
+
133
+ if ( $total_contacts > 0 ) {
134
+ // Create a new mailing queue using this campaign
135
+ $result = $this->add_campaign_to_queue( $campaign, $total_contacts );
136
+
137
+ if ( is_array( $result ) ) {
138
+ $queue_id = $result['id'];
139
+ $hash = $result['hash'];
140
+
141
+ $this->add_contacts_to_queue( $campaign_id, $hash, $queue_id, $contacts );
142
+ }
143
+
144
+ }
145
  }
146
 
147
  $time_frame = ! empty( $rules['time_frame'] ) ? $rules['time_frame'] : '';
171
  $meta_data['scheduled'] = 1;
172
  }
173
 
174
+ ES()->campaigns_db->update_campaign_meta( $campaign_id, $meta_data );
175
+ }
176
+ }
177
+ }
178
+
179
+ }
180
+
181
+ /**
182
+ * Queue Valid Sequence messages
183
+ *
184
+ * @since 4.2.1
185
+ */
186
+ public function queue_sequences( $campaign_id, $force = false ) {
187
+ global $wpdb;
188
+ /**
189
+ * Steps
190
+ * 1. Fetch all active Sequence Message
191
+ * 2. Loop over through and based on matched condition put campaign into mailing_queue table if not already exists
192
+ * 3. And also insert subscribers for respective campaign into snding_queue_table
193
+ */
194
+ static $campaigns_to_process;
195
+
196
+ if ( ! isset( $campaigns_to_process ) ) {
197
+ $campaigns_to_process = array();
198
+ }
199
+
200
+ if ( $campaign_id ) {
201
+ $campaign = ES()->campaigns_db->get_campaign_by_id( $campaign_id );
202
+ $campaigns = array( $campaign );
203
+ } else {
204
+ $campaigns = ES()->campaigns_db->get_active_campaigns( IG_CAMPAIGN_TYPE_SEQUENCE_MESSAGE );
205
+ }
206
+
207
+ if ( empty( $campaigns ) ) {
208
+ return;
209
+ }
210
+
211
+ $now = time();
212
+
213
+ foreach ( $campaigns as $campaign ) {
214
+
215
+ if ( in_array( $campaign['id'], $campaigns_to_process ) && ! $force ) {
216
+ continue;
217
+ }
218
+
219
+ $campaign_id = $campaign['id'];
220
+
221
+ $campaigns_to_process[] = $campaign_id;
222
+
223
+ $meta = maybe_unserialize( $campaign['meta'] );
224
+
225
+ $rules = ! empty( $meta['rules'] ) ? $meta['rules'] : array();
226
+
227
+ //ES()->logger->info( 'Rules: ' . print_r( $rules, true ) );
228
+
229
+ if ( ! empty( $rules ) ) {
230
+
231
+ $action = ! empty( $rules['action'] ) ? $rules['action'] : '';
232
+
233
+ if ( 'ig_es_contact_insert' != $action ) {
234
+ continue;
235
+ }
236
+
237
+ // We are considering contacts for sequences which are last added in a week.
238
+ $grace_period = 1 * DAY_IN_SECONDS;
239
+ $queue_upfront = 3600;
240
+
241
+ $offset = (int) $rules['amount'] . ' ' . strtoupper( $rules['unit'] );
242
+
243
+ $list_ids = $campaign['list_ids'];
244
+
245
+ $ig_actions_table = IG_ACTIONS_TABLE;
246
+ $ig_lists_contacts_table = IG_LISTS_CONTACTS_TABLE;
247
+ $ig_queue_table = IG_QUEUE_TABLE;
248
+ $ig_campaign_sent = IG_MESSAGE_SENT;
249
+
250
+ $query_args = array(
251
+ "select" => "SELECT lists_contacts.contact_id, UNIX_TIMESTAMP ( lists_contacts.subscribed_at + INTERVAL $offset ) AS timestamp",
252
+ "from" => "FROM $ig_lists_contacts_table AS lists_contacts",
253
+ 'join1' => "LEFT JOIN $ig_actions_table AS actions_sent_message ON lists_contacts.contact_id = actions_sent_message.contact_id AND actions_sent_message.type = $ig_campaign_sent AND actions_sent_message.campaign_id IN ($campaign_id)",
254
+ 'join2' => "LEFT JOIN $ig_queue_table AS queue ON lists_contacts.contact_id = queue.contact_id AND queue.campaign_id IN ($campaign_id)",
255
+ 'where' => "WHERE 1=1 AND lists_contacts.list_id IN ($list_ids) AND lists_contacts.status = 'subscribed' AND actions_sent_message.contact_id IS NULL AND queue.contact_id IS NULL",
256
+ 'group_by' => "GROUP BY lists_contacts.contact_id",
257
+ 'having' => "HAVING timestamp <= " . ( $now + $queue_upfront ) . " AND timestamp >= " . ( $now - $grace_period ),
258
+ 'order_by' => 'ORDER BY timestamp ASC',
259
+ );
260
+
261
+ $query = implode( ' ', $query_args );
262
+
263
+ //ES()->logger->info( '----------------------------Query Args (ig_es_contact_insert) ----------------------------' );
264
+ //ES()->logger->info( $query );
265
+ //ES()->logger->info( '----------------------------Query Args Complete (ig_es_contact_insert) ----------------------------' );
266
+
267
+ $results = $wpdb->get_results( $query, ARRAY_A );
268
+
269
+ //ES()->logger->info( 'Results: ' . print_r( $results, true ) );
270
+
271
+ if ( ! empty( $results ) ) {
272
+
273
+ $contact_ids = wp_list_pluck( $results, 'contact_id' );
274
+ $timestamps = wp_list_pluck( $results, 'timestamp' );
275
+
276
+ /**
277
+ * Check whether campaign is already exists in mailing_queue table with $campaign_id
278
+ * If Exists, Get the mailing_queue_id & hash
279
+ * If Not, create new and get the mailing_queue_id & hash
280
+ */
281
+ $total_contacts = count( $contact_ids );
282
+ if ( $total_contacts > 0 ) {
283
+
284
+ $this->bulk_add( $campaign_id, $contact_ids, $timestamps, 15 );
285
+
286
+ $timestamp = min( $timestamps );
287
+
288
+ // handle instant delivery
289
+ if ( $timestamp - time() <= 0 ) {
290
+ wp_schedule_single_event( $timestamp, 'ig_es_cron_worker', array( $campaign_id ) );
291
+ }
292
+
293
+ }
294
  }
295
+
296
  }
297
  }
298
 
299
+
300
  }
301
 
302
  /**
304
  *
305
  * @param $campaign
306
  *
307
+ * @return int | array
308
  *
309
  * @since 4.2.0
310
  */
311
+ public function add_campaign_to_queue( $campaign, $total_contacts ) {
312
 
313
  $campaign_id = $campaign['id'];
314
  $template_id = $campaign['base_template_id'];
315
  $template = get_post( $template_id );
316
  $queue_id = 0;
317
+ if ( $template instanceof WP_Post && $total_contacts > 0 ) {
318
 
319
  $subject = ! empty( $template->post_title ) ? $template->post_title : '';
320
  $content = ! empty( $template->post_content ) ? $template->post_content : '';
321
  $content = ES_Common::es_process_template_body( $content, $template_id );
322
 
323
+ $guid = ES_Common::generate_guid( 6 );
324
+
325
+ $data = array(
326
+ 'hash' => $guid,
327
+ 'campaign_id' => $campaign_id,
328
+ 'subject' => $subject,
329
+ 'body' => $content,
330
+ 'count' => $total_contacts,
331
+ 'status' => 'In Queue',
332
+ 'start_at' => ! empty( $campaign['start_at'] ) ? $campaign['start_at'] : '',
333
+ 'finish_at' => '',
334
+ 'created_at' => ig_get_current_date_time(),
335
+ 'updated_at' => ig_get_current_date_time(),
336
+ 'meta' => maybe_serialize( array( 'type' => $campaign['type'] ) )
337
+ );
338
+
339
+ $queue_id = ES_DB_Mailing_Queue::add_notification( $data );
340
+
341
+ return array(
342
+ 'hash' => $guid,
343
+ 'id' => $queue_id
344
+ );
345
 
346
+ }
347
 
348
+ return $queue_id;
349
+ }
350
 
351
+ /**
352
+ * Add contacts into sending_queue_table
353
+ *
354
+ * @param $campaign_id
355
+ * @param $guid
356
+ * @param $queue_id
357
+ * @param $contacts
358
+ *
359
+ * @since 4.2.1
360
+ */
361
+ public function add_contacts_to_queue( $campaign_id, $guid, $queue_id, $contacts ) {
362
 
363
+ $delivery_data = array();
364
+ $delivery_data['hash'] = $guid;
365
+ $delivery_data['subscribers'] = $contacts;
366
+ $delivery_data['campaign_id'] = $campaign_id;
367
+ $delivery_data['mailing_queue_id'] = $queue_id;
368
 
369
+ ES_DB_Sending_Queue::do_batch_insert( $delivery_data );
370
+ }
371
+
372
+ /**
373
+ * Bulk Add contacts into queue
374
+ *
375
+ * @param $campaign_id
376
+ * @param $subscribers
377
+ * @param null $timestamp
378
+ * @param int $priority
379
+ * @param bool $clear
380
+ * @param bool $ignore_status
381
+ * @param bool $reset
382
+ * @param bool $options
383
+ * @param bool $tags
384
+ *
385
+ * @return bool|void
386
+ *
387
+ * @since 4.2.1
388
+ */
389
+ public function bulk_add( $campaign_id, $subscribers, $timestamp = null, $priority = 10, $clear = false, $ignore_status = false, $reset = false, $options = false, $tags = false ) {
390
+
391
+ global $wpdb;
392
+
393
+ if ( $clear ) {
394
+ $this->clear( $campaign_id, $subscribers );
395
+ }
396
+
397
+ if ( empty( $subscribers ) ) {
398
+ return;
399
+ }
400
+
401
+ if ( is_null( $timestamp ) ) {
402
+ $timestamp = time();
403
+ }
404
+
405
+ $timestamps = ! is_array( $timestamp )
406
+ ? array_fill( 0, count( $subscribers ), $timestamp )
407
+ : $timestamp;
408
+
409
+ $now = time();
410
+
411
+ $campaign_id = (int) $campaign_id;
412
+ $subscribers = array_filter( $subscribers, 'is_numeric' );
413
+
414
+ if ( $tags ) {
415
+ $tags = maybe_serialize( $tags );
416
+ }
417
+ if ( $options ) {
418
+ $options = maybe_serialize( $options );
419
+ }
420
+
421
+ if ( empty( $subscribers ) ) {
422
+ return true;
423
+ }
424
+
425
+ $inserts = array();
426
+
427
+ foreach ( $subscribers as $i => $subscriber_id ) {
428
+ $inserts[] = "($subscriber_id,$campaign_id,$now," . $timestamps[ $i ] . ",$priority,1,'$ignore_status','$options','$tags')";
429
+ }
430
 
431
+ $chunks = array_chunk( $inserts, 1000 );
432
 
433
+ $success = true;
 
 
 
 
434
 
435
+ foreach ( $chunks as $insert ) {
436
+
437
+ $sql = "INSERT INTO {$wpdb->prefix}ig_queue (contact_id, campaign_id, added, timestamp, priority, count, ignore_status, options, tags) VALUES";
438
+
439
+ $sql .= ' ' . implode( ',', $insert );
440
+
441
+ $sql .= ' ON DUPLICATE KEY UPDATE timestamp = values(timestamp), ignore_status = values(ignore_status)';
442
+ if ( $reset ) {
443
+ $sql .= ', sent = 0';
444
  }
445
+ if ( $options ) {
446
+ $sql .= sprintf( ", options = '%s'", $options );
447
+ }
448
+ if ( $tags ) {
449
+ $sql .= sprintf( ", tags = '%s'", $tags );
450
+ }
451
+
452
+ //ES()->logger->info( 'Adding Bulk SQL: ' . $sql );
453
+
454
+ $success = $success && false !== $wpdb->query( $sql );
455
+
456
  }
457
 
458
+ return $success;
459
+
460
  }
461
 
462
+ /**
463
+ * Clear queue which are not assigned to any campaign
464
+ *
465
+ * @param null $campaign_id
466
+ * @param array $subscribers
467
+ *
468
+ * @return bool
469
+ *
470
+ * @since 4.2.1
471
+ */
472
+ public function clear( $campaign_id = null, $subscribers = array() ) {
473
 
474
+ global $wpdb;
 
475
 
476
+ $campaign_id = (int) $campaign_id;
477
+ $subscribers = array_filter( $subscribers, 'is_numeric' );
478
+
479
+ if ( empty( $subscribers ) ) {
480
+ $subscribers = array( - 1 );
481
+ }
482
+
483
+ $sql = "DELETE queue FROM {$wpdb->prefix}ig_queue AS queue WHERE queue.sent = 0 AND queue.contact_id NOT IN (" . implode( ',', $subscribers ) . ')';
484
+ if ( ! is_null( $campaign_id ) ) {
485
+ $sql .= $wpdb->prepare( ' AND queue.campaign_id = %d', $campaign_id );
486
+ }
487
+
488
+ return false !== $wpdb->query( $sql );
489
+
490
+ }
491
+
492
+ /**
493
+ * Process Queue
494
+ *
495
+ * @since 4.2.1
496
+ */
497
+ public function process_queue() {
498
+ global $wpdb;
499
+
500
+ $micro_time = microtime( true );
501
+
502
+ $ig_queue_table = IG_QUEUE_TABLE;
503
+ $ig_campaigns_table = IG_CAMPAIGNS_TABLE;
504
+
505
+ $sql = 'SELECT queue.campaign_id, queue.contact_id, queue.count AS _count, queue.requeued AS _requeued, queue.options AS _options, queue.tags AS _tags, queue.priority AS _priority';
506
+ $sql .= " FROM $ig_queue_table AS queue";
507
+ $sql .= " LEFT JOIN $ig_campaigns_table AS campaigns ON campaigns.id = queue.campaign_id";
508
+ $sql .= ' WHERE queue.timestamp <= ' . (int) $micro_time . " AND queue.sent_at = 0";
509
+ $sql .= " AND (campaigns.status = 1)";
510
+ $sql .= ' ORDER BY queue.priority DESC';
511
+
512
+ //ES()->logger->info( 'Process Queue:' );
513
+ //ES()->logger->info( 'SQL: ' . $sql );
514
+
515
+ $notifications = $wpdb->get_results( $sql, ARRAY_A );
516
+
517
+ if ( is_array( $notifications ) && count( $notifications ) > 0 ) {
518
+ $campaigns_notifications = $contact_ids = array();
519
+ foreach ( $notifications as $notification ) {
520
+ $campaigns_notifications[ $notification['campaign_id'] ][] = $notification;
521
+
522
+ $contact_ids[] = $notification['contact_id'];
523
+ }
524
+
525
+ // We need unique ids
526
+ $contact_ids = array_unique( $contact_ids );
527
+
528
+ $contacts = ES_DB_Contacts::get_details_by_ids( $contact_ids );
529
+
530
+ foreach ( $campaigns_notifications as $campaign_id => $notifications ) {
531
+
532
+ $campaign = ES()->campaigns_db->get( $campaign_id );
533
+
534
+ if ( ! empty( $campaign ) ) {
535
+
536
+ $content = $campaign['body'];
537
+ $subject = $campaign['subject'];
538
+
539
+ foreach ( $notifications as $notification ) {
540
+
541
+ $contact_id = $notification['contact_id'];
542
+
543
+ if ( ! empty( $contacts[ $contact_id ] ) ) {
544
+
545
+ $first_name = $contacts[ $contact_id ]['first_name'];
546
+ $last_name = $contacts[ $contact_id ]['last_name'];
547
+ $hash = $contacts[ $contact_id ]['hash'];
548
+ $email = $contacts[ $contact_id ]['email'];
549
+ $name = ES_Common::prepare_name_from_first_name_last_name( $first_name, $last_name );
550
+
551
+ $keywords = array(
552
+ 'name' => $name,
553
+ 'first_name' => $first_name,
554
+ 'last_name' => $last_name,
555
+ 'email' => $email,
556
+ 'guid' => $hash,
557
+ 'dbid' => $contact_id,
558
+ 'message_id' => 0,
559
+ 'campaign_id' => $campaign_id
560
+ );
561
+
562
+ // Preparing email body
563
+ $body = ES_Mailer::prepare_email_template( $content, $keywords );
564
+
565
+ $result = ES_Mailer::send( $email, $subject, $body );
566
+
567
+ do_action( 'ig_es_message_sent', $contact_id, $campaign_id, 0 );
568
+
569
+ // Email Sent now delete from queue now.
570
+ $this->db->delete_from_queue( $campaign_id, $contact_id );
571
+ }
572
+ }
573
+ }
574
+
575
+ }
576
+
577
+ }
578
+ }
579
+
580
+ }
581
+ }
582
 
583
 
584
 
includes/admin/class-es-reports-table.php CHANGED
@@ -22,7 +22,7 @@ class ES_Reports_Table extends WP_List_Table {
22
  'screen' => 'es_reports'
23
  ) );
24
 
25
- add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
26
  }
27
 
28
 
@@ -197,7 +197,7 @@ class ES_Reports_Table extends WP_List_Table {
197
  if ( empty( $item['campaign_id'] ) ) {
198
  $type = __( 'Post Notification', 'email-subscribers' );
199
  } else {
200
- $type = ES_DB_Campaigns::get_campaign_type_by_id( $item['campaign_id'] );
201
  $type = strtolower( $type );
202
  $type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type;
203
  }
22
  'screen' => 'es_reports'
23
  ) );
24
 
25
+ //add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 );
26
  }
27
 
28
 
197
  if ( empty( $item['campaign_id'] ) ) {
198
  $type = __( 'Post Notification', 'email-subscribers' );
199
  } else {
200
+ $type = ES()->campaigns_db->get_campaign_type_by_id( $item['campaign_id'] );
201
  $type = strtolower( $type );
202
  $type = ( 'newsletter' === $type ) ? __( 'Broadcast', 'email-subscribers' ) : $type;
203
  }
includes/admin/class-es-tracking.php CHANGED
@@ -10,7 +10,6 @@ if ( ! class_exists( 'ES_Tracking' ) ) {
10
  *
11
  * Track Activities like Subscribe, Open, Click, Unsubscribe
12
  *
13
- *
14
  * @since 4.2.0
15
  */
16
  class ES_Tracking {
10
  *
11
  * Track Activities like Subscribe, Open, Click, Unsubscribe
12
  *
 
13
  * @since 4.2.0
14
  */
15
  class ES_Tracking {
includes/class-email-subscribers.php CHANGED
@@ -33,6 +33,148 @@ if ( ! defined( 'ABSPATH' ) ) {
33
  * @author Your Name <email@example.com>
34
  */
35
  class Email_Subscribers {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  /**
37
  * The loader that's responsible for maintaining and registering all hooks that power
38
  * the plugin.
@@ -70,7 +212,7 @@ class Email_Subscribers {
70
  *
71
  * @since 4.0
72
  */
73
- public function __construct() {
74
  global $ig_es_feedback, $ig_es_tracker;
75
 
76
  require_once plugin_dir_path( __FILE__ ) . 'class-email-subscribers-activator.php';
@@ -109,6 +251,24 @@ class Email_Subscribers {
109
  public function add_admin_notice() {
110
  global $ig_es_tracker;
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  $screen = get_current_screen();
113
  $screen_id = $screen ? $screen->id : '';
114
  $show_on_screens = array(
@@ -150,18 +310,18 @@ class Email_Subscribers {
150
  <?php
151
  return;
152
  }
153
- if ( is_admin() && ! empty( $es_pro_plugin_version ) && version_compare( $es_pro_plugin_version, '4.2', '<' ) ) {
154
  $url = admin_url( "plugins.php?plugin_status=upgrade" );
155
  $es_upgrade_text = __( 'We have released a recommended update of Email subscribers Premium. So kindly ', 'email-subscribers-premium' ) . '<a href=' . $url . ' target="_blank" style="cursor:pointer">' . __( "update to the latest version", "email-subscribers-premium" ) . '</a>' . __( " right now", "email-subscribers-premium" );
156
- echo '<div class="notice notice-warning" style="background-color: #FFF;"><p style="letter-spacing: 0.6px;">' . $es_upgrade_text . '</p></div>';
157
  }
158
  }
159
  $es_premium = 'email-subscribers-premium/email-subscribers-premium.php';
160
  $all_plugins = $ig_es_tracker::get_plugins();
161
  //get pro button
162
- if ( ! in_array( $es_premium, $all_plugins ) && is_admin() && ! in_array( $screen_id, array( 'toplevel_page_es_dashboard' ), true ) ) {
163
- echo "<div class='notice es-floting-button'><i class='dashicons dashicons-es dashicons-awards'></i> <a href='https://www.icegram.com/email-subscribers-pricing/?utm_source=in_app&utm_medium=get_starter_floating_button&utm_campaign=es_upsale' target='_blank'>" . __( 'Get Starter Now!', 'email-subscribers' ) . "</a></div>";
164
- }
165
  //cron notice
166
  $notice_option = get_option( 'ig_es_wp_cron_notice' );
167
 
@@ -179,13 +339,12 @@ class Email_Subscribers {
179
  'email-subscribers' ) . '</a></p></div>';
180
  }
181
 
182
- //post digest
183
- $post_digest_option_dismiss = get_option( 'post_digest_release_notice' );
184
- $post_digest_option_seen = get_option( 'ig_es_post_digest_release_notice_seen' );
185
- if ( ! in_array( $es_premium, $all_plugins ) && is_admin() && $post_digest_option_seen != 'yes' && $post_digest_option_dismiss != 'yes' ) {
186
- $post_digest_url = admin_url() . '?es_dismiss_admin_notice=1&option_name=post_digest_release_notice_seen';
187
- $post_digest_notice = sprintf( __( '📣 <b>[ Released ]</b> New Feature : Send <strong>Post Digest</strong> using Email Subscribers <a href="%s" target="_blank">[Read more]</a>', 'email-subscribers' ), $post_digest_url );
188
- echo '<div class="notice notice-warning" style="background-color: #FFF;"><p style="letter-spacing: 0.6px;">' . $post_digest_notice . '<a style="float:right" class="es-admin-btn es-admin-btn-secondary " href="' . admin_url() . '?es_dismiss_admin_notice=1&option_name=post_digest_release_notice">' . __( 'OK, I Got it!',
189
  'email-subscribers' ) . '</a></p></div>';
190
  }
191
 
@@ -209,8 +368,8 @@ class Email_Subscribers {
209
  header( "Location: https://wordpress.org/support/plugin/email-subscribers/reviews/" );
210
  exit();
211
  }
212
- if ( $option_name === 'post_digest_release_notice_seen' ) {
213
- header( "Location: https://www.icegram.com/send-post-digest-using-email-subscribers-plugin/?utm_source=es&utm_medium=es_upsale_banner&utm_campaign=es_upsale" );
214
  exit();
215
  }
216
  if ( $option_name === 'redirect_upsale_notice' ) {
@@ -235,70 +394,169 @@ class Email_Subscribers {
235
 
236
  $upload_dir = wp_upload_dir( null, false );
237
 
238
- $constants = array(
239
-
240
- 'EMAIL_SUBSCRIBERS_SLUG' => 'email-subscribers',
241
- 'IG_LOG_DIR' => $upload_dir['basedir'] . '/ig-logs/',
242
- 'EMAIL_SUBSCRIBERS_INCLUDES_DIR' => __DIR__ . '/includes',
243
- 'EMAIL_SUBSCRIBERS_DIR' => WP_PLUGIN_DIR . '/email-subscribers',
244
- 'EMAIL_SUBSCRIBERS_URL' => WP_PLUGIN_URL . '/email-subscribers',
245
- //ES3 Tables
246
- 'ES_EMAILLIST_TABLE' => $wpdb->prefix . 'es_emaillist',
247
- 'EMAIL_LIST_TABLE' => $wpdb->prefix . 'es_lists',
248
- 'EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE' => $wpdb->prefix . 'es_notification',
249
- 'EMAIL_SUBSCRIBERS_STATS_TABLE' => $wpdb->prefix . 'es_deliverreport',
250
- 'EMAIL_SUBSCRIBERS_SENT_TABLE' => $wpdb->prefix . 'es_sentdetails',
251
- 'EMAIL_TEMPLATES_TABLE' => $wpdb->prefix . 'es_templates',
252
- 'EMAIL_SUBSCRIBERS_ADVANCED_FORM' => $wpdb->prefix . 'es_advanced_form',
253
- // Constants
254
- 'EMAIL_SUBSCRIBERS_LIST_MAX' => 40,
255
- 'EMAIL_SUBSCRIBERS_CRON_INTERVAL' => 300,
256
- // ES4 Tables
257
- 'IG_CAMPAIGNS_TABLE' => $wpdb->prefix . 'ig_campaigns',
258
- 'IG_CONTACTS_TABLE' => $wpdb->prefix . 'ig_contacts',
259
- 'IG_CONTACTS_IPS_TABLE' => $wpdb->prefix . 'ig_contacts_ips',
260
- 'IG_FORMS_TABLE' => $wpdb->prefix . 'ig_forms',
261
- 'IG_LISTS_TABLE' => $wpdb->prefix . 'ig_lists',
262
- 'IG_LISTS_CONTACTS_TABLE' => $wpdb->prefix . 'ig_lists_contacts',
263
- 'IG_MAILING_QUEUE_TABLE' => $wpdb->prefix . 'ig_mailing_queue',
264
- 'IG_SENDING_QUEUE_TABLE' => $wpdb->prefix . 'ig_sending_queue',
265
- 'IG_BLOCKED_EMAILS_TABLE' => $wpdb->prefix . 'ig_blocked_emails',
266
- 'IG_ACTIONS_TABLE' => $wpdb->prefix . 'ig_actions',
267
- 'IG_LINKS_TABLE' => $wpdb->prefix . 'ig_links',
268
- 'IG_CONTACT_META_TABLE' => $wpdb->prefix . 'ig_contact_meta',
269
- //Statuses
270
- 'IG_EMAIL_STATUS_IN_QUEUE' => 'in_queue',
271
- 'IG_EMAIL_STATUS_SENDING' => 'sending',
272
- 'IG_EMAIL_STATUS_SENT' => 'sent',
273
- // Opt-In Types
274
- 'IG_SINGLE_OPTIN' => 1,
275
- 'IG_DOUBLE_OPTIN' => 2,
276
-
277
- 'IG_CAMPAIGN_TYPE_POST_NOTIFICATION' => 'post_notification',
278
- 'IG_CAMPAIGN_TYPE_NEWSLETTER' => 'newsletter',
279
- 'IG_CAMPAIGN_TYPE_POST_DIGEST' => 'post_digest',
280
- 'IG_DEFAULT_BATCH_SIZE' => 100,
281
- 'IG_MAX_MEMORY_LIMIT' => '-1',
282
- 'IG_SET_TIME_LIMIT' => 0,
283
-
284
- 'IG_DEFAULT_LIST' => 'Test',
285
- 'IG_MAIN_LIST' => 'Main',
286
-
287
- 'IG_CONTACT_SUBSCRIBE' => 1,
288
- 'IG_MESSAGE_SENT' => 2,
289
- 'IG_MESSAGE_OPEN' => 3,
290
- 'IG_LINK_CLICK' => 4,
291
- 'IG_CONTACT_UNSUBSCRIBE' => 5,
292
- 'IG_MESSAGE_SOFT_BOUNCE' => 6,
293
- 'IG_MESSAGE_HARD_BOUNCE' => 7,
294
- 'IG_MESSAGE_ERROR' => 8
295
 
296
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
- foreach ( $constants as $constant => $value ) {
299
- $this->define( $constant, $value );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  }
301
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
 
304
  /**
@@ -333,103 +591,105 @@ class Email_Subscribers {
333
  */
334
  private function load_dependencies() {
335
 
336
- /**
337
- * The class responsible for orchestrating the actions and filters of the
338
- * core plugin.
339
- */
340
- $required_files = array(
341
-
342
- // Loader
343
- 'includes/class-email-subscribers-loader.php',
344
- // Language
345
- 'includes/class-email-subscribers-i18n.php',
346
- //Logger
347
- 'includes/logs/class-ig-logger-interface.php',
348
- 'includes/logs/class-ig-log-handler-interface.php',
349
- 'includes/logs/class-ig-log-handler.php',
350
- 'includes/logs/log-handlers/class-ig-log-handler-file.php',
351
- 'includes/logs/class-ig-log-levels.php',
352
- 'includes/class-ig-logger.php',
353
- //Notices
354
- 'includes/notices/class-es-admin-notices.php',
355
- // Database Classes
356
- 'includes/db/class-es-db.php',
357
- 'includes/db/class-es-db-mailing-queue.php',
358
- 'includes/db/class-es-db-lists.php',
359
- 'includes/db/class-es-db-contacts.php',
360
- 'includes/db/class-es-db-lists-contacts.php',
361
- 'includes/db/class-es-db-sending-queue.php',
362
- 'includes/db/class-es-db-notifications.php',
363
- 'includes/db/class-es-db-campaigns.php',
364
- 'includes/db/class-es-db-forms.php',
365
- 'includes/db/class-es-db-blocked-emails.php',
366
- // Mailer Class
367
- 'includes/class-es-mailer.php',
368
- 'includes/mailers/class-es-base-mailer.php',
369
- 'includes/mailers/class-es-pepipost-mailer.php',
370
- // Common Class
371
- 'includes/class-es-common.php',
372
- // Admin Classes
373
- 'includes/admin/class-es-lists-table.php',
374
- 'includes/admin/class-es-subscribers-table.php',
375
- 'includes/admin/class-es-post-notifications.php',
376
- 'includes/admin/class-es-templates-table.php',
377
- 'includes/admin/class-es-campaigns-table.php',
378
- 'includes/admin/class-es-reports-table.php',
379
- 'includes/admin/class-es-forms-table.php',
380
- 'includes/admin/class-es-queue.php',
381
- 'includes/admin/class-es-cron.php',
382
- 'includes/admin/class-es-newsletters.php',
383
- 'includes/admin/class-es-tools.php',
384
- 'includes/admin/class-es-admin-settings.php',
385
- 'includes/admin/class-es-widget.php',
386
- 'includes/admin/class-es-old-widget.php',
387
- 'includes/admin/class-es-form-widget.php',
388
- 'includes/admin/class-es-export-subscribers.php',
389
- 'includes/admin/class-es-import-subscribers.php',
390
- 'includes/admin/class-es-info.php',
391
- 'includes/admin/class-es-handle-post-notification.php',
392
- 'includes/admin/class-es-handle-subscription.php',
393
- 'includes/admin/class-es-handle-sync-wp-user.php',
394
- 'includes/admin/class-es-subscription-throttaling.php',
395
- 'includes/admin/class-es-actions.php',
396
- 'includes/admin/class-es-tracking.php',
397
- //includes
398
- 'includes/upgrade/es-update-functions.php',
399
- 'includes/es-core-functions.php',
400
- 'includes/class-es-install.php',
401
- // Main public class
402
- 'public/class-email-subscribers-public.php',
403
- // Partials
404
- 'admin/partials/admin-header.php',
405
- 'public/partials/class-es-shortcode.php',
406
- // Backward Compatibility with Rainmaker
407
- 'includes/es-backward.php',
408
- // Main Admin Class
409
- 'admin/class-email-subscribers-admin.php',
410
-
411
- 'includes/pro-features.php',
412
-
413
- // Feedback
414
- 'includes/feedback/class-ig-tracker.php',
415
- 'includes/feedback/class-ig-feedback.php',
416
- 'includes/feedback.php'
417
- );
418
-
419
- foreach ( $required_files as $file ) {
420
- $file_path = plugin_dir_path( dirname( __FILE__ ) ) . $file;
421
-
422
- if ( is_file( $file_path ) ) {
423
- require_once $file_path;
424
- } else {
425
- echo $file_path;
426
- die( 'Not Found' );
427
- }
428
- }
 
429
 
430
  add_shortcode( 'email-subscribers', array( 'ES_Shortcode', 'render_es_subscription_shortcode' ) );
431
  add_shortcode( 'email-subscribers-advanced-form', array( 'ES_Shortcode', 'render_es_advanced_form' ) );
432
  add_shortcode( 'email-subscribers-form', array( 'ES_Shortcode', 'render_es_form' ) );
 
433
  $this->loader = new Email_Subscribers_Loader();
434
 
435
  }
@@ -462,6 +722,7 @@ class Email_Subscribers {
462
  $this->loader->add_action( 'plugins_loaded', $plugin_admin, 'plugins_loaded' );
463
 
464
  $this->loader->add_filter( 'ig_es_lite_do_send', $plugin_admin, 'do_send', 10, 2 );
 
465
 
466
  $this->loader->add_action( 'wp_ajax_count_contacts_by_list', $plugin_admin, 'count_contacts_by_list' );
467
 
@@ -541,14 +802,6 @@ class Email_Subscribers {
541
  register_widget( 'ES_Form_Widget' );
542
  }
543
 
544
- public static function get_request( $request ) {
545
- if ( isset( $_REQUEST[ $request ] ) ) {
546
- return wp_unslash( $_REQUEST[ $request ] );
547
- }
548
-
549
- return '';
550
- }
551
-
552
  public static function insert_widget_in_sidebar( $widget_id, $widget_data, $sidebar ) {
553
  // Retrieve sidebars, widgets and their instances
554
  $sidebars_widgets = get_option( 'sidebars_widgets', array() );
@@ -576,4 +829,61 @@ class Email_Subscribers {
576
 
577
  return $schedules;
578
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
  }
33
  * @author Your Name <email@example.com>
34
  */
35
  class Email_Subscribers {
36
+ /**
37
+ *
38
+ * @since 4.2.1
39
+ *
40
+ * @var Email_Subscribers The one true Email_Subscribers
41
+ *
42
+ */
43
+ private static $instance;
44
+
45
+ /**
46
+ * ES_Queue object
47
+ *
48
+ * @since 4.2.1
49
+ * @var object|ES_Queue
50
+ *
51
+ */
52
+ public $queue;
53
+
54
+ /**
55
+ * ES_DB_Queue object
56
+ *
57
+ * @since 4.2.1
58
+ * @var object|ES_DB_Queue
59
+ *
60
+ */
61
+ public $queue_db;
62
+ /**
63
+ * ES_Actions object
64
+ *
65
+ * @since 4.2.1
66
+ * @var object|ES_Actions
67
+ *
68
+ */
69
+ public $actions;
70
+
71
+ /**
72
+ * ES_DB_Actions object
73
+ *
74
+ * @since 4.2.1
75
+ * @var object|ES_DB_Actions
76
+ *
77
+ */
78
+ public $actions_db;
79
+
80
+ /**
81
+ * Feedback object
82
+ *
83
+ * @since 4.2.1
84
+ *
85
+ * @var $feedback
86
+ *
87
+ */
88
+ public $feedback;
89
+
90
+ /**
91
+ * Tracker Object
92
+ *
93
+ * @since 4.2.1
94
+ *
95
+ * @var $tracker
96
+ *
97
+ */
98
+ public $tracker;
99
+
100
+ /**
101
+ * @since 4.2.1
102
+ *
103
+ * @var object|ES_Campaigns_Table
104
+ */
105
+ public $campaigns;
106
+
107
+ /**
108
+ * ES_DB_Campaigns object
109
+ *
110
+ * @since 4.2.1
111
+ *
112
+ * @var object|ES_DB_Campaigns
113
+ *
114
+ */
115
+ public $campaigns_db;
116
+
117
+ /**
118
+ * @since 4.2.1
119
+ * @var object|ES_Lists_Table
120
+ *
121
+ */
122
+ public $lists;
123
+
124
+ /**
125
+ * @since 4.2.1
126
+ *
127
+ * @var object|ES_DB_Lists
128
+ *
129
+ */
130
+ public $lists_db;
131
+
132
+
133
+ /**
134
+ * @since 4.2.1
135
+ * @var object|ES_Forms_Table
136
+ *
137
+ */
138
+ public $forms;
139
+
140
+ /**
141
+ * @since 4.2.1
142
+ *
143
+ * @var object|ES_DB_Forms
144
+ */
145
+ public $forms_db;
146
+
147
+ /**
148
+ * @since 4.2.1
149
+ *
150
+ * @var object|ES_Contacts_Table
151
+ */
152
+ public $contacts;
153
+
154
+ /**
155
+ * @since 4.2.1
156
+ *
157
+ * @var object|ES_DB_Contacts
158
+ */
159
+ public $contacts_db;
160
+
161
+ /**
162
+ *
163
+ * @since 4.2.1
164
+ *
165
+ * @var object|ES_Integrations
166
+ *
167
+ */
168
+ public $integrations;
169
+
170
+ /**
171
+ * @since 4.2.1
172
+ *
173
+ * @var object|IG_Logger
174
+ *
175
+ */
176
+ public $logger;
177
+
178
  /**
179
  * The loader that's responsible for maintaining and registering all hooks that power
180
  * the plugin.
212
  *
213
  * @since 4.0
214
  */
215
+ public function ___construct() {
216
  global $ig_es_feedback, $ig_es_tracker;
217
 
218
  require_once plugin_dir_path( __FILE__ ) . 'class-email-subscribers-activator.php';
251
  public function add_admin_notice() {
252
  global $ig_es_tracker;
253
 
254
+ $active_plugins = $ig_es_tracker::get_active_plugins();
255
+
256
+ if ( is_admin() && in_array( 'email-subscribers-premium/email-subscribers-premium.php', $active_plugins ) ) {
257
+ $es_pro_plugin_meta_data = get_plugin_data( WP_PLUGIN_DIR . '/email-subscribers-premium/email-subscribers-premium.php' );
258
+ $es_pro_plugin_version = $es_pro_plugin_meta_data['Version'];
259
+
260
+ if ( is_admin() && ! empty( $es_pro_plugin_version ) && version_compare( $es_pro_plugin_version, '4.2.1', '<' ) ) {
261
+ $upgrade_url = admin_url('plugins.php?plugin_status=upgrade');
262
+ ob_start();
263
+ ?>
264
+ <div class="notice notice-error">
265
+ <p><?php echo sprintf( __( '<strong>Email Subscribers</strong> plugin is activated but it won\'t work because it needs <strong>Email Subscribers Premium</strong> plugin to be updated. Please <a href="%s" target="_blank">update</a> plugin first.', 'email-subscribers-premium' ), $upgrade_url); ?></p>
266
+ </div>
267
+ <?php
268
+ return;
269
+ }
270
+ }
271
+
272
  $screen = get_current_screen();
273
  $screen_id = $screen ? $screen->id : '';
274
  $show_on_screens = array(
310
  <?php
311
  return;
312
  }
313
+ if ( is_admin() && ! empty( $es_pro_plugin_version ) && version_compare( $es_pro_plugin_version, '4.2.1', '<' ) ) {
314
  $url = admin_url( "plugins.php?plugin_status=upgrade" );
315
  $es_upgrade_text = __( 'We have released a recommended update of Email subscribers Premium. So kindly ', 'email-subscribers-premium' ) . '<a href=' . $url . ' target="_blank" style="cursor:pointer">' . __( "update to the latest version", "email-subscribers-premium" ) . '</a>' . __( " right now", "email-subscribers-premium" );
316
+ echo '<div class="notice notice-error" style="background-color: #FFF;"><p style="letter-spacing: 0.6px;">' . $es_upgrade_text . '</p></div>';
317
  }
318
  }
319
  $es_premium = 'email-subscribers-premium/email-subscribers-premium.php';
320
  $all_plugins = $ig_es_tracker::get_plugins();
321
  //get pro button
322
+ // if ( ! in_array( $es_premium, $all_plugins ) && is_admin() && ! in_array( $screen_id, array( 'toplevel_page_es_dashboard' ), true ) ) {
323
+ // echo "<div class='notice es-floting-button'><i class='dashicons dashicons-es dashicons-awards'></i> <a href='https://www.icegram.com/email-subscribers-pricing/?utm_source=in_app&utm_medium=get_starter_floating_button&utm_campaign=es_upsale' target='_blank'>" . __( 'Get Starter Now!', 'email-subscribers' ) . "</a></div>";
324
+ // }
325
  //cron notice
326
  $notice_option = get_option( 'ig_es_wp_cron_notice' );
327
 
339
  'email-subscribers' ) . '</a></p></div>';
340
  }
341
 
342
+ $sequence_option_dismiss = get_option( 'ig_es_sequence_release_notice_dismiss' );
343
+ $sequence_option_seen = get_option( 'ig_es_sequence_release_notice_seen' );
344
+ if ( ! in_array( $es_premium, $all_plugins ) && is_admin() && $sequence_option_seen != 'yes' && $sequence_option_dismiss != 'yes' ) {
345
+ $sequence_url = admin_url() . '?es_dismiss_admin_notice=1&option_name=sequence_release_notice_seen';
346
+ $sequence_notice = sprintf( __( '📣 <b>[ Released ]</b> New Feature : <strong>Sequences</strong> (Autoresponders) using Email Subscribers <a href="%s" target="_blank">[Read more]</a>', 'email-subscribers' ), $sequence_url );
347
+ echo '<div class="notice notice-warning" style="background-color: #FFF;"><p style="letter-spacing: 0.6px;">' . $sequence_notice . '<a style="float:right" class="es-admin-btn es-admin-btn-secondary " href="' . admin_url() . '?es_dismiss_admin_notice=1&option_name=sequence_release_notice_dismiss">' . __( 'OK, I Got it!',
 
348
  'email-subscribers' ) . '</a></p></div>';
349
  }
350
 
368
  header( "Location: https://wordpress.org/support/plugin/email-subscribers/reviews/" );
369
  exit();
370
  }
371
+ if ( $option_name === 'sequence_release_notice_seen' ) {
372
+ header( "Location: https://www.icegram.com/autoresponders-the-simplest-way-of-keeping-your-customers-engaged-for-long/?utm_source=es&utm_medium=es_upsale_banner&utm_campaign=es_upsale_sequences" );
373
  exit();
374
  }
375
  if ( $option_name === 'redirect_upsale_notice' ) {
394
 
395
  $upload_dir = wp_upload_dir( null, false );
396
 
397
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_SLUG' ) ) {
398
+ define( 'EMAIL_SUBSCRIBERS_SLUG', 'email-subscribers' );
399
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
+ if ( ! defined( 'IG_LOG_DIR' ) ) {
402
+ define( 'IG_LOG_DIR', $upload_dir['basedir'] . '/ig-logs/' );
403
+ }
404
+
405
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_INCLUDES_DIR' ) ) {
406
+ define( 'EMAIL_SUBSCRIBERS_INCLUDES_DIR', __DIR__ . '/includes' );
407
+ }
408
+
409
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_DIR' ) ) {
410
+ define( 'EMAIL_SUBSCRIBERS_DIR', WP_PLUGIN_DIR . '/email-subscribers' );
411
+ }
412
+
413
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_URL' ) ) {
414
+ define( 'EMAIL_SUBSCRIBERS_URL', WP_PLUGIN_URL . '/email-subscribers' );
415
+ }
416
+
417
+ if ( ! defined( 'ES_EMAILLIST_TABLE' ) ) {
418
+ define( 'ES_EMAILLIST_TABLE', $wpdb->prefix . 'es_emaillist' );
419
+ }
420
+
421
+ if ( ! defined( 'EMAIL_LIST_TABLE' ) ) {
422
+ define( 'EMAIL_LIST_TABLE', $wpdb->prefix . 'es_lists' );
423
+ }
424
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE' ) ) {
425
+ define( 'EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE', $wpdb->prefix . 'es_notification' );
426
+ }
427
+
428
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_STATS_TABLE' ) ) {
429
+ define( 'EMAIL_SUBSCRIBERS_STATS_TABLE', $wpdb->prefix . 'es_deliverreport' );
430
+ }
431
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_SENT_TABLE' ) ) {
432
+ define( 'EMAIL_SUBSCRIBERS_SENT_TABLE', $wpdb->prefix . 'es_sentdetails' );
433
+ }
434
 
435
+ if ( ! defined( 'EMAIL_TEMPLATES_TABLE' ) ) {
436
+ define( 'EMAIL_TEMPLATES_TABLE', $wpdb->prefix . 'es_templates' );
437
+ }
438
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_ADVANCED_FORM' ) ) {
439
+ define( 'EMAIL_SUBSCRIBERS_ADVANCED_FORM', $wpdb->prefix . 'es_advanced_form' );
440
+ }
441
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_LIST_MAX' ) ) {
442
+ define( 'EMAIL_SUBSCRIBERS_LIST_MAX', 40 );
443
+ }
444
+ if ( ! defined( 'EMAIL_SUBSCRIBERS_CRON_INTERVAL' ) ) {
445
+ define( 'EMAIL_SUBSCRIBERS_CRON_INTERVAL', 300 );
446
+ }
447
+ if ( ! defined( 'IG_CAMPAIGNS_TABLE' ) ) {
448
+ define( 'IG_CAMPAIGNS_TABLE', $wpdb->prefix . 'ig_campaigns' );
449
+ }
450
+ if ( ! defined( 'IG_CONTACTS_TABLE' ) ) {
451
+ define( 'IG_CONTACTS_TABLE', $wpdb->prefix . 'ig_contacts' );
452
+ }
453
+ if ( ! defined( 'IG_CONTACTS_IPS_TABLE' ) ) {
454
+ define( 'IG_CONTACTS_IPS_TABLE', $wpdb->prefix . 'ig_contacts_ips' );
455
+ }
456
+ if ( ! defined( 'IG_FORMS_TABLE' ) ) {
457
+ define( 'IG_FORMS_TABLE', $wpdb->prefix . 'ig_forms' );
458
+ }
459
+ if ( ! defined( 'IG_LISTS_TABLE' ) ) {
460
+ define( 'IG_LISTS_TABLE', $wpdb->prefix . 'ig_lists' );
461
+ }
462
+ if ( ! defined( 'IG_LISTS_CONTACTS_TABLE' ) ) {
463
+ define( 'IG_LISTS_CONTACTS_TABLE', $wpdb->prefix . 'ig_lists_contacts' );
464
+ }
465
+ if ( ! defined( 'IG_MAILING_QUEUE_TABLE' ) ) {
466
+ define( 'IG_MAILING_QUEUE_TABLE', $wpdb->prefix . 'ig_mailing_queue' );
467
+ }
468
+ if ( ! defined( 'IG_SENDING_QUEUE_TABLE' ) ) {
469
+ define( 'IG_SENDING_QUEUE_TABLE', $wpdb->prefix . 'ig_sending_queue' );
470
+ }
471
+ if ( ! defined( 'IG_BLOCKED_EMAILS_TABLE' ) ) {
472
+ define( 'IG_BLOCKED_EMAILS_TABLE', $wpdb->prefix . 'ig_blocked_emails' );
473
+ }
474
+ if ( ! defined( 'IG_ACTIONS_TABLE' ) ) {
475
+ define( 'IG_ACTIONS_TABLE', $wpdb->prefix . 'ig_actions' );
476
+ }
477
+ if ( ! defined( 'IG_LINKS_TABLE' ) ) {
478
+ define( 'IG_LINKS_TABLE', $wpdb->prefix . 'ig_links' );
479
  }
480
 
481
+ if ( ! defined( 'IG_CONTACT_META_TABLE' ) ) {
482
+ define( 'IG_CONTACT_META_TABLE', $wpdb->prefix . 'ig_contactmeta' );
483
+ }
484
+
485
+ if ( ! defined( 'IG_QUEUE_TABLE' ) ) {
486
+ define( 'IG_QUEUE_TABLE', $wpdb->prefix . 'ig_queue' );
487
+ }
488
+
489
+ if ( ! defined( 'IG_EMAIL_STATUS_IN_QUEUE' ) ) {
490
+ define( 'IG_EMAIL_STATUS_IN_QUEUE', 'in_queue' );
491
+ }
492
+ if ( ! defined( 'IG_EMAIL_STATUS_SENDING' ) ) {
493
+ define( 'IG_EMAIL_STATUS_SENDING', 'sending' );
494
+ }
495
+ if ( ! defined( 'IG_EMAIL_STATUS_SENT' ) ) {
496
+ define( 'IG_EMAIL_STATUS_SENT', 'sent' );
497
+ }
498
+ if ( ! defined( 'IG_SINGLE_OPTIN' ) ) {
499
+ define( 'IG_SINGLE_OPTIN', 1 );
500
+ }
501
+ if ( ! defined( 'IG_DOUBLE_OPTIN' ) ) {
502
+ define( 'IG_DOUBLE_OPTIN', 2 );
503
+ }
504
+ if ( ! defined( 'IG_CAMPAIGN_TYPE_POST_NOTIFICATION' ) ) {
505
+ define( 'IG_CAMPAIGN_TYPE_POST_NOTIFICATION', 'post_notification' );
506
+ }
507
+ if ( ! defined( 'IG_CAMPAIGN_TYPE_NEWSLETTER' ) ) {
508
+ define( 'IG_CAMPAIGN_TYPE_NEWSLETTER', 'newsletter' );
509
+ }
510
+ if ( ! defined( 'IG_CAMPAIGN_TYPE_POST_DIGEST' ) ) {
511
+ define( 'IG_CAMPAIGN_TYPE_POST_DIGEST', 'post_digest' );
512
+ }
513
+ if ( ! defined( 'IG_CAMPAIGN_TYPE_SEQUENCE' ) ) {
514
+ define( 'IG_CAMPAIGN_TYPE_SEQUENCE', 'sequence' );
515
+ }
516
+
517
+ if ( ! defined( 'IG_CAMPAIGN_TYPE_SEQUENCE_MESSAGE' ) ) {
518
+ define( 'IG_CAMPAIGN_TYPE_SEQUENCE_MESSAGE', 'sequence_message' );
519
+ }
520
+
521
+ if ( ! defined( 'IG_DEFAULT_BATCH_SIZE' ) ) {
522
+ define( 'IG_DEFAULT_BATCH_SIZE', 100 );
523
+ }
524
+ if ( ! defined( 'IG_MAX_MEMORY_LIMIT' ) ) {
525
+ define( 'IG_MAX_MEMORY_LIMIT', '-1' );
526
+ }
527
+ if ( ! defined( 'IG_SET_TIME_LIMIT' ) ) {
528
+ define( 'IG_SET_TIME_LIMIT', 0 );
529
+ }
530
+ if ( ! defined( 'IG_DEFAULT_LIST' ) ) {
531
+ define( 'IG_DEFAULT_LIST', 'Test' );
532
+ }
533
+ if ( ! defined( 'IG_MAIN_LIST' ) ) {
534
+ define( 'IG_MAIN_LIST', 'Main' );
535
+ }
536
+ if ( ! defined( 'IG_CONTACT_SUBSCRIBE' ) ) {
537
+ define( 'IG_CONTACT_SUBSCRIBE', 1 );
538
+ }
539
+ if ( ! defined( 'IG_MESSAGE_SENT' ) ) {
540
+ define( 'IG_MESSAGE_SENT', 2 );
541
+ }
542
+ if ( ! defined( 'IG_MESSAGE_OPEN' ) ) {
543
+ define( 'IG_MESSAGE_OPEN', 3 );
544
+ }
545
+ if ( ! defined( 'IG_LINK_CLICK' ) ) {
546
+ define( 'IG_LINK_CLICK', 4 );
547
+ }
548
+ if ( ! defined( 'IG_CONTACT_UNSUBSCRIBE' ) ) {
549
+ define( 'IG_CONTACT_UNSUBSCRIBE', 5 );
550
+ }
551
+ if ( ! defined( 'IG_MESSAGE_SOFT_BOUNCE' ) ) {
552
+ define( 'IG_MESSAGE_SOFT_BOUNCE', 6 );
553
+ }
554
+ if ( ! defined( 'IG_MESSAGE_HARD_BOUNCE' ) ) {
555
+ define( 'IG_MESSAGE_HARD_BOUNCE', 7 );
556
+ }
557
+ if ( ! defined( 'IG_MESSAGE_ERROR' ) ) {
558
+ define( 'IG_MESSAGE_ERROR', 8 );
559
+ }
560
  }
561
 
562
  /**
591
  */
592
  private function load_dependencies() {
593
 
594
+ // Loader
595
+ require_once ES_PLUGIN_DIR . 'includes/class-email-subscribers-loader.php';
596
+
597
+ // Language
598
+ require_once ES_PLUGIN_DIR . 'includes/class-email-subscribers-i18n.php';
599
+
600
+ // Logs
601
+ require_once ES_PLUGIN_DIR . 'includes/logs/class-ig-logger-interface.php';
602
+ require_once ES_PLUGIN_DIR . 'includes/logs/class-ig-log-handler-interface.php';
603
+ require_once ES_PLUGIN_DIR . 'includes/logs/class-ig-log-handler.php';
604
+ require_once ES_PLUGIN_DIR . 'includes/logs/log-handlers/class-ig-log-handler-file.php';
605
+ require_once ES_PLUGIN_DIR . 'includes/logs/class-ig-log-levels.php';
606
+ require_once ES_PLUGIN_DIR . 'includes/class-ig-logger.php';
607
+
608
+ // Admin Notices
609
+ require_once ES_PLUGIN_DIR . 'includes/notices/class-es-admin-notices.php';
610
+
611
+ // DB Classes
612
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db.php';
613
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-queue.php';
614
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-mailing-queue.php';
615
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-lists.php';
616
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-contacts.php';
617
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-lists-contacts.php';
618
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-sending-queue.php';
619
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-notifications.php';
620
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-campaigns.php';
621
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-forms.php';
622
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-blocked-emails.php';
623
+ require_once ES_PLUGIN_DIR . 'includes/db/class-es-db-actions.php';
624
+
625
+ // Mailers
626
+ require_once ES_PLUGIN_DIR . 'includes/class-es-mailer.php';
627
+ require_once ES_PLUGIN_DIR . 'includes/mailers/class-es-base-mailer.php';
628
+ require_once ES_PLUGIN_DIR . 'includes/mailers/class-es-pepipost-mailer.php';
629
+
630
+
631
+ require_once ES_PLUGIN_DIR . 'includes/class-es-common.php';
632
+
633
+ // Classes
634
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-lists-table.php';
635
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-contacts-table.php';
636
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-post-notifications.php';
637
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-templates-table.php';
638
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-campaigns-table.php';
639
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-reports-table.php';
640
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-forms-table.php';
641
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-queue.php';
642
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-cron.php';
643
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-newsletters.php';
644
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-tools.php';
645
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-admin-settings.php';
646
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-widget.php';
647
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-old-widget.php';
648
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-form-widget.php';
649
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-export-subscribers.php';
650
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-import-subscribers.php';
651
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-info.php';
652
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-handle-post-notification.php';
653
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-handle-subscription.php';
654
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-handle-sync-wp-user.php';
655
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-subscription-throttaling.php';
656
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-actions.php';
657
+ require_once ES_PLUGIN_DIR . 'includes/admin/class-es-tracking.php';
658
+
659
+ // Upgrade functions
660
+ require_once ES_PLUGIN_DIR . 'includes/upgrade/es-update-functions.php';
661
+
662
+ // Core Function
663
+ require_once ES_PLUGIN_DIR . 'includes/es-core-functions.php';
664
+
665
+ // Install Class
666
+ require_once ES_PLUGIN_DIR . 'includes/class-es-install.php';
667
+
668
+ // Public Class
669
+ require_once ES_PLUGIN_DIR . 'public/class-email-subscribers-public.php';
670
+
671
+ // Partials
672
+ require_once ES_PLUGIN_DIR . 'admin/partials/admin-header.php';
673
+ require_once ES_PLUGIN_DIR . 'public/partials/class-es-shortcode.php';
674
+
675
+ // Backward Compatibility
676
+ require_once ES_PLUGIN_DIR . 'includes/es-backward.php';
677
+
678
+ // Admin Main Class
679
+ require_once ES_PLUGIN_DIR . 'admin/class-email-subscribers-admin.php';
680
+
681
+ // Pro Features indicator
682
+ require_once ES_PLUGIN_DIR . 'includes/pro-features.php';
683
+
684
+ // Feedback Class
685
+ require_once ES_PLUGIN_DIR . 'includes/feedback/class-ig-tracker.php';
686
+ require_once ES_PLUGIN_DIR . 'includes/feedback/class-ig-feedback.php';
687
+ require_once ES_PLUGIN_DIR . 'includes/feedback.php';
688
 
689
  add_shortcode( 'email-subscribers', array( 'ES_Shortcode', 'render_es_subscription_shortcode' ) );
690
  add_shortcode( 'email-subscribers-advanced-form', array( 'ES_Shortcode', 'render_es_advanced_form' ) );
691
  add_shortcode( 'email-subscribers-form', array( 'ES_Shortcode', 'render_es_form' ) );
692
+
693
  $this->loader = new Email_Subscribers_Loader();
694
 
695
  }
722
  $this->loader->add_action( 'plugins_loaded', $plugin_admin, 'plugins_loaded' );
723
 
724
  $this->loader->add_filter( 'ig_es_lite_do_send', $plugin_admin, 'do_send', 10, 2 );
725
+ $this->loader->add_filter( 'set-screen-option', $plugin_admin, 'save_screen_options', 20, 3 );
726
 
727
  $this->loader->add_action( 'wp_ajax_count_contacts_by_list', $plugin_admin, 'count_contacts_by_list' );
728
 
802
  register_widget( 'ES_Form_Widget' );
803
  }
804
 
 
 
 
 
 
 
 
 
805
  public static function insert_widget_in_sidebar( $widget_id, $widget_data, $sidebar ) {
806
  // Retrieve sidebars, widgets and their instances
807
  $sidebars_widgets = get_option( 'sidebars_widgets', array() );
829
 
830
  return $schedules;
831
  }
832
+
833
+ /**
834
+ * Return a true instance of a class
835
+ *
836
+ * @return Email_Subscribers
837
+ *
838
+ * @since 4.2.1
839
+ */
840
+ public static function instance() {
841
+ if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Email_Subscribers ) ) {
842
+ global $ig_es_feedback, $ig_es_tracker;
843
+
844
+ self::$instance = new Email_Subscribers();
845
+
846
+ require_once plugin_dir_path( __FILE__ ) . 'class-email-subscribers-activator.php';
847
+ require_once plugin_dir_path( __FILE__ ) . 'class-email-subscribers-deactivator.php';
848
+
849
+ self::$instance->email_subscribers = 'email-subscribers';
850
+
851
+ self::$instance->define_constants();
852
+ self::$instance->load_dependencies();
853
+ self::$instance->set_locale();
854
+ self::$instance->define_admin_hooks();
855
+ self::$instance->define_public_hooks();
856
+
857
+ add_action( 'widgets_init', array( self::$instance, 'register_es_widget' ) );
858
+ add_filter( 'cron_schedules', array( self::$instance, 'es_add_cron_interval' ) );
859
+
860
+ self::$instance->queue_db = new ES_DB_Queue();
861
+ self::$instance->actions_db = new ES_DB_Actions();
862
+ self::$instance->campaigns_db = new ES_DB_Campaigns();
863
+ self::$instance->lists_db = new ES_DB_Lists();
864
+ self::$instance->forms_db = new ES_DB_Forms();
865
+ self::$instance->contacts_db = new ES_DB_Contacts();
866
+ self::$instance->queue = new ES_Queue();
867
+ self::$instance->actions = new ES_Actions();
868
+
869
+ self::$instance->logger = get_ig_logger();
870
+
871
+ $ig_es_tracker = 'IG_Tracker_V_' . str_replace( '.', '_', IG_ES_FEEDBACK_VERSION );
872
+ if ( is_admin() ) {
873
+ $ig_es_feedback_class = 'IG_Feedback_V_' . str_replace( '.', '_', IG_ES_FEEDBACK_VERSION );
874
+ $ig_es_feedback = new $ig_es_feedback_class( 'Email Subscribers', 'email-subscribers', 'ig_es', 'esfree.', false );
875
+ $ig_es_feedback->render_deactivate_feedback();
876
+ }
877
+
878
+ add_action( 'admin_notices', array( self::$instance, 'add_admin_notice' ) );
879
+ add_action( 'admin_init', array( self::$instance, 'es_dismiss_admin_notice' ) );
880
+
881
+ if ( ! post_type_exists( 'es_template' ) ) {
882
+ add_action( 'init', array( 'Email_Subscribers_Activator', 'register_email_templates' ) );
883
+ }
884
+
885
+ }
886
+
887
+ return self::$instance;
888
+ }
889
  }
includes/class-es-common.php CHANGED
@@ -151,7 +151,7 @@ Class ES_Common {
151
 
152
  $default_option[0] = __( $default_label, 'email-subscribers' );
153
 
154
- $lists = ES_DB_Lists::get_list_id_name_map();
155
  $lists = $default_option + $lists;
156
 
157
  $dropdown = '';
@@ -192,7 +192,7 @@ Class ES_Common {
192
 
193
 
194
  public static function prepare_list_checkbox( $selected = array() ) {
195
- $lists = ES_DB_Lists::get_list_id_name_map();
196
 
197
  $html = '';
198
  foreach ( $lists as $key => $list ) {
@@ -728,7 +728,7 @@ Class ES_Common {
728
  $desc = ! empty( $data['es_desc'] ) ? $data['es_desc'] : '';
729
  $group = ! empty( $data['es_group'] ) ? $data['es_group'] : '';
730
 
731
- $list = ES_DB_Lists::get_list_by_name( $group );
732
 
733
  $list_id = 1;
734
  if ( ! empty( $list ) ) {
@@ -936,7 +936,7 @@ Class ES_Common {
936
  *
937
  */
938
  public static function render_feedback_widget( $params ) {
939
- global $ig_es_feedback;
940
 
941
  $feedback = $ig_es_feedback;
942
 
@@ -1022,9 +1022,9 @@ Class ES_Common {
1022
  public static function get_ig_es_meta_info() {
1023
 
1024
  $total_contacts = ES_DB_Contacts::get_total_subscribers();
1025
- $total_lists = ES_DB_Lists::count_lists();
1026
- $total_newsletters = ES_DB_Campaigns::get_total_campaigns_by_type( 'newsletter' );
1027
- $total_post_notifications = ES_DB_Campaigns::get_total_campaigns_by_type( 'post_notification' );
1028
 
1029
  $meta_info = array(
1030
  'total_contacts' => $total_contacts,
@@ -1049,7 +1049,7 @@ Class ES_Common {
1049
  public static function prepare_list_name_by_ids( $list_ids = array() ) {
1050
  $list_name = '';
1051
  if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
1052
- $lists_id_name_map = ES_DB_Lists::get_list_id_name_map();
1053
  $lists_name = array();
1054
  foreach ( $list_ids as $list_id ) {
1055
  if ( ! empty( $lists_id_name_map[ $list_id ] ) ) {
151
 
152
  $default_option[0] = __( $default_label, 'email-subscribers' );
153
 
154
+ $lists = ES()->lists_db->get_list_id_name_map();
155
  $lists = $default_option + $lists;
156
 
157
  $dropdown = '';
192
 
193
 
194
  public static function prepare_list_checkbox( $selected = array() ) {
195
+ $lists = ES()->lists_db->get_list_id_name_map();
196
 
197
  $html = '';
198
  foreach ( $lists as $key => $list ) {
728
  $desc = ! empty( $data['es_desc'] ) ? $data['es_desc'] : '';
729
  $group = ! empty( $data['es_group'] ) ? $data['es_group'] : '';
730
 
731
+ $list = ES()->lists_db->get_list_by_name( $group );
732
 
733
  $list_id = 1;
734
  if ( ! empty( $list ) ) {
936
  *
937
  */
938
  public static function render_feedback_widget( $params ) {
939
+ global $ig_es_feedback;
940
 
941
  $feedback = $ig_es_feedback;
942
 
1022
  public static function get_ig_es_meta_info() {
1023
 
1024
  $total_contacts = ES_DB_Contacts::get_total_subscribers();
1025
+ $total_lists = ES()->lists_db->count_lists();
1026
+ $total_newsletters = ES()->campaigns_db->get_total_newsletters();
1027
+ $total_post_notifications = ES()->campaigns_db->get_total_post_notifications;
1028
 
1029
  $meta_info = array(
1030
  'total_contacts' => $total_contacts,
1049
  public static function prepare_list_name_by_ids( $list_ids = array() ) {
1050
  $list_name = '';
1051
  if ( is_array( $list_ids ) && count( $list_ids ) > 0 ) {
1052
+ $lists_id_name_map = ES()->lists_db->get_list_id_name_map();
1053
  $lists_name = array();
1054
  foreach ( $list_ids as $list_id ) {
1055
  if ( ! empty( $lists_id_name_map[ $list_id ] ) ) {
includes/class-es-install.php CHANGED
@@ -135,6 +135,12 @@ class ES_Install {
135
  'ig_es_update_420_create_tables',
136
  'ig_es_update_420_migrate_mailer_options',
137
  'ig_es_update_420_db_version'
 
 
 
 
 
 
138
  )
139
 
140
  );
@@ -828,24 +834,7 @@ class ES_Install {
828
  $collate = $wpdb->get_charset_collate();
829
  }
830
 
831
- $tables = "CREATE TABLE `{$wpdb->prefix}ig_actions` (
832
- `contact_id` bigint(20) UNSIGNED DEFAULT NULL,
833
- `message_id` bigint(20) UNSIGNED DEFAULT NULL,
834
- `campaign_id` bigint(20) UNSIGNED DEFAULT NULL,
835
- `type` tinyint(1) NOT NULL DEFAULT 0,
836
- `count` int(11) UNSIGNED NOT NULL DEFAULT 0,
837
- `link_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
838
- `list_id` int(11) UNSIGNED NOT NULL DEFAULT 0,
839
- `created_at` int(11) UNSIGNED NOT NULL DEFAULT 0,
840
- `updated_at` int(11) UNSIGNED NOT NULL DEFAULT 0,
841
- UNIQUE KEY `id` (`contact_id`,`message_id`, `campaign_id`,`type`,`link_id`, `list_id`),
842
- KEY `contact_id` (`contact_id`),
843
- KEY `message_id` (`message_id`),
844
- KEY `campaign_id` (`campaign_id`),
845
- KEY `type` (`type`)
846
- ) $collate;
847
-
848
- CREATE TABLE `{$wpdb->prefix}ig_contact_meta` (
849
  `id` int(10) NOT NULL AUTO_INCREMENT,
850
  `contact_id` bigint(10) unsigned NOT NULL,
851
  `meta_key` varchar(255) DEFAULT NULL,
@@ -872,10 +861,83 @@ class ES_Install {
872
  return $tables;
873
  }
874
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
  private static function get_schema() {
876
 
877
  $tables = self::get_ig_es_400_schema();
878
  $tables .= self::get_ig_es_420_schema();
 
879
 
880
  return $tables;
881
  }
@@ -884,7 +946,7 @@ class ES_Install {
884
 
885
  $list_name = IG_DEFAULT_LIST;
886
 
887
- $list_id = ES_DB_Lists::add_list( $list_name );
888
 
889
  if ( $list_id ) {
890
 
@@ -927,7 +989,7 @@ class ES_Install {
927
  }
928
 
929
  // Also Add Main List
930
- $main_list_id = ES_DB_Lists::add_list( IG_MAIN_LIST );
931
  //add admin to main list
932
  if ( $main_list_id && $contact_id ) {
933
  $data = array(
@@ -986,7 +1048,7 @@ class ES_Install {
986
 
987
  // Create Broadcast Campaign
988
 
989
- $default_list = ES_DB_Lists::get_list_by_name( IG_DEFAULT_LIST );
990
 
991
  if ( ! empty( $default_list ) ) {
992
  $list_id = $default_list['id'];
@@ -1002,7 +1064,7 @@ class ES_Install {
1002
  $data['base_template_id'] = $post_id;
1003
  $data['status'] = 1;
1004
 
1005
- $campaign_id = ES_DB_Campaigns::save_campaign( $data );
1006
 
1007
  $subscribers = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
1008
  if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
@@ -1084,7 +1146,7 @@ class ES_Install {
1084
  // Insert the post into the database
1085
  $post_id = wp_insert_post( $post );
1086
 
1087
- $default_list = ES_DB_Lists::get_list_by_name( IG_DEFAULT_LIST );
1088
 
1089
  if ( ! empty( $post_id ) ) {
1090
  $list_id = $default_list['id'];
@@ -1115,7 +1177,7 @@ class ES_Install {
1115
  $data['base_template_id'] = $post_id;
1116
  $data['status'] = 1;
1117
 
1118
- $campaign_id = ES_DB_Campaigns::save_campaign( $data );
1119
 
1120
  $subscribers = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
1121
  if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
@@ -1182,7 +1244,7 @@ class ES_Install {
1182
 
1183
  private static function create_default_form() {
1184
  $form_data = array();
1185
- $default_list = ES_DB_Lists::get_list_by_name( IG_MAIN_LIST );
1186
  $list_id = $default_list['id'];
1187
  $body = array(
1188
  array(
135
  'ig_es_update_420_create_tables',
136
  'ig_es_update_420_migrate_mailer_options',
137
  'ig_es_update_420_db_version'
138
+ ),
139
+
140
+ '4.2.1' => array(
141
+ 'ig_es_update_421_drop_tables',
142
+ 'ig_es_update_421_create_tables',
143
+ 'ig_es_update_421_db_version'
144
  )
145
 
146
  );
834
  $collate = $wpdb->get_charset_collate();
835
  }
836
 
837
+ $tables = "CREATE TABLE `{$wpdb->prefix}ig_contact_meta` (
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
838
  `id` int(10) NOT NULL AUTO_INCREMENT,
839
  `contact_id` bigint(10) unsigned NOT NULL,
840
  `meta_key` varchar(255) DEFAULT NULL,
861
  return $tables;
862
  }
863
 
864
+ /**
865
+ * Add new table
866
+ *
867
+ * @return string
868
+ *
869
+ * @since 4.2.1
870
+ */
871
+ public static function get_ig_es_421_schema() {
872
+
873
+ global $wpdb;
874
+
875
+ $collate = '';
876
+
877
+ if ( $wpdb->has_cap( 'collation' ) ) {
878
+ $collate = $wpdb->get_charset_collate();
879
+ }
880
+
881
+ $tables = "CREATE TABLE `{$wpdb->prefix}ig_contactmeta` (
882
+ `meta_id` bigint(20) NOT NULL AUTO_INCREMENT,
883
+ `contact_id` bigint(20) unsigned NOT NULL,
884
+ `meta_key` varchar(255) DEFAULT NULL,
885
+ `meta_value` longtext DEFAULT NULL,
886
+ PRIMARY KEY (meta_id),
887
+ KEY `contact_id` (contact_id),
888
+ KEY `meta_ley` (meta_key)
889
+ ) $collate;
890
+
891
+ CREATE TABLE {$wpdb->prefix}ig_queue (
892
+ `contact_id` bigint(20) unsigned NOT NULL DEFAULT 0,
893
+ `campaign_id` bigint(20) unsigned NOT NULL DEFAULT 0,
894
+ `requeued` tinyint(1) unsigned NOT NULL DEFAULT 0,
895
+ `added` int(11) unsigned NOT NULL DEFAULT 0,
896
+ `timestamp` int(11) unsigned NOT NULL DEFAULT 0,
897
+ `sent_at` int(11) unsigned NOT NULL DEFAULT 0,
898
+ `priority` tinyint(1) unsigned NOT NULL DEFAULT 0,
899
+ `count` tinyint(1) unsigned NOT NULL DEFAULT 0,
900
+ `error` tinyint(1) unsigned NOT NULL DEFAULT 0,
901
+ `ignore_status` tinyint(1) unsigned NOT NULL DEFAULT 0,
902
+ `options` varchar(191) NOT NULL DEFAULT '',
903
+ `tags` longtext NOT NULL,
904
+ UNIQUE KEY `id` (`contact_id`,`campaign_id`,`requeued`,`options`),
905
+ KEY `contact_id` (`contact_id`),
906
+ KEY `campaign_id` (`campaign_id`),
907
+ KEY `requeued` (`requeued`),
908
+ KEY `timestamp` (`timestamp`),
909
+ KEY `priority` (`priority`),
910
+ KEY `count` (`count`),
911
+ KEY `error` (`error`),
912
+ KEY `ignore_status` (`ignore_status`)
913
+ ) $collate;
914
+
915
+ CREATE TABLE `{$wpdb->prefix}ig_actions` (
916
+ `contact_id` bigint(20) UNSIGNED DEFAULT NULL,
917
+ `message_id` bigint(20) UNSIGNED DEFAULT NULL,
918
+ `campaign_id` bigint(20) UNSIGNED DEFAULT NULL,
919
+ `type` tinyint(1) NOT NULL DEFAULT 0,
920
+ `count` int(11) UNSIGNED NOT NULL DEFAULT 0,
921
+ `link_id` bigint(20) UNSIGNED NOT NULL DEFAULT 0,
922
+ `list_id` int(11) UNSIGNED NOT NULL DEFAULT 0,
923
+ `created_at` int(11) UNSIGNED NOT NULL DEFAULT 0,
924
+ `updated_at` int(11) UNSIGNED NOT NULL DEFAULT 0,
925
+ UNIQUE KEY `id` (`contact_id`,`message_id`, `campaign_id`,`type`,`link_id`, `list_id`),
926
+ KEY `contact_id` (`contact_id`),
927
+ KEY `message_id` (`message_id`),
928
+ KEY `campaign_id` (`campaign_id`),
929
+ KEY `type` (`type`)
930
+ ) $collate;
931
+ ";
932
+
933
+ return $tables;
934
+ }
935
+
936
  private static function get_schema() {
937
 
938
  $tables = self::get_ig_es_400_schema();
939
  $tables .= self::get_ig_es_420_schema();
940
+ $tables .= self::get_ig_es_421_schema();
941
 
942
  return $tables;
943
  }
946
 
947
  $list_name = IG_DEFAULT_LIST;
948
 
949
+ $list_id = ES()->lists_db->add_list( $list_name );
950
 
951
  if ( $list_id ) {
952
 
989
  }
990
 
991
  // Also Add Main List
992
+ $main_list_id = ES()->lists_db->add_list( IG_MAIN_LIST );
993
  //add admin to main list
994
  if ( $main_list_id && $contact_id ) {
995
  $data = array(
1048
 
1049
  // Create Broadcast Campaign
1050
 
1051
+ $default_list = ES()->lists_db->get_list_by_name( IG_DEFAULT_LIST );
1052
 
1053
  if ( ! empty( $default_list ) ) {
1054
  $list_id = $default_list['id'];
1064
  $data['base_template_id'] = $post_id;
1065
  $data['status'] = 1;
1066
 
1067
+ $campaign_id = ES()->campaigns_db->save_campaign( $data );
1068
 
1069
  $subscribers = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
1070
  if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
1146
  // Insert the post into the database
1147
  $post_id = wp_insert_post( $post );
1148
 
1149
+ $default_list = ES()->lists_db->get_list_by_name( IG_DEFAULT_LIST );
1150
 
1151
  if ( ! empty( $post_id ) ) {
1152
  $list_id = $default_list['id'];
1177
  $data['base_template_id'] = $post_id;
1178
  $data['status'] = 1;
1179
 
1180
+ $campaign_id = ES()->campaigns_db->save_campaign( $data );
1181
 
1182
  $subscribers = ES_DB_Contacts::get_active_subscribers_by_list_id( $list_id );
1183
  if ( ! empty( $subscribers ) && count( $subscribers ) > 0 ) {
1244
 
1245
  private static function create_default_form() {
1246
  $form_data = array();
1247
+ $default_list = ES()->lists_db->get_list_by_name( IG_MAIN_LIST );
1248
  $list_id = $default_list['id'];
1249
  $body = array(
1250
  array(
includes/class-es-mailer.php CHANGED
@@ -23,14 +23,14 @@ class ES_Mailer {
23
  $content = $notification['body'];
24
  $subject = $notification['subject'];
25
  $guid = $notification['hash'];
26
- $template_id = ES_DB_Campaigns::get_templateid_by_campaign( $notification['id'] );
27
  function temp_fun( $mail ) {
28
  return $mail['email'];
29
  }
30
 
31
  $emails = array_map( "temp_fun", $mails );
32
 
33
- $emails_name_map = ES_DB_Contacts::get_subsribers_email_name_map( $emails );
34
 
35
  foreach ( $mails as $mail ) {
36
  $email = $mail['email'];
@@ -206,6 +206,12 @@ class ES_Mailer {
206
  $email = isset( $keywords['email'] ) ? $keywords['email'] : '';
207
  $first_name = isset( $keywords['first_name'] ) ? $keywords['first_name'] : '';
208
  $last_name = isset( $keywords['last_name'] ) ? $keywords['last_name'] : '';
 
 
 
 
 
 
209
 
210
  $template_content = str_replace( "{{NAME}}", $name, $template_content );
211
  $template_content = str_replace( "{{FIRSTNAME}}", $first_name, $template_content );
@@ -224,18 +230,14 @@ class ES_Mailer {
224
  $data = apply_filters( 'es_after_process_template_body', $data );
225
  $template_content = $data['content'];
226
 
227
- $dbid = $keywords['dbid'];
228
- $contact_guid = ES_DB_Contacts::get_contact_hash_by_id( $dbid );
229
- $guid = $keywords['guid'];
230
- $email = $keywords['email'];
231
 
232
  $link_data = array(
233
  'action' => 'unsubscribe',
234
  'message_id' => ! empty( $keywords['message_id'] ) ? $keywords['message_id'] : 0,
235
  'campaign_id' => ! empty( $keywords['campaign_id'] ) ? $keywords['campaign_id'] : 0,
236
- 'contact_id' => $dbid,
237
  'email' => $email,
238
- 'guid' => $contact_guid
239
  );
240
 
241
  $unsubscribe_link = self::prepare_link( $link_data );
@@ -248,9 +250,9 @@ class ES_Mailer {
248
  $data = array(
249
  'message_id' => $keywords['message_id'],
250
  'campaign_id' => $keywords['campaign_id'],
251
- 'contact_id' => $dbid,
252
  'email' => $email,
253
- 'guid' => $guid
254
  );
255
 
256
  $email_tracking_image = self::get_tracking_pixel( $data );
@@ -384,6 +386,7 @@ class ES_Mailer {
384
 
385
  public static function send( $to_email, $subject, $email_template ) {
386
 
 
387
  $subject = html_entity_decode( $subject, ENT_QUOTES, get_bloginfo( 'charset' ) );
388
  $get_email_type = get_option( 'ig_es_email_type', true );
389
  $site_title = get_bloginfo();
@@ -407,12 +410,12 @@ class ES_Mailer {
407
  $headers[] = "X-Mailer: PHP" . phpversion();
408
  }
409
 
410
- $plain_text_template = self::convert_to_text( $email_template );
411
- $headers[] = "Content-Type: text/html; charset=\"" . get_bloginfo( 'charset' ) . "\"";
412
- $headers = implode( "\n", $headers );
413
- $ig_es_mailer_settings = get_option( 'ig_es_mailer_settings' );
414
- if ( !empty($ig_es_mailer_settings['mailer']) && 'phpmail' !== $ig_es_mailer_settings['mailer'] ) {
415
- $data = array(
416
  'to_email' => $to_email,
417
  'subject' => $subject,
418
  'email_template' => $email_template,
@@ -423,14 +426,16 @@ class ES_Mailer {
423
  'email_type' => $get_email_type
424
  );
425
 
426
- $response = array();
427
  $response = apply_filters( 'ig_es_lite_do_send', $response, $data );
428
- return $response;
429
  } else {
430
- mail( $to_email, $subject, $email_template, $headers );
 
 
 
431
  }
432
 
433
- return '';
434
 
435
  }
436
 
23
  $content = $notification['body'];
24
  $subject = $notification['subject'];
25
  $guid = $notification['hash'];
26
+ $template_id = ES()->campaigns_db->get_template_id_by_campaign( $notification['id'] );
27
  function temp_fun( $mail ) {
28
  return $mail['email'];
29
  }
30
 
31
  $emails = array_map( "temp_fun", $mails );
32
 
33
+ $emails_name_map = ES_DB_Contacts::get_subscribers_email_name_map( $emails );
34
 
35
  foreach ( $mails as $mail ) {
36
  $email = $mail['email'];
206
  $email = isset( $keywords['email'] ) ? $keywords['email'] : '';
207
  $first_name = isset( $keywords['first_name'] ) ? $keywords['first_name'] : '';
208
  $last_name = isset( $keywords['last_name'] ) ? $keywords['last_name'] : '';
209
+ $contact_id = isset( $keywords['dbid'] ) ? $keywords['dbid'] : '';
210
+ $hash = isset( $keywords['hash'] ) ? $keywords['hash'] : '';
211
+
212
+ if ( empty( $hash ) ) {
213
+ $hash = ES_DB_Contacts::get_contact_hash_by_id( $contact_id );
214
+ }
215
 
216
  $template_content = str_replace( "{{NAME}}", $name, $template_content );
217
  $template_content = str_replace( "{{FIRSTNAME}}", $first_name, $template_content );
230
  $data = apply_filters( 'es_after_process_template_body', $data );
231
  $template_content = $data['content'];
232
 
 
 
 
 
233
 
234
  $link_data = array(
235
  'action' => 'unsubscribe',
236
  'message_id' => ! empty( $keywords['message_id'] ) ? $keywords['message_id'] : 0,
237
  'campaign_id' => ! empty( $keywords['campaign_id'] ) ? $keywords['campaign_id'] : 0,
238
+ 'contact_id' => $contact_id,
239
  'email' => $email,
240
+ 'guid' => $hash
241
  );
242
 
243
  $unsubscribe_link = self::prepare_link( $link_data );
250
  $data = array(
251
  'message_id' => $keywords['message_id'],
252
  'campaign_id' => $keywords['campaign_id'],
253
+ 'contact_id' => $contact_id,
254
  'email' => $email,
255
+ 'guid' => $hash
256
  );
257
 
258
  $email_tracking_image = self::get_tracking_pixel( $data );
386
 
387
  public static function send( $to_email, $subject, $email_template ) {
388
 
389
+ $response = array('status' => 'ERROR');
390
  $subject = html_entity_decode( $subject, ENT_QUOTES, get_bloginfo( 'charset' ) );
391
  $get_email_type = get_option( 'ig_es_email_type', true );
392
  $site_title = get_bloginfo();
410
  $headers[] = "X-Mailer: PHP" . phpversion();
411
  }
412
 
413
+ $plain_text_template = self::convert_to_text( $email_template );
414
+ $headers[] = "Content-Type: text/html; charset=\"" . get_bloginfo( 'charset' ) . "\"";
415
+ $headers = implode( "\n", $headers );
416
+ $ig_es_mailer_settings = get_option( 'ig_es_mailer_settings' );
417
+ if ( ! empty( $ig_es_mailer_settings['mailer'] ) && 'phpmail' !== $ig_es_mailer_settings['mailer'] ) {
418
+ $data = array(
419
  'to_email' => $to_email,
420
  'subject' => $subject,
421
  'email_template' => $email_template,
426
  'email_type' => $get_email_type
427
  );
428
 
 
429
  $response = apply_filters( 'ig_es_lite_do_send', $response, $data );
430
+
431
  } else {
432
+ $result = mail( $to_email, $subject, $email_template, $headers );
433
+ if($result) {
434
+ $response['status'] = 'SUCCESS';
435
+ }
436
  }
437
 
438
+ return $response;
439
 
440
  }
441
 
includes/db/class-es-db-actions.php ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ class ES_DB_Actions extends ES_DB {
8
+ /**
9
+ * @since 4.2.1
10
+ * @var $table_name
11
+ *
12
+ */
13
+ public $table_name;
14
+ /**
15
+ * @since 4.2.1
16
+ * @var $version
17
+ *
18
+ */
19
+ public $version;
20
+ /**
21
+ * @since 4.2.1
22
+ * @var $primary_key
23
+ *
24
+ */
25
+ public $primary_key;
26
+
27
+ /**
28
+ * ES_DB_Lists constructor.
29
+ *
30
+ * @since 4.2.1
31
+ */
32
+ public function __construct() {
33
+ global $wpdb;
34
+
35
+ $this->table_name = $wpdb->prefix . 'ig_actions';
36
+
37
+ $this->primary_key = 'id';
38
+
39
+ $this->version = '1.0';
40
+
41
+ }
42
+
43
+ /**
44
+ * Get table columns
45
+ *
46
+ * @return array
47
+ *
48
+ * @since 4.2.1
49
+ */
50
+ public function get_columns() {
51
+ return array(
52
+ 'id' => '%d',
53
+ 'slug' => '%s',
54
+ 'name' => '%s',
55
+ 'created_at' => '%s',
56
+ 'updated_at' => '%s',
57
+ 'deleted_at' => '%s'
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Get default column values
63
+ *
64
+ * @since 4.2.1
65
+ */
66
+ public function get_column_defaults() {
67
+ return array(
68
+ 'slug' => null,
69
+ 'name' => null,
70
+ 'created_at' => ig_get_current_date_time(),
71
+ 'updated_at' => null,
72
+ 'deleted_at' => null
73
+ );
74
+ }
75
+
76
+
77
+
78
+
79
+ }
includes/db/class-es-db-campaigns.php CHANGED
@@ -5,28 +5,52 @@ if ( ! defined( 'ABSPATH' ) ) {
5
  exit;
6
  }
7
 
8
- class ES_DB_Campaigns {
9
 
10
  const STATUS_ACTIVE = 1;
11
 
12
  const STATUS_INACTIVE = 0;
13
-
 
 
 
 
14
  public $table_name;
15
 
 
 
 
 
 
16
  public $version;
17
 
 
 
 
 
 
18
  public $primary_key;
19
 
20
  public function __construct() {
 
 
 
 
 
 
 
 
 
 
21
 
22
  }
23
 
24
  /**
25
  * Get columns and formats
26
  *
27
- * @since 2.1
28
  */
29
- public static function get_columns() {
30
  return array(
31
  'id' => '%d',
32
  'slug' => '%s',
@@ -54,9 +78,9 @@ class ES_DB_Campaigns {
54
  /**
55
  * Get default column values
56
  *
57
- * @since 2.1
58
  */
59
- public static function get_column_defaults() {
60
 
61
  $from_name = ES_Common::get_ig_option( 'from_name' );
62
  $from_email = ES_Common::get_ig_option( 'from_email' );
@@ -84,41 +108,46 @@ class ES_DB_Campaigns {
84
  );
85
  }
86
 
87
- public static function do_insert( $place_holders, $values ) {
88
- global $wpdb;
89
-
90
- $campiagns_table = IG_CAMPAIGNS_TABLE;
91
- $query = "INSERT INTO {$campiagns_table} (`slug`, `name`, `type`, `from_name`, `from_email`, `reply_to_name`, `reply_to_email`, `categories`, `list_ids`, `base_template_id`, `status`, `created_at`, `updated_at`, `deleted_at`, `meta`) VALUES ";
92
- $query .= implode( ', ', $place_holders );
93
- $sql = $wpdb->prepare( "$query ", $values );
94
-
95
- if ( $wpdb->query( $sql ) ) {
96
- return true;
97
- } else {
98
- return false;
99
- }
100
  }
101
 
102
- public static function get_templateid_by_campaign( $id ) {
103
- global $wpdb;
104
-
105
- $campiagns_table = IG_CAMPAIGNS_TABLE;
106
-
107
- $query = "SELECT base_template_id FROM {$campiagns_table} WHERE id = %d";
 
 
 
108
 
109
- $sql = $wpdb->prepare( $query, array( $id ) );
110
- $template_id = $wpdb->get_var( $sql );
111
 
112
- return $template_id;
113
- }
 
 
 
114
 
 
 
115
 
116
- public static function save_campaign( $data, $id = null ) {
117
- global $wpdb;
118
 
 
 
119
  $column_formats = self::get_columns();
120
  $column_defaults = self::get_column_defaults();
121
- $insert = is_null( $id ) ? true : false;
122
  $prepared_data = ES_DB::prepare_data( $data, $column_formats, $column_defaults, $insert );
123
 
124
  $campaigns_data = $prepared_data['data'];
@@ -133,22 +162,32 @@ class ES_DB_Campaigns {
133
 
134
  $result = $wpdb->update( IG_CAMPAIGNS_TABLE, $campaigns_data, array( 'id' => $id ), $column_formats );
135
  }
136
-
137
  return $result;
138
- }
139
-
140
- public static function get_campaign_type_by_id( $id ) {
141
- global $wpdb;
142
-
143
- $query = "SELECT type FROM " . IG_CAMPAIGNS_TABLE . " WHERE id = %d";
144
 
145
- $sql = $wpdb->prepare( $query, array( $id ) );
146
- $type = $wpdb->get_var( $sql );
147
 
148
- return $type;
 
 
 
 
 
 
 
 
 
 
 
 
149
  }
150
 
151
- public static function migrate_post_notifications() {
 
 
 
 
 
152
  /**
153
  * - Migrate post notifications from es_notification table
154
  *
@@ -160,7 +199,7 @@ class ES_DB_Campaigns {
160
 
161
  $from_name = ES_Common::get_ig_option( 'from_name' );
162
  $from_email = ES_Common::get_ig_option( 'from_email' );
163
- $list_is_name_map = ES_DB_Lists::get_list_id_name_map( '', true );
164
 
165
  $query = "SELECT count(*) as total FROM " . EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE;
166
  $total = $wpdb->get_var( $query );
@@ -221,7 +260,7 @@ class ES_DB_Campaigns {
221
 
222
  //Do Batach Insert
223
  $values = $place_holders = array();
224
- $columns = self::get_columns();
225
  unset( $columns['id'] );
226
  $fields = array_keys( $columns );
227
 
@@ -229,7 +268,7 @@ class ES_DB_Campaigns {
229
  $campaign_data['slug'] = ! empty( $templates_data[ $campaign_data['slug'] ] ) ? $templates_data[ $campaign_data['slug'] ]['post_name'] : '';
230
  $campaign_data['name'] = ! empty( $templates_data[ $campaign_data['name'] ] ) ? $templates_data[ $campaign_data['name'] ]['post_title'] : '';
231
 
232
- $campaign_data = wp_parse_args( $campaign_data, self::get_column_defaults() );
233
 
234
  $formats = array();
235
  foreach ( $columns as $column => $format ) {
@@ -246,7 +285,12 @@ class ES_DB_Campaigns {
246
  }
247
  }
248
 
249
- public static function migrate_newsletters() {
 
 
 
 
 
250
  global $wpdb;
251
 
252
  $from_name = ES_Common::get_ig_option( 'from_name' );
@@ -257,15 +301,15 @@ class ES_DB_Campaigns {
257
 
258
  if ( $total > 0 ) {
259
 
260
- $list_is_name_map = ES_DB_Lists::get_list_id_name_map( '', true );
261
  $batch_size = IG_DEFAULT_BATCH_SIZE;
262
- $total_bataches = ceil( $total / $batch_size );
263
 
264
  $values = $place_holders = array();
265
- $columns = self::get_columns();
266
  unset( $columns['id'] );
267
  $fields = array_keys( $columns );
268
- for ( $i = 0; $i <= $total_bataches; $i ++ ) {
269
  $batch_start = $i * $batch_size;
270
 
271
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_SENT_TABLE . " WHERE es_sent_source = 'Newsletter' LIMIT {$batch_start}, {$batch_size}";
@@ -285,7 +329,7 @@ class ES_DB_Campaigns {
285
  $campaign_data['status'] = 1;
286
  $campaign_data['created_at'] = $newsletter['es_sent_starttime'];
287
 
288
- $campaign_data = wp_parse_args( $campaign_data, self::get_column_defaults() );
289
 
290
  $formats = array();
291
  foreach ( $columns as $column => $format ) {
@@ -307,7 +351,7 @@ class ES_DB_Campaigns {
307
  * table. So, we are fetching it now and set campaign_id based on subject match.
308
  * If not match, set as 0.
309
  */
310
- public static function update_campaign_id_in_mailing_queue() {
311
  global $wpdb;
312
 
313
  $sql = "SELECT id, name FROM {$wpdb->prefix}ig_campaigns";
@@ -342,28 +386,66 @@ class ES_DB_Campaigns {
342
  }
343
  }
344
 
 
 
 
 
 
 
 
 
345
 
346
- public static function count_campaigns() {
347
-
348
- global $wpdb;
349
 
350
- $query = "SELECT count(*) as total_campaigns FROM " . IG_CAMPAIGNS_TABLE . " WHERE deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00'";
351
- $campaigns = $wpdb->get_var( $query );
352
 
353
  return $campaigns;
354
 
355
  }
356
 
357
- public static function get_total_campaigns_by_type( $type = 'newsletter' ) {
 
 
 
 
 
 
 
 
 
358
  global $wpdb;
359
 
360
- $query = "SELECT count(*) as total_campaigns FROM " . IG_CAMPAIGNS_TABLE . " WHERE type = %s AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')";
361
- $query = $wpdb->prepare( $query, $type );
362
- $campaigns = $wpdb->get_var( $query );
363
 
364
  return $campaigns;
365
  }
366
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  /**
368
  * Get campaign meta data
369
  *
@@ -373,14 +455,12 @@ class ES_DB_Campaigns {
373
  *
374
  * @since 4.2.0
375
  */
376
- public static function get_campaign_meta_by_id( $id ) {
377
- global $wpdb;
378
-
379
- $query = "SELECT meta FROM " . IG_CAMPAIGNS_TABLE . " WHERE id = %d";
380
 
381
- $sql = $wpdb->prepare( $query, array( $id ) );
382
- $meta = $wpdb->get_var( $sql );
383
- $meta = maybe_unserialize( $meta );
384
 
385
  return $meta;
386
  }
@@ -394,13 +474,8 @@ class ES_DB_Campaigns {
394
  *
395
  * @since 4.2.0
396
  */
397
- public static function get_campaign_categories_str_by_id( $id ) {
398
- global $wpdb;
399
-
400
- $query = "SELECT categories FROM " . IG_CAMPAIGNS_TABLE . " WHERE id = %d";
401
-
402
- $sql = $wpdb->prepare( $query, array( $id ) );
403
- $categories_str = $wpdb->get_var( $sql );
404
 
405
  return $categories_str;
406
  }
@@ -413,22 +488,45 @@ class ES_DB_Campaigns {
413
  *
414
  * @return array|object|null
415
  */
416
- public static function get_campaign_by_id( $id = 0 ) {
417
  global $wpdb;
418
 
419
- $campaigns_table = IG_CAMPAIGNS_TABLE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
 
421
  if ( empty( $id ) ) {
422
  return array();
423
  }
424
 
425
- $query = "SELECT * FROM {$campaigns_table} WHERE id = %d AND status = %d";
426
- $campaigns = $wpdb->get_results( $wpdb->prepare( $query, $id, 1 ), ARRAY_A );
 
427
 
428
  return $campaigns;
429
 
430
  }
431
 
 
432
  /**
433
  * Get Active Campaigns
434
  *
@@ -436,19 +534,17 @@ class ES_DB_Campaigns {
436
  *
437
  * @since 4.2.0
438
  */
439
- public static function get_active_campaigns( $type = '' ) {
440
  global $wpdb;
441
 
442
- $campaigns_table = IG_CAMPAIGNS_TABLE;
443
-
444
  if ( empty( $type ) ) {
445
- $query = "SELECT * FROM {$campaigns_table} WHERE status = %d AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')";
446
- $campaigns = $wpdb->get_results( $wpdb->prepare( $query, self::STATUS_ACTIVE ), ARRAY_A );
447
  } else {
448
- $query = "SELECT * FROM {$campaigns_table} WHERE status = %d AND type = %s AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')";
449
- $campaigns = $wpdb->get_results( $wpdb->prepare( $query, self::STATUS_ACTIVE, $type ), ARRAY_A );
450
  }
451
 
 
 
452
  return $campaigns;
453
  }
454
 
@@ -462,12 +558,11 @@ class ES_DB_Campaigns {
462
  *
463
  * @sine 4.2.0
464
  */
465
- public static function update_campaign_meta( $campaign_id = 0, $meta_data = array() ) {
466
- global $wpdb;
467
 
468
  $update = false;
469
  if ( ! empty( $campaign_id ) && ! empty( $meta_data ) ) {
470
- $campaigns = self::get_campaign_by_id( $campaign_id );
471
 
472
  if ( ! empty( $campaigns ) && count( $campaigns ) == 1 ) {
473
 
@@ -482,7 +577,7 @@ class ES_DB_Campaigns {
482
 
483
  $campaign['meta'] = maybe_serialize( $meta );
484
 
485
- $update = self::save_campaign( $campaign, $campaign_id );
486
 
487
  }
488
  }
5
  exit;
6
  }
7
 
8
+ class ES_DB_Campaigns extends ES_DB {
9
 
10
  const STATUS_ACTIVE = 1;
11
 
12
  const STATUS_INACTIVE = 0;
13
+ /**
14
+ * @since 4.2.1
15
+ * @var string $table_name
16
+ *
17
+ */
18
  public $table_name;
19
 
20
+ /**
21
+ * @since 4.2.1
22
+ * @var string $version
23
+ *
24
+ */
25
  public $version;
26
 
27
+ /**
28
+ * @since 4.2.1
29
+ * @var string
30
+ *
31
+ */
32
  public $primary_key;
33
 
34
  public function __construct() {
35
+ global $wpdb;
36
+
37
+ parent::__construct();
38
+
39
+ $this->table_name = $wpdb->prefix . 'ig_campaigns';
40
+
41
+ $this->primary_key = 'id';
42
+
43
+ $this->version = '1.0';
44
+
45
 
46
  }
47
 
48
  /**
49
  * Get columns and formats
50
  *
51
+ * @since 4.0.0
52
  */
53
+ public function get_columns() {
54
  return array(
55
  'id' => '%d',
56
  'slug' => '%s',
78
  /**
79
  * Get default column values
80
  *
81
+ * @since 4.0.0
82
  */
83
+ public function get_column_defaults() {
84
 
85
  $from_name = ES_Common::get_ig_option( 'from_name' );
86
  $from_email = ES_Common::get_ig_option( 'from_email' );
108
  );
109
  }
110
 
111
+ /**
112
+ * Get template id by campaign id
113
+ *
114
+ * @param $id
115
+ *
116
+ * @return array|string|null
117
+ *
118
+ * @since 4.2.1
119
+ */
120
+ public function get_template_id_by_campaign( $id ) {
121
+ return $this->get_column( 'base_template_id', $id );
 
 
122
  }
123
 
124
+ /**
125
+ * @param $data
126
+ * @param null $id
127
+ *
128
+ * @return false|int
129
+ *
130
+ * @since 4.0.0
131
+ */
132
+ public function save_campaign( $data, $id = null ) {
133
 
134
+ $insert = is_null( $id ) ? true : false;
 
135
 
136
+ if ( $insert ) {
137
+ $result = $this->insert( $data );
138
+ } else {
139
+ // Set updated_at if not set
140
+ $data['updated_at'] = ! empty( $data['updated_at'] ) ? $data['updated_at'] : ig_get_current_date_time();
141
 
142
+ $result = $this->update( $id, $data );
143
+ }
144
 
145
+ return $result;
 
146
 
147
+ /*
148
+ $insert = is_null( $id ) ? true : false;
149
  $column_formats = self::get_columns();
150
  $column_defaults = self::get_column_defaults();
 
151
  $prepared_data = ES_DB::prepare_data( $data, $column_formats, $column_defaults, $insert );
152
 
153
  $campaigns_data = $prepared_data['data'];
162
 
163
  $result = $wpdb->update( IG_CAMPAIGNS_TABLE, $campaigns_data, array( 'id' => $id ), $column_formats );
164
  }
 
165
  return $result;
166
+ */
 
 
 
 
 
167
 
168
+ }
 
169
 
170
+ /**
171
+ * Get campaign type by campaign id
172
+ *
173
+ * @param $id
174
+ *
175
+ * @return string|null
176
+ *
177
+ * @since 4.0.0
178
+ *
179
+ * @modify 4.2.1
180
+ */
181
+ public function get_campaign_type_by_id( $id ) {
182
+ return $this->get_by( 'type', $id );
183
  }
184
 
185
+ /**
186
+ * Migrate post notification from ES 3.5.x
187
+ *
188
+ * @since 4.0.0
189
+ */
190
+ public function migrate_post_notifications() {
191
  /**
192
  * - Migrate post notifications from es_notification table
193
  *
199
 
200
  $from_name = ES_Common::get_ig_option( 'from_name' );
201
  $from_email = ES_Common::get_ig_option( 'from_email' );
202
+ $list_is_name_map = ES()->lists_db->get_list_id_name_map( '', true );
203
 
204
  $query = "SELECT count(*) as total FROM " . EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE;
205
  $total = $wpdb->get_var( $query );
260
 
261
  //Do Batach Insert
262
  $values = $place_holders = array();
263
+ $columns = $this->get_columns();
264
  unset( $columns['id'] );
265
  $fields = array_keys( $columns );
266
 
268
  $campaign_data['slug'] = ! empty( $templates_data[ $campaign_data['slug'] ] ) ? $templates_data[ $campaign_data['slug'] ]['post_name'] : '';
269
  $campaign_data['name'] = ! empty( $templates_data[ $campaign_data['name'] ] ) ? $templates_data[ $campaign_data['name'] ]['post_title'] : '';
270
 
271
+ $campaign_data = wp_parse_args( $campaign_data, $this->get_column_defaults() );
272
 
273
  $formats = array();
274
  foreach ( $columns as $column => $format ) {
285
  }
286
  }
287
 
288
+ /**
289
+ * Migrate Newsletters from ES 3.5.x
290
+ *
291
+ * @since 4.0.0
292
+ */
293
+ public function migrate_newsletters() {
294
  global $wpdb;
295
 
296
  $from_name = ES_Common::get_ig_option( 'from_name' );
301
 
302
  if ( $total > 0 ) {
303
 
304
+ $list_is_name_map = ES()->lists_db->get_list_id_name_map( '', true );
305
  $batch_size = IG_DEFAULT_BATCH_SIZE;
306
+ $total_batches = ceil( $total / $batch_size );
307
 
308
  $values = $place_holders = array();
309
+ $columns = $this->get_columns();
310
  unset( $columns['id'] );
311
  $fields = array_keys( $columns );
312
+ for ( $i = 0; $i <= $total_batches; $i ++ ) {
313
  $batch_start = $i * $batch_size;
314
 
315
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_SENT_TABLE . " WHERE es_sent_source = 'Newsletter' LIMIT {$batch_start}, {$batch_size}";
329
  $campaign_data['status'] = 1;
330
  $campaign_data['created_at'] = $newsletter['es_sent_starttime'];
331
 
332
+ $campaign_data = wp_parse_args( $campaign_data, $this->get_column_defaults() );
333
 
334
  $formats = array();
335
  foreach ( $columns as $column => $format ) {
351
  * table. So, we are fetching it now and set campaign_id based on subject match.
352
  * If not match, set as 0.
353
  */
354
+ public function update_campaign_id_in_mailing_queue() {
355
  global $wpdb;
356
 
357
  $sql = "SELECT id, name FROM {$wpdb->prefix}ig_campaigns";
386
  }
387
  }
388
 
389
+ /**
390
+ * Get total campaigns
391
+ *
392
+ * @return string|null
393
+ *
394
+ * @since 4.2.1
395
+ */
396
+ public function get_total_campaigns( $where = '' ) {
397
 
398
+ if ( empty( $where ) ) {
399
+ $where = "deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00'";
400
+ }
401
 
402
+ $campaigns = $this->count( $where );
 
403
 
404
  return $campaigns;
405
 
406
  }
407
 
408
+ /**
409
+ * Get total campaigns by type
410
+ *
411
+ * @param string $type
412
+ *
413
+ * @return string|null
414
+ *
415
+ * @since 4.2.1
416
+ */
417
+ public function get_total_campaigns_by_type( $type = 'newsletter' ) {
418
  global $wpdb;
419
 
420
+ $where = $wpdb->prepare( "type = %s AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')", array( $type ) );
421
+
422
+ $campaigns = $this->get_total_campaigns( $where );
423
 
424
  return $campaigns;
425
  }
426
 
427
+ /**
428
+ * Get total post notifications
429
+ *
430
+ * @return string|null
431
+ *
432
+ * @since 4.2.1
433
+ */
434
+ public function get_total_post_notifications() {
435
+ return $this->get_total_campaigns_by_type( 'post_notification' );
436
+ }
437
+
438
+ /**
439
+ * Get total newsletters
440
+ *
441
+ * @return string|null
442
+ *
443
+ * @since 4.2.1
444
+ */
445
+ public function get_total_newsletters() {
446
+ return $this->get_total_campaigns_by_type( 'newsletter' );
447
+ }
448
+
449
  /**
450
  * Get campaign meta data
451
  *
455
  *
456
  * @since 4.2.0
457
  */
458
+ public function get_campaign_meta_by_id( $id ) {
459
+ $meta = $this->get_column( 'meta', $id );
 
 
460
 
461
+ if ( $meta ) {
462
+ $meta = maybe_unserialize( $meta );
463
+ }
464
 
465
  return $meta;
466
  }
474
  *
475
  * @since 4.2.0
476
  */
477
+ public function get_campaign_categories_str_by_id( $id ) {
478
+ $categories_str = $this->get_column( 'categories', $id );
 
 
 
 
 
479
 
480
  return $categories_str;
481
  }
488
  *
489
  * @return array|object|null
490
  */
491
+ public function get_campaign_by_id( $id = 0 ) {
492
  global $wpdb;
493
 
494
+ if ( empty( $id ) ) {
495
+ return array();
496
+ }
497
+
498
+ $where = $wpdb->prepare( "id = %d AND status = %d", $id, self::STATUS_ACTIVE );
499
+
500
+ $campaigns = $this->get_by_conditions( $where );
501
+
502
+ return $campaigns;
503
+ }
504
+
505
+ /**
506
+ * Get campaigns by parent id
507
+ *
508
+ * @param int $id
509
+ *
510
+ * @return array|object|null
511
+ *
512
+ * @since 4.2.1
513
+ */
514
+ public function get_campaign_by_parent_id( $id = 0 ) {
515
+ global $wpdb;
516
 
517
  if ( empty( $id ) ) {
518
  return array();
519
  }
520
 
521
+ $where = $wpdb->prepare( "parent_id = %d AND status = %d AND ( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' )", $id, self::STATUS_ACTIVE );
522
+
523
+ $campaigns = $this->get_by_conditions( $where );
524
 
525
  return $campaigns;
526
 
527
  }
528
 
529
+
530
  /**
531
  * Get Active Campaigns
532
  *
534
  *
535
  * @since 4.2.0
536
  */
537
+ public function get_active_campaigns( $type = '' ) {
538
  global $wpdb;
539
 
 
 
540
  if ( empty( $type ) ) {
541
+ $where = $wpdb->prepare( "status = %d AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')", self::STATUS_ACTIVE );
 
542
  } else {
543
+ $where = $wpdb->prepare( "status = %d AND type = %s AND (deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00')", self::STATUS_ACTIVE, $type );
 
544
  }
545
 
546
+ $campaigns = $this->get_by_conditions( $where );
547
+
548
  return $campaigns;
549
  }
550
 
558
  *
559
  * @sine 4.2.0
560
  */
561
+ public function update_campaign_meta( $campaign_id = 0, $meta_data = array() ) {
 
562
 
563
  $update = false;
564
  if ( ! empty( $campaign_id ) && ! empty( $meta_data ) ) {
565
+ $campaigns = $this->get_campaign_by_id( $campaign_id );
566
 
567
  if ( ! empty( $campaigns ) && count( $campaigns ) == 1 ) {
568
 
577
 
578
  $campaign['meta'] = maybe_serialize( $meta );
579
 
580
+ $update = $this->save_campaign( $campaign, $campaign_id );
581
 
582
  }
583
  }
includes/db/class-es-db-contacts.php CHANGED
@@ -73,7 +73,7 @@ class ES_DB_Contacts {
73
  return $subscriber;
74
  }
75
 
76
- public static function get_subsribers_email_name_map( $emails = array() ) {
77
 
78
  global $wpdb;
79
 
@@ -107,11 +107,19 @@ class ES_DB_Contacts {
107
  public static function get_contact_hash_by_id( $id ) {
108
  global $wpdb;
109
 
110
- $query = "SELECT hash FROM " . IG_CONTACTS_TABLE . " WHERE id = %d";
111
- $sql = $wpdb->prepare( $query, $id );
112
- $contact_hash = $wpdb->get_col( $sql );
113
 
114
- return $contact_hash[0];
 
 
 
 
 
 
 
 
 
 
115
  }
116
 
117
  public static function is_contact_exists( $id = '', $email = '' ) {
@@ -151,6 +159,30 @@ class ES_DB_Contacts {
151
 
152
  }
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  public static function count_active_subscribers_by_list_id( $list_id = '' ) {
155
 
156
  global $wpdb;
@@ -265,7 +297,7 @@ class ES_DB_Contacts {
265
  global $wpdb;
266
 
267
  $contacts_table = IG_CONTACTS_TABLE;
268
- $ids = implode( ',', array_map( 'absint', $ids ) );
269
 
270
  $sql = "UPDATE {$contacts_table} SET unsubscribed = %d WHERE id IN ($ids)";
271
  $query = $wpdb->prepare( $sql, array( $unsubscribed ) );
@@ -332,6 +364,30 @@ class ES_DB_Contacts {
332
 
333
  }
334
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
335
  public static function get_contact_ids_by_emails( $emails = array() ) {
336
  global $wpdb;
337
 
@@ -503,7 +559,7 @@ class ES_DB_Contacts {
503
 
504
  //Do import Lists Contacts
505
  if ( count( $lists_contacts ) > 0 ) {
506
- $list_name_id_map = ES_DB_Lists::get_list_id_name_map( '', true );
507
  foreach ( $lists_contacts as $list_name => $contacts ) {
508
  if ( ! empty( $list_name_id_map[ $list_name ] ) ) {
509
  ES_DB_Lists_Contacts::import_contacts_into_lists( $list_name_id_map[ $list_name ], $contacts );
@@ -527,7 +583,7 @@ class ES_DB_Contacts {
527
  public static function edit_list_contact_status( $contact_ids, $list_ids, $status ) {
528
  global $wpdb;
529
 
530
- $ids = implode( ',', array_map( 'absint', $contact_ids ) );
531
  $list_ids = implode( ',', array_map( 'absint', $list_ids ) );
532
 
533
  $current_date = ig_get_current_date_time();
@@ -542,6 +598,7 @@ class ES_DB_Contacts {
542
  $sql = "UPDATE " . IG_LISTS_CONTACTS_TABLE . " SET status = %s, optin_type = %d, subscribed_at = NULL, unsubscribed_at = NULL WHERE contact_id IN ($ids) AND list_id IN ($list_ids)";
543
  $query = $wpdb->prepare( $sql, array( $status, IG_DOUBLE_OPTIN ) );
544
  }
 
545
  return $wpdb->query( $query );
546
 
547
  }
73
  return $subscriber;
74
  }
75
 
76
+ public static function get_subscribers_email_name_map( $emails = array() ) {
77
 
78
  global $wpdb;
79
 
107
  public static function get_contact_hash_by_id( $id ) {
108
  global $wpdb;
109
 
110
+ if ( ! empty( $id ) ) {
 
 
111
 
112
+ $ig_contacts_table = IG_CONTACTS_TABLE;
113
+ $query = "SELECT hash FROM {$ig_contacts_table} WHERE id = %d";
114
+ $sql = $wpdb->prepare( $query, $id );
115
+ $contact_hash = $wpdb->get_col( $sql );
116
+
117
+ if ( ! empty( $contact_hash ) ) {
118
+ return $contact_hash[0];
119
+ }
120
+ }
121
+
122
+ return '';
123
  }
124
 
125
  public static function is_contact_exists( $id = '', $email = '' ) {
159
 
160
  }
161
 
162
+ /**
163
+ * Get contacts by ids
164
+ *
165
+ * @param $ids
166
+ *
167
+ * @return array|object|null
168
+ *
169
+ * @since 4.2.1
170
+ */
171
+ public static function get_contacts_by_ids( $ids ) {
172
+
173
+ global $wpdb;
174
+
175
+ $contacts_table = IG_CONTACTS_TABLE;
176
+
177
+ $ids_str = "'" . implode( ", '", $ids ) . "'";
178
+
179
+ $query = "SELECT * FROM $contacts_table WHERE id IN ($ids_str)";
180
+ $subscribers = $wpdb->get_results( $query, ARRAY_A );
181
+
182
+ return $subscribers;
183
+
184
+ }
185
+
186
  public static function count_active_subscribers_by_list_id( $list_id = '' ) {
187
 
188
  global $wpdb;
297
  global $wpdb;
298
 
299
  $contacts_table = IG_CONTACTS_TABLE;
300
+ $ids = implode( ',', array_map( 'absint', $ids ) );
301
 
302
  $sql = "UPDATE {$contacts_table} SET unsubscribed = %d WHERE id IN ($ids)";
303
  $query = $wpdb->prepare( $sql, array( $unsubscribed ) );
364
 
365
  }
366
 
367
+ /**
368
+ * Get contacts id details map
369
+ *
370
+ * @param array $contact_ids
371
+ *
372
+ * @return array
373
+ *
374
+ * @since 4.2.1
375
+ */
376
+ public static function get_details_by_ids( $contact_ids = array() ) {
377
+
378
+ $contacts = self::get_contacts_by_ids( $contact_ids );
379
+
380
+ $results = array();
381
+ if ( ! empty( $contacts ) && count( $contacts ) > 0 ) {
382
+
383
+ foreach ( $contacts as $contact ) {
384
+ $results[ $contact['id'] ] = $contact;
385
+ }
386
+ }
387
+
388
+ return $results;
389
+ }
390
+
391
  public static function get_contact_ids_by_emails( $emails = array() ) {
392
  global $wpdb;
393
 
559
 
560
  //Do import Lists Contacts
561
  if ( count( $lists_contacts ) > 0 ) {
562
+ $list_name_id_map = ES()->lists_db->get_list_id_name_map( '', true );
563
  foreach ( $lists_contacts as $list_name => $contacts ) {
564
  if ( ! empty( $list_name_id_map[ $list_name ] ) ) {
565
  ES_DB_Lists_Contacts::import_contacts_into_lists( $list_name_id_map[ $list_name ], $contacts );
583
  public static function edit_list_contact_status( $contact_ids, $list_ids, $status ) {
584
  global $wpdb;
585
 
586
+ $ids = implode( ',', array_map( 'absint', $contact_ids ) );
587
  $list_ids = implode( ',', array_map( 'absint', $list_ids ) );
588
 
589
  $current_date = ig_get_current_date_time();
598
  $sql = "UPDATE " . IG_LISTS_CONTACTS_TABLE . " SET status = %s, optin_type = %d, subscribed_at = NULL, unsubscribed_at = NULL WHERE contact_id IN ($ids) AND list_id IN ($list_ids)";
599
  $query = $wpdb->prepare( $sql, array( $status, IG_DOUBLE_OPTIN ) );
600
  }
601
+
602
  return $wpdb->query( $query );
603
 
604
  }
includes/db/class-es-db-forms.php CHANGED
@@ -96,7 +96,7 @@ class ES_DB_Forms {
96
  $table = sanitize_text_field( EMAIL_SUBSCRIBERS_ADVANCED_FORM );
97
  $is_table_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
98
 
99
- $lists_name_id_map = ES_DB_Lists::get_list_id_name_map( '', true );
100
  if ( $is_table_exists ) {
101
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_ADVANCED_FORM;
102
  $forms = $wpdb->get_results( $query, ARRAY_A );
@@ -122,7 +122,7 @@ class ES_DB_Forms {
122
  foreach ( $es_af_group_lists as $list ) {
123
 
124
  if ( ! isset( $lists_name_id_map[ $list ] ) ) {
125
- $list_id = ES_DB_Lists::add_list( $list );
126
  $lists_name_id_map[ $list ] = $list_id;
127
  }
128
 
96
  $table = sanitize_text_field( EMAIL_SUBSCRIBERS_ADVANCED_FORM );
97
  $is_table_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
98
 
99
+ $lists_name_id_map = ES()->lists_db->get_list_id_name_map( '', true );
100
  if ( $is_table_exists ) {
101
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_ADVANCED_FORM;
102
  $forms = $wpdb->get_results( $query, ARRAY_A );
122
  foreach ( $es_af_group_lists as $list ) {
123
 
124
  if ( ! isset( $lists_name_id_map[ $list ] ) ) {
125
+ $list_id = ES()->lists_db->add_list( $list );
126
  $lists_name_id_map[ $list ] = $list_id;
127
  }
128
 
includes/db/class-es-db-links.php CHANGED
@@ -10,39 +10,40 @@ if ( class_exists( 'ES_DB_Links' ) ) {
10
  *
11
  * Class ES_DB_Links
12
  *
13
- * @since 4.2.0
14
  */
15
  class ES_DB_Links extends ES_DB {
16
  /**
17
  * Table Name
18
  *
 
19
  * @var string
20
  *
21
- * @since 4.2.0
22
  */
23
  public $table_name;
24
  /**
25
  * Table Version
26
  *
 
27
  * @var string
28
  *
29
- * @since 4.2.0
30
  */
31
  public $version;
32
  /**
33
  * Primary key
34
  *
 
35
  * @var string
36
  *
37
- * @since 4.2.0
38
  */
39
  public $primary_key;
 
40
  /**
41
  * Initialize
42
  *
43
  * ES_DB_Links constructor.
44
  *
45
- * @since 4.2.0
46
  */
47
  public function __construct() {
48
  global $wpdb;
@@ -57,7 +58,7 @@ if ( class_exists( 'ES_DB_Links' ) ) {
57
  /**
58
  * Get columns and formats
59
  *
60
- * @since 4.2.0
61
  */
62
  public function get_columns() {
63
  return array(
@@ -73,7 +74,7 @@ if ( class_exists( 'ES_DB_Links' ) ) {
73
  /**
74
  * Get default column values
75
  *
76
- * @since 2.1
77
  */
78
  public function get_column_defaults() {
79
 
@@ -93,15 +94,15 @@ if ( class_exists( 'ES_DB_Links' ) ) {
93
  *
94
  * @return string
95
  *
96
- * @since 4.2.0
97
  */
98
  public function get_by_hash( $hash = null ) {
99
 
100
- if(!empty($hash)) {
101
  return '';
102
  }
103
 
104
- return $this->get_by('hash', $hash);
105
  }
106
 
107
  /**
@@ -110,14 +111,16 @@ if ( class_exists( 'ES_DB_Links' ) ) {
110
  * @param int $id
111
  *
112
  * @return array|object|void|null
 
 
113
  */
114
  public function get_by_id( $id = 0 ) {
115
 
116
- if(empty($id)) {
117
  return;
118
  }
119
 
120
- return $this->get_by('id', $id);
121
  }
122
 
123
  }
10
  *
11
  * Class ES_DB_Links
12
  *
13
+ * @since 4.2.1
14
  */
15
  class ES_DB_Links extends ES_DB {
16
  /**
17
  * Table Name
18
  *
19
+ * @since 4.2.1
20
  * @var string
21
  *
 
22
  */
23
  public $table_name;
24
  /**
25
  * Table Version
26
  *
27
+ * @since 4.2.1
28
  * @var string
29
  *
 
30
  */
31
  public $version;
32
  /**
33
  * Primary key
34
  *
35
+ * @since 4.2.1
36
  * @var string
37
  *
 
38
  */
39
  public $primary_key;
40
+
41
  /**
42
  * Initialize
43
  *
44
  * ES_DB_Links constructor.
45
  *
46
+ * @since 4.2.1
47
  */
48
  public function __construct() {
49
  global $wpdb;
58
  /**
59
  * Get columns and formats
60
  *
61
+ * @since 4.2.1
62
  */
63
  public function get_columns() {
64
  return array(
74
  /**
75
  * Get default column values
76
  *
77
+ * @since 4.2.1
78
  */
79
  public function get_column_defaults() {
80
 
94
  *
95
  * @return string
96
  *
97
+ * @since 4.2.1
98
  */
99
  public function get_by_hash( $hash = null ) {
100
 
101
+ if ( ! empty( $hash ) ) {
102
  return '';
103
  }
104
 
105
+ return $this->get_by( 'hash', $hash );
106
  }
107
 
108
  /**
111
  * @param int $id
112
  *
113
  * @return array|object|void|null
114
+ *
115
+ * @since 4.2.1
116
  */
117
  public function get_by_id( $id = 0 ) {
118
 
119
+ if ( empty( $id ) ) {
120
  return;
121
  }
122
 
123
+ return $this->get_by( 'id', $id );
124
  }
125
 
126
  }
includes/db/class-es-db-lists.php CHANGED
@@ -4,58 +4,150 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
7
- class ES_DB_Lists {
8
-
 
 
 
 
9
  public $table_name;
10
-
 
 
 
 
11
  public $version;
12
-
 
 
 
 
13
  public $primary_key;
14
 
 
 
 
 
 
15
  public function __construct() {
 
 
 
 
 
 
 
16
 
17
  }
18
 
19
- public static function get_lists( $status = 'all' ) {
20
- global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
 
 
 
 
 
 
 
 
 
22
 
23
- $query = "SELECT * FROM " . IG_LISTS_TABLE . " WHERE deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' ";
24
- // if ( $status === 'enable' || $status === 'disable' ) {
25
- // $query .= $wpdb->prepare(" WHERE status = %s", $status);
26
- // }
27
 
28
  $lists = $wpdb->get_results( $query, ARRAY_A );
29
 
30
  return $lists;
31
  }
32
 
33
-
34
- public static function get_list_id_name_map( $list_id = '', $flip = false ) {
35
- global $wpdb;
 
 
 
 
 
 
 
 
 
 
36
 
37
  $lists_map = array();
38
 
39
- $sSql = "SELECT id, name FROM " . IG_LISTS_TABLE . " WHERE deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' ";
40
- $res = $wpdb->get_results( $sSql, ARRAY_A );
41
- foreach ( $res as $list ) {
42
- $lists_map[ $list['id'] ] = $list['name'];
43
- }
44
 
45
- if ( ! empty( $list_id ) ) {
46
- $list_name = ! empty( $lists_map[ $list_id ] ) ? $lists_map[ $list_id ] : '';
47
 
48
- return $list_name;
49
- }
 
 
 
 
50
 
51
- if ( $flip ) {
52
- $lists_map = array_flip( $lists_map );
 
 
 
 
53
  }
54
 
55
  return $lists_map;
56
  }
57
 
58
- public static function get_list_by_name( $name ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  global $wpdb;
60
 
61
  $lists = array();
@@ -72,36 +164,66 @@ class ES_DB_Lists {
72
  }
73
 
74
  return $list;
 
75
  }
76
 
77
- public static function get_all_lists_name_by_contact( $id ) {
 
 
 
 
 
 
 
 
 
 
 
78
  global $wpdb;
79
 
80
- $sSql = $wpdb->prepare( "SELECT name FROM " . IG_LISTS_TABLE . " where id IN ( SELECT list_id from " . IG_LISTS_CONTACTS_TABLE . " where contact_id = %d ) AND ( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' ) ", $id );
 
 
81
  $res = $wpdb->get_col( $sSql );
82
 
83
  return $res;
84
  }
85
 
86
- public static function add_lists( $lists ) {
87
- global $wpdb;
 
 
 
 
 
 
 
 
88
 
89
  if ( is_string( $lists ) ) {
90
  $lists = array( $lists );
91
  }
92
 
93
- $query = "SELECT LOWER(name) FROM " . IG_LISTS_TABLE;
94
- $existing_lists = $wpdb->get_col( $query );
95
- foreach ( $lists as $key => $list ) {
96
- // Insert only if list is not exists.
97
- $lower_list = strtolower( $list );
98
- if ( ! in_array( $lower_list, $existing_lists ) ) {
99
- $sql = "INSERT INTO " . IG_LISTS_TABLE . " (`slug`, `name`, `created_at`) VALUES (%s, %s, %s)";
100
- $query = $wpdb->prepare( $sql, sanitize_title( $list ), $list, ig_get_current_date_time() );
101
- $wpdb->query( $query );
102
- $existing_lists[] = $list;
103
  }
104
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  }
106
 
107
  /**
@@ -113,9 +235,28 @@ class ES_DB_Lists {
113
  *
114
  * @since 4.0.0
115
  */
116
- public static function add_list( $list ) {
117
- global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
118
 
 
 
 
 
 
 
 
 
119
  $list_table = IG_LISTS_TABLE;
120
 
121
  $query = "SELECT LOWER(name) FROM {$list_table}";
@@ -138,9 +279,53 @@ class ES_DB_Lists {
138
  }
139
 
140
  return 0;
 
141
 
142
  }
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  /**
145
  * Get total count of lists
146
  *
@@ -148,12 +333,10 @@ class ES_DB_Lists {
148
  *
149
  * @since 4.2.0
150
  */
151
- public static function count_lists() {
152
-
153
- global $wpdb;
154
 
155
- $query = "SELECT count(*) as total_lists FROM " . IG_LISTS_TABLE . " WHERE deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00'";
156
- $lists = $wpdb->get_var( $query );
157
 
158
  return $lists;
159
 
@@ -168,15 +351,35 @@ class ES_DB_Lists {
168
  *
169
  * @since 4.2.0
170
  */
171
- public static function get_list_name_by_id( $id ) {
 
 
 
 
 
 
 
 
 
 
 
172
  global $wpdb;
173
 
174
- $list_table = IG_LISTS_TABLE;
175
- $query = "SELECT name FROM {$list_table} WHERE id = %d";
176
- $sql = $wpdb->prepare( $query, $id );
177
- $lists = $wpdb->get_var( $sql );
178
 
179
- return $lists;
 
 
 
 
 
 
 
 
 
 
180
  }
181
 
182
 
4
  exit;
5
  }
6
 
7
+ class ES_DB_Lists extends ES_DB {
8
+ /**
9
+ * @since 4.0.0
10
+ * @var $table_name
11
+ *
12
+ */
13
  public $table_name;
14
+ /**
15
+ * @since 4.0.0
16
+ * @var $version
17
+ *
18
+ */
19
  public $version;
20
+ /**
21
+ * @since 4.0.0
22
+ * @var $primary_key
23
+ *
24
+ */
25
  public $primary_key;
26
 
27
+ /**
28
+ * ES_DB_Lists constructor.
29
+ *
30
+ * @since 4.0.0
31
+ */
32
  public function __construct() {
33
+ global $wpdb;
34
+
35
+ $this->table_name = $wpdb->prefix . 'ig_lists';
36
+
37
+ $this->primary_key = 'id';
38
+
39
+ $this->version = '1.0';
40
 
41
  }
42
 
43
+ /**
44
+ * Get table columns
45
+ *
46
+ * @return array
47
+ *
48
+ * @since 4.2.1
49
+ */
50
+ public function get_columns() {
51
+ return array(
52
+ 'id' => '%d',
53
+ 'slug' => '%s',
54
+ 'name' => '%s',
55
+ 'created_at' => '%s',
56
+ 'updated_at' => '%s',
57
+ 'deleted_at' => '%s'
58
+ );
59
+ }
60
+
61
+ /**
62
+ * Get default column values
63
+ *
64
+ * @since 4.2.1
65
+ */
66
+ public function get_column_defaults() {
67
+ return array(
68
+ 'slug' => null,
69
+ 'name' => null,
70
+ 'created_at' => ig_get_current_date_time(),
71
+ 'updated_at' => null,
72
+ 'deleted_at' => null
73
+ );
74
+ }
75
 
76
+ /**
77
+ * Get Lists
78
+ *
79
+ * @return array|object|null
80
+ *
81
+ * @since 4.0.0
82
+ */
83
+ public function get_lists() {
84
+ global $wpdb;
85
 
86
+ $query = "SELECT * FROM {$this->table_name} WHERE deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' ";
 
 
 
87
 
88
  $lists = $wpdb->get_results( $query, ARRAY_A );
89
 
90
  return $lists;
91
  }
92
 
93
+ /**
94
+ * Get list id name map
95
+ *
96
+ * @param string $list_id
97
+ * @param bool $flip
98
+ *
99
+ * @return array|mixed|string
100
+ *
101
+ * @since 4.0.0
102
+ *
103
+ * @modify 4.2.1
104
+ */
105
+ public function get_list_id_name_map( $list_id = '', $flip = false ) {
106
 
107
  $lists_map = array();
108
 
109
+ $lists = $this->get_lists();
 
 
 
 
110
 
111
+ if ( count( $lists ) > 0 ) {
 
112
 
113
+ foreach ( $lists as $list ) {
114
+ $lists_map[ $list['id'] ] = $list['name'];
115
+ }
116
+
117
+ if ( ! empty( $list_id ) ) {
118
+ $list_name = ! empty( $lists_map[ $list_id ] ) ? $lists_map[ $list_id ] : '';
119
 
120
+ return $list_name;
121
+ }
122
+
123
+ if ( $flip ) {
124
+ $lists_map = array_flip( $lists_map );
125
+ }
126
  }
127
 
128
  return $lists_map;
129
  }
130
 
131
+ /**
132
+ * Get list by name
133
+ *
134
+ * @param $name
135
+ *
136
+ * @return array|mixed
137
+ *
138
+ * @since 4.0.0
139
+ *
140
+ * @modify 4.2.1
141
+ */
142
+ public function get_list_by_name( $name ) {
143
+ $list = $this->get_by( 'name', $name );
144
+ if ( is_null( $list ) ) {
145
+ $list = array();
146
+ }
147
+
148
+ return $list;
149
+
150
+ /* TODO: Keep for sometime. Remove it after complete verification/ testing
151
  global $wpdb;
152
 
153
  $lists = array();
164
  }
165
 
166
  return $list;
167
+ */
168
  }
169
 
170
+ /**
171
+ * Get all lists name by contact_id
172
+ *
173
+ * @param $id
174
+ *
175
+ * @return array
176
+ *
177
+ * @since 4.0.0
178
+ *
179
+ * @modify 4.2.0
180
+ */
181
+ public function get_all_lists_name_by_contact( $id ) {
182
  global $wpdb;
183
 
184
+ $lists_contact_table = IG_LISTS_CONTACTS_TABLE;
185
+
186
+ $sSql = $wpdb->prepare( "SELECT `name` FROM {$this->table_name} WHERE id IN ( SELECT list_id FROM {$lists_contact_table} WHERE contact_id = %d ) AND ( deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00' ) ", $id );
187
  $res = $wpdb->get_col( $sSql );
188
 
189
  return $res;
190
  }
191
 
192
+ /**
193
+ * Add lists
194
+ *
195
+ * @param $lists
196
+ *
197
+ * @since 4.0.0
198
+ *
199
+ * @modify 4.2.1
200
+ */
201
+ public function add_lists( $lists ) {
202
 
203
  if ( is_string( $lists ) ) {
204
  $lists = array( $lists );
205
  }
206
 
207
+ if ( count( $lists ) > 0 ) {
208
+ foreach ( $lists as $key => $list ) {
209
+ $this->add_list( $list );
 
 
 
 
 
 
 
210
  }
211
  }
212
+
213
+ /**
214
+ * $query = "SELECT LOWER(name) FROM " . IG_LISTS_TABLE;
215
+ * $existing_lists = $wpdb->get_col( $query );
216
+ * foreach ( $lists as $key => $list ) {
217
+ * // Insert only if list is not exists.
218
+ * $lower_list = strtolower( $list );
219
+ * if ( ! in_array( $lower_list, $existing_lists ) ) {
220
+ * $sql = "INSERT INTO " . IG_LISTS_TABLE . " (`slug`, `name`, `created_at`) VALUES (%s, %s, %s)";
221
+ * $query = $wpdb->prepare( $sql, sanitize_title( $list ), $list, ig_get_current_date_time() );
222
+ * $wpdb->query( $query );
223
+ * $existing_lists[] = $list;
224
+ * }
225
+ * }
226
+ */
227
  }
228
 
229
  /**
235
  *
236
  * @since 4.0.0
237
  */
238
+ public function add_list( $list = '' ) {
239
+
240
+ if ( empty( $list ) || ! is_string( $list ) ) {
241
+ return 0;
242
+ }
243
+
244
+ $lower_list = strtolower( $list );
245
+
246
+ $is_list_exists = $this->is_list_exists( $lower_list );
247
+
248
+ if ( $is_list_exists ) {
249
+ return 0;
250
+ }
251
 
252
+ $data = array(
253
+ 'slug' => sanitize_title( $list ),
254
+ 'name' => $list
255
+ );
256
+
257
+ return $this->insert( $data );
258
+
259
+ /*
260
  $list_table = IG_LISTS_TABLE;
261
 
262
  $query = "SELECT LOWER(name) FROM {$list_table}";
279
  }
280
 
281
  return 0;
282
+ */
283
 
284
  }
285
 
286
+ /**
287
+ * Update List
288
+ *
289
+ * @param int $row_id
290
+ * @param array $data
291
+ *
292
+ * @return bool|void
293
+ *
294
+ * @since 4.2.1
295
+ */
296
+ public function update_list( $row_id = 0, $name ) {
297
+
298
+ if ( empty( $row_id ) ) {
299
+ return;
300
+ }
301
+
302
+ $data = array(
303
+ 'name' => $name,
304
+ 'updated_at' => ig_get_current_date_time()
305
+ );
306
+
307
+ return $this->update( $row_id, $data );
308
+ }
309
+
310
+ /**
311
+ * Check if list is already exists
312
+ *
313
+ * @param $name
314
+ *
315
+ * @return bool
316
+ *
317
+ * @since 4.2.1
318
+ */
319
+ public function is_list_exists( $name ) {
320
+ $col = $this->get_by( 'name', $name );
321
+
322
+ if ( is_null( $col ) ) {
323
+ return false;
324
+ }
325
+
326
+ return true;
327
+ }
328
+
329
  /**
330
  * Get total count of lists
331
  *
333
  *
334
  * @since 4.2.0
335
  */
336
+ public function count_lists() {
337
+ $where = "deleted_at IS NULL OR deleted_at = '0000-00-00 00:00:00'";
 
338
 
339
+ $lists = $this->count($where);
 
340
 
341
  return $lists;
342
 
351
  *
352
  * @since 4.2.0
353
  */
354
+ public function get_list_name_by_id( $id ) {
355
+ return $this->get_column_by( 'name', 'id', $id );
356
+ }
357
+
358
+ /**
359
+ * Delete lists
360
+ *
361
+ * @param $ids
362
+ *
363
+ * @since 4.2.1
364
+ */
365
+ public function delete_lists( $ids ) {
366
  global $wpdb;
367
 
368
+ if ( is_int( $ids ) ) {
369
+ $ids = array( $ids );
370
+ }
 
371
 
372
+ $ids = implode( ', ', array_map( 'absint', $ids ) );
373
+
374
+ // We are doing soft delete.
375
+ $query = "UPDATE {$this->table_name} SET deleted_at = %s WHERE id IN ($ids)";
376
+ $query = $wpdb->prepare( $query, array( ig_get_current_date_time() ) );
377
+ $wpdb->query( $query );
378
+
379
+ // Delete Contacts From Lists Contacts Table
380
+ $ig_lists_contacts_table = IG_LISTS_CONTACTS_TABLE;
381
+ $query = "DELETE FROM {$ig_lists_contacts_table} WHERE list_id IN ($ids)";
382
+ $wpdb->query( $query );
383
  }
384
 
385
 
includes/db/class-es-db-mailing-queue.php CHANGED
@@ -169,6 +169,20 @@ class ES_DB_Mailing_Queue {
169
  return $notification;
170
  }
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  public static function get_notifications( $per_page = 5, $page_number = 1 ) {
173
  global $wpdb;
174
 
169
  return $notification;
170
  }
171
 
172
+ public static function get_notification_by_campaign_id($campaign_id) {
173
+ global $wpdb;
174
+
175
+ $notification = array();
176
+ $query = $wpdb->prepare( "SELECT * FROM " . IG_MAILING_QUEUE_TABLE . " WHERE campaign_id = %d", $campaign_id );
177
+ $results = $wpdb->get_results( $query, ARRAY_A );
178
+
179
+ if ( count( $results ) > 0 ) {
180
+ $notification = array_shift( $results );
181
+ }
182
+
183
+ return $notification;
184
+ }
185
+
186
  public static function get_notifications( $per_page = 5, $page_number = 1 ) {
187
  global $wpdb;
188
 
includes/db/class-es-db-queue.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if accessed directly
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ /**
8
+ * ES_DB_Queue class
9
+ *
10
+ * @since 4.2.1
11
+ */
12
+ class ES_DB_Queue extends ES_DB {
13
+ /**
14
+ * @since 4.2.1
15
+ * @var $table_name
16
+ *
17
+ */
18
+ public $table_name;
19
+
20
+ /**
21
+ * @since 4.2.1
22
+ * @var $version
23
+ *
24
+ */
25
+ public $version;
26
+
27
+ /**
28
+ * @since 4.2.1
29
+ * @var $primary_key
30
+ *
31
+ */
32
+ public $primary_key;
33
+
34
+ /**
35
+ * ES_DB constructor.
36
+ *
37
+ * @since 4.0.0
38
+ */
39
+ public function __construct() {
40
+ global $wpdb;
41
+
42
+ parent::__construct();
43
+
44
+ $this->table_name = $wpdb->prefix . 'ig_queue';
45
+
46
+ $this->version = '1.0';
47
+ }
48
+
49
+ /**
50
+ * Delete from queue based on campaign_id & contact_id
51
+ *
52
+ * @param $campaign_id
53
+ * @param $contact_id
54
+ *
55
+ * @return bool|int
56
+ *
57
+ * @since 4.2.1
58
+ */
59
+ public function delete_from_queue($campaign_id, $contact_id) {
60
+ global $wpdb;
61
+
62
+ $sql = "DELETE FROM $this->table_name WHERE campaign_id = %d AND $contact_id = %d";
63
+
64
+ return $wpdb->query($wpdb->prepare($sql, $campaign_id, $contact_id));
65
+ }
66
+
67
+ }
includes/db/class-es-db.php CHANGED
@@ -4,45 +4,145 @@ if ( ! defined( 'ABSPATH' ) ) {
4
  exit;
5
  }
6
 
 
 
 
 
 
7
  abstract class ES_DB {
8
-
 
 
 
 
9
  public $table_name;
10
 
 
 
 
 
 
11
  public $version;
12
 
 
 
 
 
 
13
  public $primary_key;
14
 
 
 
 
 
 
15
  public function __construct() {
16
  }
17
 
 
 
 
 
 
 
 
18
  public function get_columns() {
19
  return array();
20
  }
21
 
 
 
 
 
 
22
  public function get_column_defaults() {
23
  return array();
24
  }
25
 
26
- public function get( $row_id ) {
 
 
 
 
 
 
 
 
 
27
  global $wpdb;
28
 
29
- return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
30
  }
31
 
32
- public function get_by( $column, $row_id ) {
 
 
 
 
 
 
 
 
 
 
33
  global $wpdb;
34
  $column = esc_sql( $column );
35
 
36
- return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
 
39
- public function get_column( $column, $row_id ) {
 
 
 
 
 
 
 
 
 
 
40
  global $wpdb;
 
41
  $column = esc_sql( $column );
42
 
43
- return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
 
 
 
 
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
46
  public function get_column_by( $column, $column_where, $column_value ) {
47
  global $wpdb;
48
  $column_where = esc_sql( $column_where );
@@ -51,12 +151,24 @@ abstract class ES_DB {
51
  return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
54
  public function insert( $data, $type = '' ) {
55
  global $wpdb;
56
 
57
  // Set default values
58
  $data = wp_parse_args( $data, $this->get_column_defaults() );
59
 
 
 
60
  // Initialise column format array
61
  $column_formats = $this->get_columns();
62
 
@@ -73,9 +185,22 @@ abstract class ES_DB {
73
  $wpdb->insert( $this->table_name, $data, $column_formats );
74
  $wpdb_insert_id = $wpdb->insert_id;
75
 
 
 
76
  return $wpdb_insert_id;
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
79
  public function update( $row_id, $data = array(), $where = '' ) {
80
 
81
  global $wpdb;
@@ -111,6 +236,15 @@ abstract class ES_DB {
111
  return true;
112
  }
113
 
 
 
 
 
 
 
 
 
 
114
  public function delete( $row_id = 0 ) {
115
 
116
  global $wpdb;
@@ -129,6 +263,15 @@ abstract class ES_DB {
129
  return true;
130
  }
131
 
 
 
 
 
 
 
 
 
 
132
  public function table_exists( $table ) {
133
  global $wpdb;
134
  $table = sanitize_text_field( $table );
@@ -136,10 +279,103 @@ abstract class ES_DB {
136
  return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
137
  }
138
 
 
 
 
 
 
 
 
139
  public function installed() {
140
  return $this->table_exists( $this->table_name );
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  public static function do_insert( $table_name, $fields, $place_holders, $values ) {
144
  global $wpdb;
145
 
@@ -156,6 +392,7 @@ abstract class ES_DB {
156
  }
157
  }
158
 
 
159
  public static function prepare_data( $data, $column_formats, $column_defaults, $insert = true ) {
160
 
161
  // Set default values
4
  exit;
5
  }
6
 
7
+ /**
8
+ * ES_DB base class
9
+ *
10
+ * @since 4.0
11
+ */
12
  abstract class ES_DB {
13
+ /**
14
+ * @since 4.0.0
15
+ * @var $table_name
16
+ *
17
+ */
18
  public $table_name;
19
 
20
+ /**
21
+ * @since 4.0.0
22
+ * @var $version
23
+ *
24
+ */
25
  public $version;
26
 
27
+ /**
28
+ * @since 4.0.0
29
+ * @var $primary_key
30
+ *
31
+ */
32
  public $primary_key;
33
 
34
+ /**
35
+ * ES_DB constructor.
36
+ *
37
+ * @since 4.0.0
38
+ */
39
  public function __construct() {
40
  }
41
 
42
+ /**
43
+ * Get default columns
44
+ *
45
+ * @return array
46
+ *
47
+ * @since 4.0.0
48
+ */
49
  public function get_columns() {
50
  return array();
51
  }
52
 
53
+ /**
54
+ * @return array
55
+ *
56
+ * @since 4.0.0
57
+ */
58
  public function get_column_defaults() {
59
  return array();
60
  }
61
 
62
+ /**
63
+ * Retrieve a row by the primary key
64
+ *
65
+ * @param $row_id
66
+ *
67
+ * @return array|object|void|null
68
+ *
69
+ * @since 4.0.0
70
+ */
71
+ public function get( $row_id, $output = ARRAY_A ) {
72
  global $wpdb;
73
 
74
+ return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ), $output );
75
  }
76
 
77
+ /**
78
+ * Retrieve a row by a specific column / value
79
+ *
80
+ * @param $column
81
+ * @param $row_id
82
+ *
83
+ * @return array|object|void|null
84
+ *
85
+ * @since 4.0.0
86
+ */
87
+ public function get_by( $column, $row_id, $output = ARRAY_A ) {
88
  global $wpdb;
89
  $column = esc_sql( $column );
90
 
91
+ return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $this->table_name WHERE $column = %s LIMIT 1;", $row_id ), $output );
92
+ }
93
+
94
+ /**
95
+ * Get rows by conditions
96
+ *
97
+ * @param string $where
98
+ *
99
+ * @since 4.2.1
100
+ */
101
+ public function get_by_conditions( $where = '', $output = ARRAY_A ) {
102
+ global $wpdb;
103
+
104
+ $query = "SELECT * FROM $this->table_name";
105
+
106
+ if ( ! empty( $where ) ) {
107
+ $query .= " WHERE {$where}";
108
+ }
109
+
110
+ return $wpdb->get_results( $query, $output );
111
  }
112
 
113
+ /**
114
+ * Retrieve a specific column's value by the primary key
115
+ *
116
+ * @param $column
117
+ * @param $row_id
118
+ *
119
+ * @return null|string|array
120
+ *
121
+ * @since 4.0.0
122
+ */
123
+ public function get_column( $column, $row_id = 0 ) {
124
  global $wpdb;
125
+
126
  $column = esc_sql( $column );
127
 
128
+ if ( $row_id ) {
129
+ return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $this->primary_key = %s LIMIT 1;", $row_id ) );
130
+ } else {
131
+ return $wpdb->get_col( "SELECT $column FROM $this->table_name" );
132
+ }
133
  }
134
 
135
+ /**
136
+ * Retrieve a specific column's value by the the specified column / value
137
+ *
138
+ * @param $column
139
+ * @param $column_where
140
+ * @param $column_value
141
+ *
142
+ * @return string|null
143
+ *
144
+ * @since 4.0.0
145
+ */
146
  public function get_column_by( $column, $column_where, $column_value ) {
147
  global $wpdb;
148
  $column_where = esc_sql( $column_where );
151
  return $wpdb->get_var( $wpdb->prepare( "SELECT $column FROM $this->table_name WHERE $column_where = %s LIMIT 1;", $column_value ) );
152
  }
153
 
154
+ /**
155
+ * Insert a new row
156
+ *
157
+ * @param $data
158
+ * @param string $type
159
+ *
160
+ * @return int
161
+ *
162
+ * @since 4.0.0
163
+ */
164
  public function insert( $data, $type = '' ) {
165
  global $wpdb;
166
 
167
  // Set default values
168
  $data = wp_parse_args( $data, $this->get_column_defaults() );
169
 
170
+ do_action( 'ig_es_pre_insert_' . $type, $data );
171
+
172
  // Initialise column format array
173
  $column_formats = $this->get_columns();
174
 
185
  $wpdb->insert( $this->table_name, $data, $column_formats );
186
  $wpdb_insert_id = $wpdb->insert_id;
187
 
188
+ do_action( 'ig_es_post_insert_' . $type, $wpdb_insert_id, $data );
189
+
190
  return $wpdb_insert_id;
191
  }
192
 
193
+ /**
194
+ * Update a specific row
195
+ *
196
+ * @param $row_id
197
+ * @param array $data
198
+ * @param string $where
199
+ *
200
+ * @return bool
201
+ *
202
+ * @since 4.0.0
203
+ */
204
  public function update( $row_id, $data = array(), $where = '' ) {
205
 
206
  global $wpdb;
236
  return true;
237
  }
238
 
239
+ /**
240
+ * Delete a row by primary key
241
+ *
242
+ * @param int $row_id
243
+ *
244
+ * @return bool
245
+ *
246
+ * @since 4.0.0
247
+ */
248
  public function delete( $row_id = 0 ) {
249
 
250
  global $wpdb;
263
  return true;
264
  }
265
 
266
+ /**
267
+ * Check whether table exists or not
268
+ *
269
+ * @param $table
270
+ *
271
+ * @return bool
272
+ *
273
+ * @since 4.0.0
274
+ */
275
  public function table_exists( $table ) {
276
  global $wpdb;
277
  $table = sanitize_text_field( $table );
279
  return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE '%s'", $table ) ) === $table;
280
  }
281
 
282
+ /**
283
+ * Check whether table installed
284
+ *
285
+ * @return bool
286
+ *
287
+ * @since 4.0.0
288
+ */
289
  public function installed() {
290
  return $this->table_exists( $this->table_name );
291
  }
292
 
293
+ /**
294
+ * Get total count
295
+ *
296
+ * @return string|null
297
+ *
298
+ * @since 4.2.1
299
+ */
300
+ public function count( $where = '' ) {
301
+ global $wpdb;
302
+
303
+ $query = "SELECT count(*) FROM $this->table_name";
304
+
305
+ if ( ! empty( $where ) ) {
306
+ $query .= " WHERE {$where}";
307
+ }
308
+
309
+ return $wpdb->get_var( $query );
310
+ }
311
+
312
+ /**
313
+ * Insert data into bulk
314
+ *
315
+ * @param $values
316
+ * @param int $length
317
+ * @param string $type
318
+ *
319
+ * @since 4.2.1
320
+ */
321
+ public function bulk_insert( $values, $length = 100, $type = '' ) {
322
+ global $wpdb;
323
+
324
+ if ( ! is_array( $values ) ) {
325
+ return;
326
+ }
327
+
328
+ // Get the first value from an array to check data structure
329
+ $data = $values[0];
330
+
331
+ // Set default values
332
+ $data = wp_parse_args( $data, $this->get_column_defaults() );
333
+
334
+ // Initialise column format array
335
+ $column_formats = $this->get_columns();
336
+
337
+ // Remove primary key as we don't require while inserting data
338
+ unset( $column_formats[ $this->primary_key ] );
339
+
340
+ // Force fields to lower case
341
+ $data = array_change_key_case( $data );
342
+
343
+ // White list columns
344
+ $data = array_intersect_key( $data, $column_formats );
345
+
346
+ // Reorder $column_formats to match the order of columns given in $data
347
+ $data = wp_parse_args( $data, $this->get_column_defaults() );
348
+
349
+ $data_keys = array_keys( $data );
350
+ $fields = array_merge( array_flip( $data_keys ), $column_formats );
351
+
352
+ // Convert Batches into smaller chunk
353
+ $batches = array_chunk( $values, $length );
354
+
355
+ foreach ( $batches as $key => $batch ) {
356
+
357
+ $place_holders = $final_values = array();
358
+
359
+ foreach ( $batch as $value ) {
360
+
361
+ $formats = array();
362
+ foreach ( $column_formats as $column => $format ) {
363
+ $final_values[] = $value[ $column ];
364
+ $formats[] = $format;
365
+ }
366
+
367
+ $place_holders[] = "( " . implode( ', ', $formats ) . " )";
368
+ $fields_str = "`" . implode( "`, `", $fields ) . "`";
369
+ $query = "INSERT INTO $this->table_name ({$fields_str}) VALUES ";
370
+ $query .= implode( ', ', $place_holders );
371
+ $sql = $wpdb->prepare( $query, $final_values );
372
+
373
+ $wpdb->query( $sql );
374
+ }
375
+ }
376
+ }
377
+
378
+
379
  public static function do_insert( $table_name, $fields, $place_holders, $values ) {
380
  global $wpdb;
381
 
392
  }
393
  }
394
 
395
+
396
  public static function prepare_data( $data, $column_formats, $column_defaults, $insert = true ) {
397
 
398
  // Set default values
includes/es-backward.php CHANGED
@@ -8,7 +8,7 @@ if ( ! defined( 'ABSPATH' ) ) {
8
  class es_cls_dbquery {
9
 
10
  public static function es_view_subscriber_group() {
11
- $res = ES_DB_Lists::get_list_id_name_map();
12
  foreach ( $res as $id => $name ) {
13
  $list['id'] = $id;
14
  $list['es_email_group'] = $name;
@@ -61,7 +61,7 @@ class es_cls_dbquery {
61
  $status = 'unconfirmed';
62
  }
63
 
64
- $list_data = ES_DB_Lists::get_list_by_name( $data['es_email_group'] );
65
  $list_id = ! empty( $list_data['id'] ) ? $list_data['id'] : 1;
66
  $list_ids = array( $list_id );
67
  $list_contact_data = array(
@@ -94,7 +94,7 @@ class es_cls_dbquery {
94
  // Send Welcome Email.
95
  ES_Mailer::send_welcome_email($email, $data);
96
 
97
- $list_name = ES_DB_Lists::get_list_id_name_map( $list_id );
98
  $template_data = array(
99
  'name' => $name,
100
  'first_name' => $sub_data['first_name'],
8
  class es_cls_dbquery {
9
 
10
  public static function es_view_subscriber_group() {
11
+ $res = ES()->lists_db->get_list_id_name_map();
12
  foreach ( $res as $id => $name ) {
13
  $list['id'] = $id;
14
  $list['es_email_group'] = $name;
61
  $status = 'unconfirmed';
62
  }
63
 
64
+ $list_data = ES()->lists_db->get_list_by_name( $data['es_email_group'] );
65
  $list_id = ! empty( $list_data['id'] ) ? $list_data['id'] : 1;
66
  $list_ids = array( $list_id );
67
  $list_contact_data = array(
94
  // Send Welcome Email.
95
  ES_Mailer::send_welcome_email($email, $data);
96
 
97
+ $list_name = ES()->lists_db->get_list_id_name_map( $list_id );
98
  $template_data = array(
99
  'name' => $name,
100
  'first_name' => $sub_data['first_name'],
includes/feedback/class-ig-feedback.php CHANGED
@@ -11,7 +11,7 @@ if ( ! class_exists( 'IG_Feedback_V_1_0_10' ) ) {
11
  * The IG Feedback class adds functionality to get quick interactive feedback from users.
12
  * There are different types of feedabck widget like Stars, Emoji, Thubms Up/ Down, Number etc.
13
  *
14
- * @class IG_Feedback_V_1_0_10
15
  * @package feedback
16
  * @copyright Copyright (c) 2019, Icegram
17
  * @license https://opensource.org/licenses/gpl-license GNU Public License
11
  * The IG Feedback class adds functionality to get quick interactive feedback from users.
12
  * There are different types of feedabck widget like Stars, Emoji, Thubms Up/ Down, Number etc.
13
  *
14
+ * @class IG_Feedback_V_1_0_9
15
  * @package feedback
16
  * @copyright Copyright (c) 2019, Icegram
17
  * @license https://opensource.org/licenses/gpl-license GNU Public License
includes/feedback/class-ig-tracker.php CHANGED
@@ -7,12 +7,12 @@ if ( ! defined( 'ABSPATH' ) ) {
7
  if ( ! class_exists( 'IG_Tracker_V_1_0_10' ) ) {
8
 
9
  /**
10
- * Class IG_Tracker_V_1_0_10
11
  *
12
  * Icegram tracker handler class is responsible for sending anonymous plugin
13
  * data to Icegram servers for users that actively allowed data tracking.
14
  *
15
- * @class IG_Tracker_V_1_0_10
16
  * @package feedback
17
  * @copyright Copyright (c) 2019, Icegram
18
  * @license https://opensource.org/licenses/gpl-license GNU Public License
7
  if ( ! class_exists( 'IG_Tracker_V_1_0_10' ) ) {
8
 
9
  /**
10
+ * Class IG_Tracker_V_1_0_9
11
  *
12
  * Icegram tracker handler class is responsible for sending anonymous plugin
13
  * data to Icegram servers for users that actively allowed data tracking.
14
  *
15
+ * @class IG_Tracker_V_1_0_9
16
  * @package feedback
17
  * @copyright Copyright (c) 2019, Icegram
18
  * @license https://opensource.org/licenses/gpl-license GNU Public License
includes/pro-features.php CHANGED
@@ -17,7 +17,7 @@ add_action( 'ig_es_sync_users_tabs_edd', 'ig_es_add_edd_tab_settings' );
17
  add_action( 'edit_form_advanced', 'add_spam_score_utm_link' );
18
 
19
  function ig_es_add_upsale( $fields ) {
20
- global $ig_es_tracker;
21
 
22
  $es_premium = 'email-subscribers-premium/email-subscribers-premium.php';
23
  $all_plugins = $ig_es_tracker::get_plugins();
17
  add_action( 'edit_form_advanced', 'add_spam_score_utm_link' );
18
 
19
  function ig_es_add_upsale( $fields ) {
20
+ global $ig_es_tracker;
21
 
22
  $es_premium = 'email-subscribers-premium/email-subscribers-premium.php';
23
  $all_plugins = $ig_es_tracker::get_plugins();
includes/upgrade/es-update-functions.php CHANGED
@@ -416,7 +416,9 @@ function ig_es_update_400_delete_tables() {
416
  $wpdb->prefix . 'ig_lists',
417
  $wpdb->prefix . 'ig_lists_contacts',
418
  $wpdb->prefix . 'ig_mailing_queue',
419
- $wpdb->prefix . 'ig_sending_queue'
 
 
420
  );
421
 
422
  foreach ( $tables_to_delete as $table ) {
@@ -471,7 +473,7 @@ function ig_es_update_400_migrate_lists() {
471
 
472
  if ( count( $lists ) > 0 || count( $ps_lists ) > 0 ) {
473
  $all_lists = array_unique( array_merge( $lists, $ps_lists ) );
474
- ES_DB_Lists::add_lists( $all_lists );
475
  }
476
 
477
  }
@@ -482,7 +484,7 @@ function ig_es_update_400_migrate_subscribers() {
482
  }
483
 
484
  function ig_es_update_400_migrate_post_notifications() {
485
- ES_DB_Campaigns::migrate_post_notifications();
486
  }
487
 
488
 
@@ -518,7 +520,7 @@ function ig_es_update_400_db_version() {
518
 
519
  function ig_es_update_401_migrate_newsletters() {
520
  // Migrate newsletters from es_sentdetails table
521
- ES_DB_Campaigns::migrate_newsletters();
522
  }
523
 
524
  function ig_es_update_401_db_version() {
@@ -611,7 +613,7 @@ function ig_es_update_4011_migrate_newsletter_es_template_type() {
611
  }
612
 
613
  function ig_es_update_4011_update_campaign_id_in_mailing_queue() {
614
- ES_DB_Campaigns::update_campaign_id_in_mailing_queue();
615
  }
616
 
617
  function ig_es_update_4011_db_version() {
@@ -809,19 +811,19 @@ function ig_es_update_420_alter_campaigns_table() {
809
  }
810
 
811
  // Add `subject`
812
- if(!in_array('subject', $cols)) {
813
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns ADD COLUMN `subject` varchar(255) DEFAULT NULL AFTER `parent_type`";
814
  $wpdb->query( $query );
815
  }
816
 
817
  // Add `body`
818
- if(!in_array('body', $cols)) {
819
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns ADD COLUMN `body` longtext DEFAULT NULL AFTER `subject`";
820
  $wpdb->query( $query );
821
  }
822
 
823
  // Drop `sequence_ids`
824
- if(in_array('sequence_ids', $cols)) {
825
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns DROP COLUMN `sequence_ids`";
826
  $wpdb->query( $query );
827
  }
@@ -881,4 +883,48 @@ function ig_es_update_420_db_version() {
881
  ES_Install::update_db_version( '4.2.0' );
882
  }
883
 
 
884
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
  $wpdb->prefix . 'ig_lists',
417
  $wpdb->prefix . 'ig_lists_contacts',
418
  $wpdb->prefix . 'ig_mailing_queue',
419
+ $wpdb->prefix . 'ig_sending_queue',
420
+ $wpdb->prefix . 'ig_queue',
421
+ $wpdb->prefix . 'ig_actions'
422
  );
423
 
424
  foreach ( $tables_to_delete as $table ) {
473
 
474
  if ( count( $lists ) > 0 || count( $ps_lists ) > 0 ) {
475
  $all_lists = array_unique( array_merge( $lists, $ps_lists ) );
476
+ ES()->lists_db->add_lists( $all_lists );
477
  }
478
 
479
  }
484
  }
485
 
486
  function ig_es_update_400_migrate_post_notifications() {
487
+ ES()->campaigns_db->migrate_post_notifications();
488
  }
489
 
490
 
520
 
521
  function ig_es_update_401_migrate_newsletters() {
522
  // Migrate newsletters from es_sentdetails table
523
+ ES()->campaigns_db->migrate_newsletters();
524
  }
525
 
526
  function ig_es_update_401_db_version() {
613
  }
614
 
615
  function ig_es_update_4011_update_campaign_id_in_mailing_queue() {
616
+ ES()->campaigns_db->update_campaign_id_in_mailing_queue();
617
  }
618
 
619
  function ig_es_update_4011_db_version() {
811
  }
812
 
813
  // Add `subject`
814
+ if ( ! in_array( 'subject', $cols ) ) {
815
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns ADD COLUMN `subject` varchar(255) DEFAULT NULL AFTER `parent_type`";
816
  $wpdb->query( $query );
817
  }
818
 
819
  // Add `body`
820
+ if ( ! in_array( 'body', $cols ) ) {
821
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns ADD COLUMN `body` longtext DEFAULT NULL AFTER `subject`";
822
  $wpdb->query( $query );
823
  }
824
 
825
  // Drop `sequence_ids`
826
+ if ( in_array( 'sequence_ids', $cols ) ) {
827
  $query = "ALTER TABLE {$wpdb->prefix}ig_campaigns DROP COLUMN `sequence_ids`";
828
  $wpdb->query( $query );
829
  }
883
  ES_Install::update_db_version( '4.2.0' );
884
  }
885
 
886
+ /* --------------------- ES 4.2.0(End)--------------------------- */
887
 
888
+ function ig_es_update_421_drop_tables() {
889
+ global $wpdb;
890
+
891
+ /**
892
+ * Note: Still we are not using ig_contact_meta table.
893
+ * So, it's ok to drop ig_contact_meta table now
894
+ * Because we want to use WordPress' metadata api and for that we need ig_contactmeta table
895
+ * Which we are going to create in 'ig_es_update_421_create_table' function.
896
+ */
897
+ $tables_to_drop = array(
898
+ $wpdb->prefix . 'ig_contact_meta',
899
+ $wpdb->prefix . 'ig_actions'
900
+ );
901
+
902
+ foreach ( $tables_to_drop as $table ) {
903
+ $query = "DROP TABLE IF EXISTS {$table}";
904
+ $wpdb->query( $query );
905
+ }
906
+ }
907
+
908
+ /**
909
+ * Create New Table
910
+ *
911
+ * @since 4.2.1
912
+ */
913
+ function ig_es_update_421_create_tables() {
914
+ global $wpdb;
915
+
916
+ $wpdb->hide_errors();
917
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
918
+ dbDelta( ES_Install::get_ig_es_421_schema() );
919
+ }
920
+
921
+ /**
922
+ * Update DB Update history
923
+ *
924
+ * @since 4.2.1
925
+ */
926
+ function ig_es_update_421_db_version() {
927
+ ES_Install::update_db_version( '4.2.1' );
928
+ }
929
+
930
+ /* --------------------- ES 4.2.1(End)--------------------------- */
public/class-email-subscribers-public.php CHANGED
@@ -175,7 +175,7 @@ class Email_Subscribers_Public {
175
  ES_DB_Contacts::edit_subscriber_status_global( $ids, $unsubscribed );
176
  ES_DB_Lists_Contacts::edit_subscriber_status( $ids, $status );
177
  //send welcome email
178
- $contact = ES_DB_Contacts::get_subsribers_email_name_map( array( $email ) );
179
  $data = array(
180
  'name' => ! empty( $contact[ $email ] ) ? $contact[ $email ]['name'] : '',
181
  'first_name' => ! empty( $contact[ $email ] ) ? $contact[ $email ]['first_name'] : '',
@@ -193,7 +193,7 @@ class Email_Subscribers_Public {
193
  ES_Mailer::send( $email, $subject, $content );
194
  }
195
 
196
- $lists = ES_DB_Lists::get_all_lists_name_by_contact( $db_id );
197
  $list_name = implode( ", ", $lists );
198
 
199
  $data['list_name'] = $list_name;
175
  ES_DB_Contacts::edit_subscriber_status_global( $ids, $unsubscribed );
176
  ES_DB_Lists_Contacts::edit_subscriber_status( $ids, $status );
177
  //send welcome email
178
+ $contact = ES_DB_Contacts::get_subscribers_email_name_map( array( $email ) );
179
  $data = array(
180
  'name' => ! empty( $contact[ $email ] ) ? $contact[ $email ]['name'] : '',
181
  'first_name' => ! empty( $contact[ $email ] ) ? $contact[ $email ]['first_name'] : '',
193
  ES_Mailer::send( $email, $subject, $content );
194
  }
195
 
196
+ $lists = ES()->lists_db->get_all_lists_name_by_contact( $db_id );
197
  $list_name = implode( ", ", $lists );
198
 
199
  $data['list_name'] = $list_name;
public/partials/class-es-shortcode.php CHANGED
@@ -148,7 +148,7 @@ class ES_Shortcode {
148
 
149
  // Lists
150
  if ( ! empty( $list_ids ) && $show_list ) {
151
- $lists_id_name_map = ES_DB_Lists::get_list_id_name_map();
152
  $list_html = self::prepare_lists_checkboxes( $lists_id_name_map, $list_ids, 1 );
153
  } elseif ( ! empty( $list_ids ) && ! $show_list ) {
154
  $list_html = '';
@@ -158,9 +158,9 @@ class ES_Shortcode {
158
  } elseif ( is_numeric( $list ) ) {
159
  $list_html = '<input type="hidden" name="lists[]" value="' . $list . '" />';
160
  } else {
161
- $list_data = ES_DB_Lists::get_list_by_name( $list );
162
  if ( empty( $list_data ) ) {
163
- $list_id = ES_DB_Lists::add_list( $list );
164
  } else {
165
  $list_id = $list_data['id'];
166
  }
148
 
149
  // Lists
150
  if ( ! empty( $list_ids ) && $show_list ) {
151
+ $lists_id_name_map = ES()->lists_db->get_list_id_name_map();
152
  $list_html = self::prepare_lists_checkboxes( $lists_id_name_map, $list_ids, 1 );
153
  } elseif ( ! empty( $list_ids ) && ! $show_list ) {
154
  $list_html = '';
158
  } elseif ( is_numeric( $list ) ) {
159
  $list_html = '<input type="hidden" name="lists[]" value="' . $list . '" />';
160
  } else {
161
+ $list_data = ES()->lists_db->get_list_by_name( $list );
162
  if ( empty( $list_data ) ) {
163
+ $list_id = ES()->lists_db->add_list( $list );
164
  } else {
165
  $list_id = $list_data['id'];
166
  }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Author URI: https://www.icegram.com/
5
  Tags: subscription, newsletter, email marketing, post notification, email newsletter form, email signup, email widget, newsletter signup, subscribe, subscription form, bulk emails, signup form, list builder, lead generation, welcome email, contacts
6
  Requires at least: 3.9
7
  Tested up to: 5.2.3
8
- Stable tag: 4.2.0
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses
11
 
@@ -300,6 +300,9 @@ Refer [here](https://www.icegram.com/documentation/es-faq/).
300
 
301
  == Changelog ==
302
 
 
 
 
303
  = 4.2.0 (01.10.2019) =
304
  * New: [Pepipost](https://pepipost.com/?utm_source=icegram&utm_medium=es_inapp&utm_campaign=pepipost) api support for email sending
305
 
5
  Tags: subscription, newsletter, email marketing, post notification, email newsletter form, email signup, email widget, newsletter signup, subscribe, subscription form, bulk emails, signup form, list builder, lead generation, welcome email, contacts
6
  Requires at least: 3.9
7
  Tested up to: 5.2.3
8
+ Stable tag: 4.2.1
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses
11
 
300
 
301
  == Changelog ==
302
 
303
+ = 4.2.1 (10.10.2019) =
304
+ * Update: Added per page screen option for Contacts, Forms, Lists & Campaigns
305
+
306
  = 4.2.0 (01.10.2019) =
307
  * New: [Pepipost](https://pepipost.com/?utm_source=icegram&utm_medium=es_inapp&utm_campaign=pepipost) api support for email sending
308