Email Subscribers & Newsletters - Version 4.1.12

Version Description

(07.08.2019) = * Fix: Set post categories correctly after migration * Fix: Get all lists from emaillist & notification tables

Download this release

Release Info

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

Code changes from version 4.1.11 to 4.1.12

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.1.11
7
  * Author: Icegram
8
  * Author URI: https://www.icegram.com/
9
  * Requires at least: 3.9
@@ -24,7 +24,7 @@ if ( ! defined( 'WPINC' ) ) {
24
  * Define constants
25
  */
26
  define( 'ES_PLUGIN_DIR', dirname( __FILE__ ) );
27
- define( 'ES_PLUGIN_VERSION', '4.1.11' );
28
  define( 'ES_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
29
 
30
  if ( ! defined( 'ES_PLUGIN_FILE' ) ) {
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.1.12
7
  * Author: Icegram
8
  * Author URI: https://www.icegram.com/
9
  * Requires at least: 3.9
24
  * Define constants
25
  */
26
  define( 'ES_PLUGIN_DIR', dirname( __FILE__ ) );
27
+ define( 'ES_PLUGIN_VERSION', '4.1.12' );
28
  define( 'ES_PLUGIN_BASE_NAME', plugin_basename( __FILE__ ) );
29
 
30
  if ( ! defined( 'ES_PLUGIN_FILE' ) ) {
includes/class-es-common.php CHANGED
@@ -480,6 +480,7 @@ Class ES_Common {
480
  public static function convert_categories_array_to_string( $categories = array() ) {
481
 
482
  $categories_str = '';
 
483
  if ( is_array( $categories ) && count( $categories ) > 0 ) {
484
  $categories_str = "##" . implode( '##', $categories ) . "##";
485
  $categories_str = wp_specialchars_decode( $categories_str, ENT_QUOTES );
@@ -789,7 +790,7 @@ Class ES_Common {
789
  }
790
 
791
  public static function temp_filter_category( $category ) {
792
- return trim( trim( $category, '##' ), '' );
793
  }
794
 
795
  public static function show_message( $message = '', $status = 'success', $is_dismissible = true ) {
@@ -942,11 +943,11 @@ Class ES_Common {
942
  $results = $wpdb->get_results( $query, ARRAY_A );
943
 
944
  $options_name_value_map = array();
945
- if(count($results) > 0 ) {
946
- foreach ($results as $result) {
947
- $options_name_value_map[$result['option_name']] = $result['option_value'];
948
- }
949
- }
950
 
951
  return $options_name_value_map;
952
  }
480
  public static function convert_categories_array_to_string( $categories = array() ) {
481
 
482
  $categories_str = '';
483
+
484
  if ( is_array( $categories ) && count( $categories ) > 0 ) {
485
  $categories_str = "##" . implode( '##', $categories ) . "##";
486
  $categories_str = wp_specialchars_decode( $categories_str, ENT_QUOTES );
790
  }
791
 
792
  public static function temp_filter_category( $category ) {
793
+ return trim( trim( $category ), '#' );
794
  }
795
 
796
  public static function show_message( $message = '', $status = 'success', $is_dismissible = true ) {
943
  $results = $wpdb->get_results( $query, ARRAY_A );
944
 
945
  $options_name_value_map = array();
946
+ if ( count( $results ) > 0 ) {
947
+ foreach ( $results as $result ) {
948
+ $options_name_value_map[ $result['option_name'] ] = $result['option_value'];
949
+ }
950
+ }
951
 
952
  return $options_name_value_map;
953
  }
includes/class-es-install.php CHANGED
@@ -125,10 +125,12 @@ class ES_Install {
125
  *
126
  * @var object
127
  */
128
- private static $background_updater;
129
-
130
  public static $logger;
131
 
 
 
 
 
132
  /**
133
  * Hook in tabs.
134
  */
@@ -136,37 +138,43 @@ class ES_Install {
136
 
137
  self::$logger = get_ig_logger();
138
 
139
- self::$logger->info( '--- Init Installation Process..' );
140
- add_action( 'init', array( __CLASS__, 'check_version' ), 5 );
141
- add_action( 'init', array( __CLASS__, 'init_background_updater' ), 5 );
142
  add_action( 'admin_init', array( __CLASS__, 'install_actions' ) );
143
  }
144
 
145
  public static function check_version() {
146
- self::$logger->info( 'Checking Version..' . get_option( 'ig_es_db_version', '1.0.0' ) );
147
- if ( version_compare( get_option( 'ig_es_db_version', '1.0.0' ), ES_PLUGIN_VERSION, '<' ) ) {
148
- self::$logger->info( 'Seems need to run updater..' );
 
 
 
 
 
 
 
 
 
149
  self::install();
150
  }
151
  }
152
 
153
- public static function init_background_updater() {
154
- self::$logger->info( 'Init Background Updater..' );
155
- include_once dirname( __FILE__ ) . '/upgrade/class-es-background-updater.php';
156
- self::$background_updater = new ES_Background_Updater();
157
- }
158
-
159
  public static function install_actions() {
160
  if ( ! empty( $_GET['do_update_ig_es'] ) ) { // WPCS: input var ok.
161
  check_admin_referer( 'ig_es_db_update', 'ig_es_db_update_nonce' );
162
  $from_db_version = ! empty( $_GET['from_db_version'] ) ? $_GET['from_db_version'] : '';
163
 
 
 
164
  if ( ! empty( $from_db_version ) ) {
 
 
165
  self::update_db_version( $from_db_version );
166
- self::delete_update_transient();
167
  }
168
 
169
- self::update();
 
170
  ES_Admin_Notices::add_notice( 'update' );
171
  }
172
 
@@ -182,31 +190,41 @@ class ES_Install {
182
  public static function install() {
183
 
184
  if ( ! is_blog_installed() ) {
 
 
185
  return;
186
  }
187
 
188
  // Check if we are not already running this routine.
189
  if ( 'yes' === get_transient( 'ig_es_installing' ) ) {
 
 
190
  return;
191
  }
192
 
193
  if ( self::is_new_install() ) {
194
- self::$logger->info( 'New Install??? Yes...Begin installing......' );
 
195
 
196
  // If we made it till here nothing is running yet, lets set the transient now.
197
  set_transient( 'ig_es_installing', 'yes', MINUTE_IN_SECONDS * 10 );
198
- ig_es_maybe_define_constant( 'IG_ES_INSTALLING', true );
199
 
 
200
 
201
  // Create Tables
202
  self::create_tables();
203
 
 
 
204
  // Create Default Optiom
205
  self::create_options();
206
 
 
 
207
  // Create Default List and contact
208
  self::create_default_list_contact();
209
 
 
210
  // Create and send default broadcast
211
  // self::create_and_send_default_broadcast();
212
 
@@ -216,7 +234,8 @@ class ES_Install {
216
  //Create Default form
217
  self::create_default_form();
218
 
219
- self::$logger->info( 'Installation Complete......' );
 
220
  }
221
 
222
  self::maybe_update_db_version();
@@ -228,14 +247,16 @@ class ES_Install {
228
  public static function delete_update_transient() {
229
  global $wpdb;
230
 
231
- delete_option('ig_es_processed_update_tasks');
 
232
 
233
  $transient_like = $wpdb->esc_like( '_transient_ig_es_update_' ) . '%';
234
  $updating_like = $wpdb->esc_like( '_transient_ig_es_updating' ) . '%';
235
  $last_sent_queue_like = '%' . $wpdb->esc_like( '_last_sending_queue_batch_run' ) . '%';
236
  $running_migration_queue_like = '%' . $wpdb->esc_like( '_running_migration_for_' ) . '%';
 
237
 
238
- $query = "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '{$transient_like}' OR option_name LIKE '{$updating_like}' OR option_name LIKE '{$last_sent_queue_like}' OR option_name LIKE '{$running_migration_queue_like}' ";
239
 
240
  $wpdb->query( $query );
241
 
@@ -245,30 +266,42 @@ class ES_Install {
245
  return is_null( get_option( 'ig_es_db_version', null ) ) && is_null( get_option( 'current_sa_email_subscribers_db_version', null ) );
246
  }
247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
248
  private static function needs_db_update() {
249
- self::$logger->info( 'Needs DB Update?......' );
 
250
  $current_db_version = get_ig_es_db_version();
251
- $updates = self::get_db_update_callbacks();
252
- $update_versions = array_keys( $updates );
253
- usort( $update_versions, 'version_compare' );
254
 
255
- self::$logger->info( 'Current DB VERSION-------------------' . $current_db_version );
 
 
256
 
257
- return ! is_null( $current_db_version ) && version_compare( $current_db_version, end( $update_versions ), '<' );
258
  }
259
 
260
  private static function maybe_update_db_version() {
261
  if ( self::needs_db_update() ) {
262
  if ( apply_filters( 'ig_es_enable_auto_update_db', true ) ) {
263
- self::$logger->info( 'Do Update DB ................. >>>>>>>>>>>>>>>>>>>>>>>' );
264
- self::init_background_updater();
265
  self::update();
266
  } else {
267
- self::$logger->info( 'Show Update Notice..' );
268
  ES_Admin_Notices::add_notice( 'update' );
269
  }
270
  } else {
271
- self::$logger->info( 'No need to update db...' );
272
  self::update_db_version();
273
  }
274
  }
@@ -277,43 +310,156 @@ class ES_Install {
277
  return self::$db_updates;
278
  }
279
 
280
- private static function update() {
281
- self::$logger->info( 'Do Update....' );
 
282
 
283
  // Check if we are not already running this routine.
284
- if ( 'yes' === get_transient( 'ig_es_updating' ) ) {
285
- self::$logger->info( '********* Update is already running..... ****** ' );
 
286
  return;
287
  }
288
 
289
  set_transient( 'ig_es_updating', 'yes', MINUTE_IN_SECONDS * 5 );
290
 
291
  $current_db_version = get_ig_es_db_version();
292
- $update_queued = false;
293
-
294
- self::$logger->info( 'Current IG ES DB Version: ' . $current_db_version );
295
- foreach ( self::get_db_update_callbacks() as $version => $update_callbacks ) {
296
- if ( version_compare( $current_db_version, $version, '<' ) ) {
297
- foreach ( $update_callbacks as $update_callback ) {
298
- self::$logger->info(
299
- sprintf( 'Queuing %s - %s', $version, $update_callback ),
300
- array( 'source' => 'ig_es_db_updates' )
301
- );
302
 
303
- self::$background_updater->push_to_queue( $update_callback );
304
- $update_queued = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  }
 
306
  }
 
 
 
 
307
  }
308
 
309
- if ( $update_queued ) {
310
- self::$background_updater->save()->dispatch();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
  }
312
 
 
313
  }
314
 
 
315
  public static function update_db_version( $version = null ) {
316
- update_option( 'ig_es_db_version', is_null( $version ) ? ES_PLUGIN_VERSION : $version );
 
 
 
317
  }
318
 
319
  private static function create_options() {
@@ -328,6 +474,10 @@ class ES_Install {
328
  $admin_email = get_option( 'admin_email' );
329
  $blogname = get_option( 'blogname' );
330
 
 
 
 
 
331
  if ( $admin_email == "" ) {
332
  $admin_email = "support@icegram.com";
333
  }
@@ -393,7 +543,7 @@ class ES_Install {
393
  'ig_es_unsubscribe_error_message' => array( 'default' => $unsubscribe_error_message, 'old_option' => 'ig_es_unsuberror' ),
394
  'ig_es_unsubscribe_success_message' => array( 'default' => $unsubscribe_message, 'old_option' => 'ig_es_unsubtext' ),
395
  'ig_es_post_image_size' => array( 'default' => 'thumbnail', 'old_option' => 'ig_es_post_image_size' ),
396
- 'ig_es_db_version' => array( 'default' => ES_PLUGIN_VERSION, 'old_option' => 'current_sa_email_subscribers_db_version' ),
397
  'ig_es_current_version_date_details' => array( 'default' => '', 'old_option' => 'ig_es_current_version_date_details' ),
398
  'ig_es_enable_captcha' => array( 'default' => '', 'old_option' => '' ),
399
  'ig_es_roles_and_capabilities' => array( 'default' => '', 'old_option' => 'ig_es_rolesandcapabilities' ),
125
  *
126
  * @var object
127
  */
 
 
128
  public static $logger;
129
 
130
+ public static $logger_context = array(
131
+ 'source' => 'ig_es_db_updates'
132
+ );
133
+
134
  /**
135
  * Hook in tabs.
136
  */
138
 
139
  self::$logger = get_ig_logger();
140
 
141
+ self::$logger->info( '--- Init Installation Process..', self::$logger_context );
142
+ add_action( 'admin_init', array( __CLASS__, 'check_version' ), 5 );
 
143
  add_action( 'admin_init', array( __CLASS__, 'install_actions' ) );
144
  }
145
 
146
  public static function check_version() {
147
+
148
+ $current_db_version = get_option( 'ig_es_db_version', '1.0.0' );
149
+
150
+ self::$logger->info( sprintf( "Checking Version: %s", $current_db_version ), self::$logger_context );
151
+
152
+ // Get latest available DB update version
153
+ $latest_db_version_to_update = self::get_latest_db_version_to_update();
154
+
155
+ if ( version_compare( $current_db_version, $latest_db_version_to_update, '<' ) ) {
156
+
157
+ self::$logger->info( 'Require to run updater..Start Installation/ Update process', self::$logger_context );
158
+
159
  self::install();
160
  }
161
  }
162
 
 
 
 
 
 
 
163
  public static function install_actions() {
164
  if ( ! empty( $_GET['do_update_ig_es'] ) ) { // WPCS: input var ok.
165
  check_admin_referer( 'ig_es_db_update', 'ig_es_db_update_nonce' );
166
  $from_db_version = ! empty( $_GET['from_db_version'] ) ? $_GET['from_db_version'] : '';
167
 
168
+ self::delete_update_transient();
169
+
170
  if ( ! empty( $from_db_version ) ) {
171
+ self::$logger->info( sprintf( "Forcefully update database from: %s", $from_db_version ), self::$logger_context );
172
+
173
  self::update_db_version( $from_db_version );
 
174
  }
175
 
176
+ self::update( true );
177
+
178
  ES_Admin_Notices::add_notice( 'update' );
179
  }
180
 
190
  public static function install() {
191
 
192
  if ( ! is_blog_installed() ) {
193
+ self::$logger->error( 'Blog is not installed.', self::$logger_context );
194
+
195
  return;
196
  }
197
 
198
  // Check if we are not already running this routine.
199
  if ( 'yes' === get_transient( 'ig_es_installing' ) ) {
200
+ self::$logger->error( 'Installation process is running..', self::$logger_context );
201
+
202
  return;
203
  }
204
 
205
  if ( self::is_new_install() ) {
206
+
207
+ self::$logger->info( 'It seems new Email Subscribers. Start Installation process.', self::$logger_context );
208
 
209
  // If we made it till here nothing is running yet, lets set the transient now.
210
  set_transient( 'ig_es_installing', 'yes', MINUTE_IN_SECONDS * 10 );
 
211
 
212
+ ig_es_maybe_define_constant( 'IG_ES_INSTALLING', true );
213
 
214
  // Create Tables
215
  self::create_tables();
216
 
217
+ self::$logger->info( 'Create Tables.', self::$logger_context );
218
+
219
  // Create Default Optiom
220
  self::create_options();
221
 
222
+ self::$logger->info( 'Create Options.', self::$logger_context );
223
+
224
  // Create Default List and contact
225
  self::create_default_list_contact();
226
 
227
+ self::$logger->info( 'Create default list.', self::$logger_context );
228
  // Create and send default broadcast
229
  // self::create_and_send_default_broadcast();
230
 
234
  //Create Default form
235
  self::create_default_form();
236
 
237
+ self::$logger->info( 'Create default form.', self::$logger_context );
238
+ self::$logger->info( 'Installation Complete.', self::$logger_context );
239
  }
240
 
241
  self::maybe_update_db_version();
247
  public static function delete_update_transient() {
248
  global $wpdb;
249
 
250
+ delete_option( 'ig_es_update_processed_tasks' );
251
+ delete_option( 'ig_es_update_tasks_to_process' );
252
 
253
  $transient_like = $wpdb->esc_like( '_transient_ig_es_update_' ) . '%';
254
  $updating_like = $wpdb->esc_like( '_transient_ig_es_updating' ) . '%';
255
  $last_sent_queue_like = '%' . $wpdb->esc_like( '_last_sending_queue_batch_run' ) . '%';
256
  $running_migration_queue_like = '%' . $wpdb->esc_like( '_running_migration_for_' ) . '%';
257
+ $db_migration_queue_like = '%' . $wpdb->esc_like( 'ig_es_updater_batch_' ) . '%';
258
 
259
+ $query = "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '{$transient_like}' OR option_name LIKE '{$updating_like}' OR option_name LIKE '{$last_sent_queue_like}' OR option_name LIKE '{$running_migration_queue_like}' OR option_name LIKE '{$db_migration_queue_like}'";
260
 
261
  $wpdb->query( $query );
262
 
266
  return is_null( get_option( 'ig_es_db_version', null ) ) && is_null( get_option( 'current_sa_email_subscribers_db_version', null ) );
267
  }
268
 
269
+ /**
270
+ * Get latest db version based on available updates.
271
+ *
272
+ * @return mixed
273
+ */
274
+ public static function get_latest_db_version_to_update() {
275
+ $updates = self::get_db_update_callbacks();
276
+ $update_versions = array_keys( $updates );
277
+ usort( $update_versions, 'version_compare' );
278
+
279
+ return end( $update_versions );
280
+ }
281
+
282
  private static function needs_db_update() {
283
+ self::$logger->info( 'Needs DB Update?', self::$logger_context );
284
+
285
  $current_db_version = get_ig_es_db_version();
 
 
 
286
 
287
+ $latest_db_version_to_update = self::get_latest_db_version_to_update();
288
+
289
+ self::$logger->info( sprintf( "Current DB Version: %s", $current_db_version ), self::$logger_context );
290
 
291
+ return ! is_null( $current_db_version ) && version_compare( $current_db_version, $latest_db_version_to_update, '<' );
292
  }
293
 
294
  private static function maybe_update_db_version() {
295
  if ( self::needs_db_update() ) {
296
  if ( apply_filters( 'ig_es_enable_auto_update_db', true ) ) {
297
+ self::$logger->info( 'Database update require. Start updating database', self::$logger_context );
 
298
  self::update();
299
  } else {
300
+ self::$logger->info( 'Show update notice.', self::$logger_context );
301
  ES_Admin_Notices::add_notice( 'update' );
302
  }
303
  } else {
304
+ self::$logger->info( 'Database is upto date' );
305
  self::update_db_version();
306
  }
307
  }
310
  return self::$db_updates;
311
  }
312
 
313
+ private static function update( $force = false ) {
314
+
315
+ self::$logger->info( 'Do Update....', self::$logger_context );
316
 
317
  // Check if we are not already running this routine.
318
+ if ( ! $force && 'yes' === get_transient( 'ig_es_updating' ) ) {
319
+ self::$logger->info( '********* Update is already running..... ****** ', self::$logger_context );
320
+
321
  return;
322
  }
323
 
324
  set_transient( 'ig_es_updating', 'yes', MINUTE_IN_SECONDS * 5 );
325
 
326
  $current_db_version = get_ig_es_db_version();
 
 
 
 
 
 
 
 
 
 
327
 
328
+ $tasks_to_process = get_option( 'ig_es_update_tasks_to_process', array() );
329
+
330
+ // Get all tasks processed
331
+ $processed_tasks = get_option( 'ig_es_update_processed_tasks', array() );
332
+
333
+ self::$logger->info( sprintf( "Current IG ES DB Version: %s", $current_db_version ), self::$logger_context );
334
+
335
+ // Get al tasks to process
336
+ $tasks = self::get_db_update_callbacks();
337
+
338
+ if ( count( $tasks ) > 0 ) {
339
+
340
+ foreach ( $tasks as $version => $update_callbacks ) {
341
+
342
+ if ( version_compare( $current_db_version, $version, '<' ) ) {
343
+
344
+ foreach ( $update_callbacks as $update_callback ) {
345
+
346
+ if ( ! in_array( $update_callback, $tasks_to_process ) && ! in_array( $update_callback, $processed_tasks ) ) {
347
+ self::$logger->info( sprintf( '[Queue] %s', $update_callback ), self::$logger_context );
348
+ $tasks_to_process[] = $update_callback;
349
+ } else {
350
+ self::$logger->info( sprintf( 'Task "%s" is already processed or is in queue', $update_callback ), self::$logger_context );
351
+ }
352
+
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ if ( count( $tasks_to_process ) > 0 ) {
359
+
360
+ self::$logger->info( "Yes, we have tasks to process", self::$logger_context );
361
+
362
+ update_option( 'ig_es_update_tasks_to_process', $tasks_to_process );
363
+
364
+ self::dispatch();
365
+ } else {
366
+ self::$logger->info( "Sorry, we do not have any tasks to process", self::$logger_context );
367
+ delete_transient( 'ig_es_updating' );
368
+ }
369
+
370
+ }
371
+
372
+ public static function dispatch() {
373
+
374
+ $logger = get_ig_logger();
375
+
376
+ $batch = get_option( 'ig_es_update_tasks_to_process', array() );
377
+
378
+ $logger->info( '--------------------- Started To Run Task Again---------------------', self::$logger_context );
379
+
380
+ if ( count( $batch ) > 0 ) {
381
+
382
+ $current_memory_limit = @ini_get( 'memory_limit' );
383
+
384
+ // We may require lots of memory
385
+ @ini_set( 'memory_limit', '-1' );
386
+
387
+ // It may take long time to process database update.
388
+ // So, increase execution time
389
+ @set_time_limit( 360 );
390
+ @ini_set( 'max_execution_time', 360 );
391
+
392
+ foreach ( $batch as $key => $value ) {
393
+
394
+ $is_value_exists = true;
395
+ //$task_transient = $value . '_processed';
396
+ $ig_es_update_processed_tasks = get_option( 'ig_es_update_processed_tasks', array() );
397
+ $task = false; // By default it's set to false
398
+
399
+ // Check whether the tasks is already processed? If not, process it.
400
+ if ( ! in_array( $value, $ig_es_update_processed_tasks ) ) {
401
+ $is_value_exists = false;
402
+ $logger->info( sprintf( "[Processing] %s", $value ), self::$logger_context );
403
+ $task = (bool) self::task( $value );
404
+ $logger->info( sprintf( "[Processed] %s", $value ), self::$logger_context );
405
+ } else {
406
+ $logger->info( sprintf( "Task '%s' is already processed. Remove it from list", $value ), self::$logger_context );
407
+ unset( $batch[ $key ] );
408
+ }
409
+
410
+ if ( false === $task ) {
411
+
412
+ if ( ! $is_value_exists ) {
413
+ $ig_es_update_processed_tasks[] = $value;
414
+ update_option( 'ig_es_update_processed_tasks', $ig_es_update_processed_tasks );
415
+ }
416
+
417
+ unset( $batch[ $key ] );
418
  }
419
+
420
  }
421
+
422
+ update_option( 'ig_es_update_tasks_to_process', $batch );
423
+
424
+ @ini_set( 'memory_limit', $current_memory_limit );
425
  }
426
 
427
+ //Delete update transient
428
+ delete_transient( 'ig_es_updating' );
429
+
430
+ }
431
+
432
+ public static function task( $callback ) {
433
+
434
+ $logger = get_ig_logger();
435
+
436
+ include_once dirname( __FILE__ ) . '/upgrade/es-update-functions.php';
437
+
438
+ $result = false;
439
+
440
+ if ( is_callable( $callback ) ) {
441
+ $logger->info( sprintf( '--- Running Task - %s', $callback ), self::$logger_context );
442
+
443
+ $result = (bool) call_user_func( $callback );
444
+
445
+ if ( $result ) {
446
+ $logger->info( sprintf( '%s callback needs to run again', $callback ), self::$logger_context );
447
+ } else {
448
+ $logger->info( sprintf( '--- Finished Task - %s ', $callback ), self::$logger_context );
449
+ }
450
+ } else {
451
+ $logger->notice( sprintf( '--- Could not find %s callback', $callback ), self::$logger_context );
452
  }
453
 
454
+ return $result ? $callback : false;
455
  }
456
 
457
+
458
  public static function update_db_version( $version = null ) {
459
+
460
+ $latest_db_version_to_update = self::get_latest_db_version_to_update();
461
+
462
+ update_option( 'ig_es_db_version', is_null( $version ) ? $latest_db_version_to_update : $version );
463
  }
464
 
465
  private static function create_options() {
474
  $admin_email = get_option( 'admin_email' );
475
  $blogname = get_option( 'blogname' );
476
 
477
+ // We are setting latest_db_version as a ig_es_db_version option while installation
478
+ // So, we don't need to run the upgrage process again.
479
+ $latest_db_version = self::get_latest_db_version_to_update();
480
+
481
  if ( $admin_email == "" ) {
482
  $admin_email = "support@icegram.com";
483
  }
543
  'ig_es_unsubscribe_error_message' => array( 'default' => $unsubscribe_error_message, 'old_option' => 'ig_es_unsuberror' ),
544
  'ig_es_unsubscribe_success_message' => array( 'default' => $unsubscribe_message, 'old_option' => 'ig_es_unsubtext' ),
545
  'ig_es_post_image_size' => array( 'default' => 'thumbnail', 'old_option' => 'ig_es_post_image_size' ),
546
+ 'ig_es_db_version' => array( 'default' => $latest_db_version, 'old_option' => 'current_sa_email_subscribers_db_version' ),
547
  'ig_es_current_version_date_details' => array( 'default' => '', 'old_option' => 'ig_es_current_version_date_details' ),
548
  'ig_es_enable_captcha' => array( 'default' => '', 'old_option' => '' ),
549
  'ig_es_roles_and_capabilities' => array( 'default' => '', 'old_option' => 'ig_es_rolesandcapabilities' ),
includes/db/class-es-db-campaigns.php CHANGED
@@ -153,9 +153,9 @@ class ES_DB_Campaigns {
153
  if ( $total > 0 ) {
154
  $batch_size = IG_DEFAULT_BATCH_SIZE;
155
 
156
- $total_bataches = ( $total > IG_DEFAULT_BATCH_SIZE ) ? ceil( $total / $batch_size ) : 1;
157
 
158
- for ( $i = 0; $i < $total_bataches; $i ++ ) {
159
  $batch_start = $i * $batch_size;
160
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE . " LIMIT {$batch_start}, {$batch_size}";
161
  $notifications = $wpdb->get_results( $query, ARRAY_A );
@@ -164,7 +164,7 @@ class ES_DB_Campaigns {
164
  $categories = ! empty( $notification['es_note_cat'] ) ? $notification['es_note_cat'] : '';
165
  if ( ! empty( $categories ) ) {
166
  $categories = explode( '--', $categories );
167
- $categories = array_filter( $categories, array( 'ES_Common', 'temp_filter_category' ) );
168
  $categories = ES_Common::convert_categories_array_to_string( $categories );
169
  }
170
 
@@ -210,6 +210,7 @@ class ES_DB_Campaigns {
210
  $columns = self::get_columns();
211
  unset( $columns['id'] );
212
  $fields = array_keys( $columns );
 
213
  foreach ( $campaigns_data as $campaign_data ) {
214
  $campaign_data['slug'] = ! empty( $templates_data[ $campaign_data['slug'] ] ) ? $templates_data[ $campaign_data['slug'] ]['post_name'] : '';
215
  $campaign_data['name'] = ! empty( $templates_data[ $campaign_data['name'] ] ) ? $templates_data[ $campaign_data['name'] ]['post_title'] : '';
153
  if ( $total > 0 ) {
154
  $batch_size = IG_DEFAULT_BATCH_SIZE;
155
 
156
+ $total_batches = ( $total > IG_DEFAULT_BATCH_SIZE ) ? ceil( $total / $batch_size ) : 1;
157
 
158
+ for ( $i = 0; $i < $total_batches; $i ++ ) {
159
  $batch_start = $i * $batch_size;
160
  $query = "SELECT * FROM " . EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE . " LIMIT {$batch_start}, {$batch_size}";
161
  $notifications = $wpdb->get_results( $query, ARRAY_A );
164
  $categories = ! empty( $notification['es_note_cat'] ) ? $notification['es_note_cat'] : '';
165
  if ( ! empty( $categories ) ) {
166
  $categories = explode( '--', $categories );
167
+ $categories = array_map( array( 'ES_Common', 'temp_filter_category' ), $categories );
168
  $categories = ES_Common::convert_categories_array_to_string( $categories );
169
  }
170
 
210
  $columns = self::get_columns();
211
  unset( $columns['id'] );
212
  $fields = array_keys( $columns );
213
+
214
  foreach ( $campaigns_data as $campaign_data ) {
215
  $campaign_data['slug'] = ! empty( $templates_data[ $campaign_data['slug'] ] ) ? $templates_data[ $campaign_data['slug'] ]['post_name'] : '';
216
  $campaign_data['name'] = ! empty( $templates_data[ $campaign_data['name'] ] ) ? $templates_data[ $campaign_data['name'] ]['post_title'] : '';
includes/notices/class-es-admin-notices.php CHANGED
@@ -129,7 +129,7 @@ class ES_Admin_Notices {
129
  'email-subscribers_page_es_pricing',
130
  );
131
 
132
- if ( ! in_array( $screen_id, $show_on_screens, true ) ) {
133
  return;
134
  }
135
 
@@ -176,13 +176,16 @@ class ES_Admin_Notices {
176
  * If we need to update, include a message with the update button.
177
  */
178
  public static function update_notice() {
179
- if ( version_compare( get_ig_es_db_version(), ES_PLUGIN_VERSION, '<' ) ) {
180
- $updater = new ES_Background_Updater();
181
- if ( $updater->is_updating() || ! empty( $_GET['do_update_ig_es'] ) ) { // WPCS: input var ok, CSRF ok.
182
- include dirname( __FILE__ ) . '/views/html-notice-updating.php';
183
- } else {
184
- include dirname( __FILE__ ) . '/views/html-notice-update.php';
185
- }
 
 
 
186
  } else {
187
  include dirname( __FILE__ ) . '/views/html-notice-updated.php';
188
  }
129
  'email-subscribers_page_es_pricing',
130
  );
131
 
132
+ if ( ! in_array( $screen_id, $show_on_screens, true ) ) {
133
  return;
134
  }
135
 
176
  * If we need to update, include a message with the update button.
177
  */
178
  public static function update_notice() {
179
+
180
+ $latest_version_to_update = ES_Install::get_latest_db_version_to_update();
181
+
182
+ if ( version_compare( get_ig_es_db_version(), $latest_version_to_update, '<' ) ) {
183
+ // Database is updating now.
184
+ include dirname( __FILE__ ) . '/views/html-notice-updating.php';
185
+
186
+ // Show button to to "Run the updater"
187
+ //include dirname( __FILE__ ) . '/views/html-notice-update.php';
188
+
189
  } else {
190
  include dirname( __FILE__ ) . '/views/html-notice-updated.php';
191
  }
includes/upgrade/es-update-functions.php CHANGED
@@ -470,16 +470,19 @@ function ig_es_update_400_migrate_lists() {
470
  */
471
  global $wpdb;
472
 
473
-
474
  $sql = "SELECT distinct(es_email_group) FROM " . ES_EMAILLIST_TABLE;
475
  $lists = $wpdb->get_col( $sql );
476
 
 
 
 
477
 
478
- if ( count( $lists ) > 0 ) {
479
- ES_DB_Lists::add_lists( $lists );
 
480
  }
481
 
482
-
483
  }
484
 
485
  // Import contacts from es_emaillist table to ig_contacts and ig_lists_contacts table
470
  */
471
  global $wpdb;
472
 
473
+ // Collect list name from Email list
474
  $sql = "SELECT distinct(es_email_group) FROM " . ES_EMAILLIST_TABLE;
475
  $lists = $wpdb->get_col( $sql );
476
 
477
+ // Collect list name from notification table
478
+ $sql = "SELECT distinct(es_note_group) FROM " . EMAIL_SUBSCRIBERS_NOTIFICATION_TABLE;
479
+ $ps_lists = $wpdb->get_col($sql);
480
 
481
+ if ( count( $lists ) > 0 || count($ps_lists) > 0) {
482
+ $all_lists = array_unique(array_merge($lists, $ps_lists));
483
+ ES_DB_Lists::add_lists( $all_lists );
484
  }
485
 
 
486
  }
487
 
488
  // Import contacts from es_emaillist table to ig_contacts and ig_lists_contacts table
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.2
8
- Stable tag: 4.1.11
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses
11
 
@@ -305,6 +305,10 @@ Use our free plugin [Email Subscribers - Group Selector](https://wordpress.org/p
305
 
306
  == Changelog ==
307
 
 
 
 
 
308
  = 4.1.11 (02.08.2019) =
309
  * Fix: Send multiple email notification issue
310
 
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.2
8
+ Stable tag: 4.1.12
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses
11
 
305
 
306
  == Changelog ==
307
 
308
+ = 4.1.12 (07.08.2019) =
309
+ * Fix: Set post categories correctly after migration
310
+ * Fix: Get all lists from emaillist & notification tables
311
+
312
  = 4.1.11 (02.08.2019) =
313
  * Fix: Send multiple email notification issue
314