Import users from CSV with meta - Version 1.18.4

Version Description

  • Improved problem when deleting users, if errors happens but they are notices, we can delete now. Many of the users who have problems with deleting users not present in CSV, was created by the old conditional that checked any kind of error (including notices).
Download this release

Release Info

Developer carazo
Plugin Icon 128x128 Import users from CSV with meta
Version 1.18.4
Comparing to
See all releases

Code changes from version 1.18.3 to 1.18.4

classes/helper.php CHANGED
@@ -103,7 +103,20 @@ class ACUI_Helper{
103
  return $prefix . $rnd_str;
104
  }
105
 
106
- function new_error( $row, $message = '', $type = 'error' ){
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  return array( 'row' => $row, 'message' => $message, 'type' => $type );
108
  }
109
 
@@ -329,7 +342,7 @@ class ACUI_Helper{
329
  function print_results( $results, $errors ){
330
  ?>
331
  <h3><?php _e( 'Results', 'import-users-from-csv-with-meta' ); ?></h3>
332
- <table id="acui_errors">
333
  <tbody>
334
  <tr>
335
  <th><?php _e( 'Users processed', 'import-users-from-csv-with-meta' ); ?></th>
@@ -343,6 +356,10 @@ class ACUI_Helper{
343
  <th><?php _e( 'Users updated', 'import-users-from-csv-with-meta' ); ?></th>
344
  <td><?php echo $results['updated']; ?></td>
345
  </tr>
 
 
 
 
346
  <tr>
347
  <th><?php _e( 'Errors, warnings and notices found', 'import-users-from-csv-with-meta' ); ?></td>
348
  <td><?php echo count( $errors ); ?></td>
@@ -352,6 +369,13 @@ class ACUI_Helper{
352
  <?php
353
  }
354
 
 
 
 
 
 
 
 
355
  function execute_datatable(){
356
  ?>
357
  <script>
103
  return $prefix . $rnd_str;
104
  }
105
 
106
+ function new_error( $row, &$errors_totals, $message = '', $type = 'error' ){
107
+ switch( $type ){
108
+ case 'error':
109
+ $errors_totals['errors']++;
110
+ break;
111
+
112
+ case 'warning':
113
+ $errors_totals['warnings']++;
114
+ break;
115
+
116
+ case 'notice':
117
+ $errors_totals['notices']++;
118
+ break;
119
+ }
120
  return array( 'row' => $row, 'message' => $message, 'type' => $type );
121
  }
122
 
342
  function print_results( $results, $errors ){
343
  ?>
344
  <h3><?php _e( 'Results', 'import-users-from-csv-with-meta' ); ?></h3>
345
+ <table id="acui_results">
346
  <tbody>
347
  <tr>
348
  <th><?php _e( 'Users processed', 'import-users-from-csv-with-meta' ); ?></th>
356
  <th><?php _e( 'Users updated', 'import-users-from-csv-with-meta' ); ?></th>
357
  <td><?php echo $results['updated']; ?></td>
358
  </tr>
359
+ <tr>
360
+ <th><?php _e( 'Users deleted', 'import-users-from-csv-with-meta' ); ?></th>
361
+ <td><?php echo $results['deleted']; ?></td>
362
+ </tr>
363
  <tr>
364
  <th><?php _e( 'Errors, warnings and notices found', 'import-users-from-csv-with-meta' ); ?></td>
365
  <td><?php echo count( $errors ); ?></td>
369
  <?php
370
  }
371
 
372
+ function print_end_of_process(){
373
+ ?>
374
+ <br/>
375
+ <p><?php printf( __( 'Process finished you can go <a href="%s">here to see results</a> or you can do <a href="%s">a new import</a>.', 'import-users-from-csv-with-meta' ), get_admin_url( null, 'users.php' ), get_admin_url( null, 'tools.php?page=acui&tab=homepage' ) ); ?></p>
376
+ <?php
377
+ }
378
+
379
  function execute_datatable(){
380
  ?>
381
  <script>
classes/import.php CHANGED
@@ -219,9 +219,10 @@ class ACUI_Import{
219
  $row = 0;
220
  $positions = array();
221
  $errors = array();
222
- $results = array( 'created' => 0, 'updated' => 0 );
 
223
 
224
- ini_set('auto_detect_line_endings',TRUE);
225
 
226
  $delimiter = $acui_helper->detect_delimiter( $file );
227
 
@@ -293,7 +294,7 @@ class ACUI_Import{
293
  $data = apply_filters( 'pre_acui_import_single_user_data', $data, $headers );
294
 
295
  if( count( $data ) != $columns ): // if number of columns is not the same that columns in header
296
- $errors[] = $acui_helper->new_error( $row, __( 'Row does not have the same columns than the header, we are going to ignore this row', 'import-users-from-csv-with-meta') );
297
  continue;
298
  endif;
299
 
@@ -330,23 +331,23 @@ class ACUI_Import{
330
  }
331
 
332
  if ( !empty( array_diff( $role, $all_roles ) ) ){
333
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'Some of the next roles "%s" does not exists', 'import-users-from-csv-with-meta' ), implode( ', ', $role ) ) );
334
  continue;
335
  }
336
 
337
  if ( !empty( array_diff( $role, $editable_roles ) ) ){ // users only are able to import users with a role they are allowed to edit
338
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'You do not have permission to assign some of the next roles "%s"', 'import-users-from-csv-with-meta' ), implode( ', ', $role ) ) );
339
  $created = false;
340
  continue;
341
  }
342
 
343
  if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid
344
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'Invalid email "%s"', 'import-users-from-csv-with-meta' ), $email ) );
345
  $data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
346
  continue;
347
  }
348
- elseif( empty( $email) ) {
349
- $errors[] = $acui_helper->new_error( $row, __( 'Email not specified', 'import-users-from-csv-with-meta' ) );
350
  $data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
351
  continue;
352
  }
@@ -354,7 +355,7 @@ class ACUI_Import{
354
  if( !empty( $id ) ){ // if user have used id
355
  if( $acui_helper->user_id_exists( $id ) ){
356
  if( $update_existing_users == 'no' ){
357
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'User with ID "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $id ), 'notice' );
358
  continue;
359
  }
360
 
@@ -371,12 +372,12 @@ class ACUI_Import{
371
 
372
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
373
  if( empty( $new_user_id ) ){
374
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'User with email "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $email ), 'notice' );
375
  continue;
376
  }
377
 
378
  if( is_wp_error( $new_user_id ) ){
379
- $errors[] = $acui_helper->new_error( $row, $new_user_id->get_error_message() );
380
  $data[0] = $new_user_id->get_error_message();
381
  $created = false;
382
  }
@@ -386,12 +387,12 @@ class ACUI_Import{
386
  $user_id = $new_user_id;
387
  $new_user = get_user_by( 'id', $new_user_id );
388
  $data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
389
- $errors[] = $acui_helper->new_error( $row, $data[0] );
390
  $created = true;
391
  }
392
  }
393
  else{
394
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'Problems with ID "%s" username is not the same in the CSV and in database', 'import-users-from-csv-with-meta' ), $id ) );
395
  continue;
396
  }
397
  }
@@ -409,7 +410,7 @@ class ACUI_Import{
409
  }
410
  elseif( username_exists( $username ) ){
411
  if( $update_existing_users == 'no' ){
412
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'User with username "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $username ), 'notice' );
413
  continue;
414
  }
415
 
@@ -424,13 +425,13 @@ class ACUI_Import{
424
 
425
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
426
  if( empty( $new_user_id ) ){
427
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'User with email "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $email ), 'notice' );
428
  continue;
429
  }
430
 
431
  if( is_wp_error( $new_user_id ) ){
432
  $data[0] = $new_user_id->get_error_message();
433
- $errors[] = $acui_helper->new_error( $row, $data[0] );
434
  $created = false;
435
  }
436
  elseif( $new_user_id == $user_id)
@@ -439,7 +440,7 @@ class ACUI_Import{
439
  $user_id = $new_user_id;
440
  $new_user = get_user_by( 'id', $new_user_id );
441
  $data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
442
- $errors[] = $acui_helper->new_error( $row, $data[0], 'warning' );
443
  $created = true;
444
  }
445
  }
@@ -452,7 +453,7 @@ class ACUI_Import{
452
  $user_id = $user_object->ID;
453
 
454
  $data[0] = sprintf( __( 'User already exists as: %s (in this CSV file is called: %s)', 'import-users-from-csv-with-meta' ), $user_object->user_login, $username );
455
- $errors[] = $acui_helper->new_error( $row, $data[0], 'warning' );
456
 
457
  if( $password !== "" && $update_allow_update_passwords == 'yes' ){
458
  wp_set_password( $password, $user_id );
@@ -482,7 +483,7 @@ class ACUI_Import{
482
  }
483
 
484
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
485
- $errors[] = $acui_helper->new_error( $row, sprintf( __( 'Problems with user: "%s" does not exists, error: %s', 'import-users-from-csv-with-meta' ), $username, $user_id->get_error_message() ) );
486
  continue;
487
  }
488
 
@@ -536,7 +537,7 @@ class ACUI_Import{
536
  else
537
  $data[0] = __('Invalid roles','import-users-from-csv-with-meta').' (' . implode( ', ', $invalid_roles ) . ')';
538
 
539
- $errors[] = $acui_helper->new_error( $row, $data[0], 'warning' );
540
  }
541
  }
542
  }
@@ -646,8 +647,6 @@ class ACUI_Import{
646
 
647
  $acui_helper->print_errors( $errors );
648
 
649
- $acui_helper->print_results( $results, $errors );
650
-
651
  // let the filter of default WordPress emails as it were before deactivating them
652
  if( !get_option('acui_automatic_wordpress_email') ){
653
  remove_filter( 'send_email_change_email', function() { return false; }, 999 );
@@ -684,7 +683,7 @@ class ACUI_Import{
684
  $change_role_not_present_role = get_option( "acui_frontend_change_role_not_present_role");
685
  }
686
 
687
- if( !empty( $errors ) ){ // if there is some problem of some kind importing we won't proceed with delete or changing role to users not present to avoid problems
688
  $delete_users_flag = false;
689
  $change_role_not_present_flag = false;
690
  }
@@ -714,7 +713,8 @@ class ACUI_Import{
714
  $all_users_ids = array_map( function( $element ){ return intval( $element->ID ); }, $all_users );
715
  $users_to_remove = array_diff( $all_users_ids, $users_registered );
716
 
717
- $delete_users_assign_posts = ( get_userdata( $delete_users_assign_posts ) === false ) ? false : $delete_users_assign_posts;
 
718
 
719
  foreach ( $users_to_remove as $user_id ) {
720
  ( empty( $delete_users_assign_posts ) ) ? wp_delete_user( $user_id ) : wp_delete_user( $user_id, $delete_users_assign_posts );
@@ -735,18 +735,17 @@ class ACUI_Import{
735
  $user_object->set_role( $change_role_not_present_role );
736
  }
737
  }
738
- endif;
739
 
740
- if( !$is_frontend ): ?>
741
- <br/>
742
- <p><?php printf( __( 'Process finished you can go <a href="%s">here to see results</a> or you can do <a href="%s">a new import</a>.', 'import-users-from-csv-with-meta' ), get_admin_url( null, 'users.php' ), get_admin_url( null, 'tools.php?page=acui&tab=homepage' ) ); ?></p>
743
- <?php endif; ?>
744
 
745
- <?php
 
 
746
  if( !$is_frontend && !$is_cron )
747
  $acui_helper->execute_datatable();
748
 
749
- ini_set( 'auto_detect_line_endings', FALSE );
750
 
751
  do_action( 'after_acui_import_users' );
752
  ?>
219
  $row = 0;
220
  $positions = array();
221
  $errors = array();
222
+ $errors_totals = array( 'notices' => 0, 'warnings' => 0, 'errors' => 0 );
223
+ $results = array( 'created' => 0, 'updated' => 0, 'deleted' => 0 );
224
 
225
+ @ini_set( 'auto_detect_line_endings', TRUE );
226
 
227
  $delimiter = $acui_helper->detect_delimiter( $file );
228
 
294
  $data = apply_filters( 'pre_acui_import_single_user_data', $data, $headers );
295
 
296
  if( count( $data ) != $columns ): // if number of columns is not the same that columns in header
297
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, __( 'Row does not have the same columns than the header, we are going to ignore this row', 'import-users-from-csv-with-meta') );
298
  continue;
299
  endif;
300
 
331
  }
332
 
333
  if ( !empty( array_diff( $role, $all_roles ) ) ){
334
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'Some of the next roles "%s" does not exists', 'import-users-from-csv-with-meta' ), implode( ', ', $role ) ) );
335
  continue;
336
  }
337
 
338
  if ( !empty( array_diff( $role, $editable_roles ) ) ){ // users only are able to import users with a role they are allowed to edit
339
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'You do not have permission to assign some of the next roles "%s"', 'import-users-from-csv-with-meta' ), implode( ', ', $role ) ) );
340
  $created = false;
341
  continue;
342
  }
343
 
344
  if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid
345
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'Invalid email "%s"', 'import-users-from-csv-with-meta' ), $email ) );
346
  $data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
347
  continue;
348
  }
349
+ elseif( empty( $email ) ) {
350
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, __( 'Email not specified', 'import-users-from-csv-with-meta' ) );
351
  $data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
352
  continue;
353
  }
355
  if( !empty( $id ) ){ // if user have used id
356
  if( $acui_helper->user_id_exists( $id ) ){
357
  if( $update_existing_users == 'no' ){
358
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'User with ID "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $id ), 'notice' );
359
  continue;
360
  }
361
 
372
 
373
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
374
  if( empty( $new_user_id ) ){
375
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'User with email "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $email ), 'notice' );
376
  continue;
377
  }
378
 
379
  if( is_wp_error( $new_user_id ) ){
380
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $new_user_id->get_error_message() );
381
  $data[0] = $new_user_id->get_error_message();
382
  $created = false;
383
  }
387
  $user_id = $new_user_id;
388
  $new_user = get_user_by( 'id', $new_user_id );
389
  $data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
390
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $data[0], 'notice' );
391
  $created = true;
392
  }
393
  }
394
  else{
395
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'Problems with ID "%s" username is not the same in the CSV and in database', 'import-users-from-csv-with-meta' ), $id ) );
396
  continue;
397
  }
398
  }
410
  }
411
  elseif( username_exists( $username ) ){
412
  if( $update_existing_users == 'no' ){
413
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'User with username "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $username ), 'notice' );
414
  continue;
415
  }
416
 
425
 
426
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
427
  if( empty( $new_user_id ) ){
428
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'User with email "%s" exists, we ignore it', 'import-users-from-csv-with-meta' ), $email ), 'notice' );
429
  continue;
430
  }
431
 
432
  if( is_wp_error( $new_user_id ) ){
433
  $data[0] = $new_user_id->get_error_message();
434
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $data[0] );
435
  $created = false;
436
  }
437
  elseif( $new_user_id == $user_id)
440
  $user_id = $new_user_id;
441
  $new_user = get_user_by( 'id', $new_user_id );
442
  $data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
443
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $data[0], 'warning' );
444
  $created = true;
445
  }
446
  }
453
  $user_id = $user_object->ID;
454
 
455
  $data[0] = sprintf( __( 'User already exists as: %s (in this CSV file is called: %s)', 'import-users-from-csv-with-meta' ), $user_object->user_login, $username );
456
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $data[0], 'warning' );
457
 
458
  if( $password !== "" && $update_allow_update_passwords == 'yes' ){
459
  wp_set_password( $password, $user_id );
483
  }
484
 
485
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
486
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, sprintf( __( 'Problems with user: "%s" does not exists, error: %s', 'import-users-from-csv-with-meta' ), $username, $user_id->get_error_message() ) );
487
  continue;
488
  }
489
 
537
  else
538
  $data[0] = __('Invalid roles','import-users-from-csv-with-meta').' (' . implode( ', ', $invalid_roles ) . ')';
539
 
540
+ $errors[] = $acui_helper->new_error( $row, $errors_totals, $data[0], 'warning' );
541
  }
542
  }
543
  }
647
 
648
  $acui_helper->print_errors( $errors );
649
 
 
 
650
  // let the filter of default WordPress emails as it were before deactivating them
651
  if( !get_option('acui_automatic_wordpress_email') ){
652
  remove_filter( 'send_email_change_email', function() { return false; }, 999 );
683
  $change_role_not_present_role = get_option( "acui_frontend_change_role_not_present_role");
684
  }
685
 
686
+ if( $errors_totals['errors'] > 0 || $errors_totals['warnings'] > 0 ){ // if there is some problem of some kind importing we won't proceed with delete or changing role to users not present to avoid problems
687
  $delete_users_flag = false;
688
  $change_role_not_present_flag = false;
689
  }
713
  $all_users_ids = array_map( function( $element ){ return intval( $element->ID ); }, $all_users );
714
  $users_to_remove = array_diff( $all_users_ids, $users_registered );
715
 
716
+ $delete_users_assign_posts = ( get_userdata( $delete_users_assign_posts ) === false ) ? false : $delete_users_assign_posts;
717
+ $results['deleted'] = count( $users_to_remove );
718
 
719
  foreach ( $users_to_remove as $user_id ) {
720
  ( empty( $delete_users_assign_posts ) ) ? wp_delete_user( $user_id ) : wp_delete_user( $user_id, $delete_users_assign_posts );
735
  $user_object->set_role( $change_role_not_present_role );
736
  }
737
  }
738
+ endif;
739
 
740
+ $acui_helper->print_results( $results, $errors );
 
 
 
741
 
742
+ if( !$is_frontend )
743
+ $acui_helper->print_end_of_process();
744
+
745
  if( !$is_frontend && !$is_cron )
746
  $acui_helper->execute_datatable();
747
 
748
+ @ini_set( 'auto_detect_line_endings', FALSE );
749
 
750
  do_action( 'after_acui_import_users' );
751
  ?>
import-users-from-csv-with-meta.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Import and export users and customers
4
  Plugin URI: https://www.codection.com
5
  Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
6
- Version: 1.18.3
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
@@ -14,7 +14,7 @@ Domain Path: /languages
14
  if ( ! defined( 'ABSPATH' ) )
15
  exit;
16
 
17
- define( 'ACUI_VERSION', '1.18.3' );
18
 
19
  class ImportExportUsersCustomers{
20
  var $file;
3
  Plugin Name: Import and export users and customers
4
  Plugin URI: https://www.codection.com
5
  Description: Using this plugin you will be able to import and export users or customers choosing many options and interacting with lots of other plugins
6
+ Version: 1.18.4
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
14
  if ( ! defined( 'ABSPATH' ) )
15
  exit;
16
 
17
+ define( 'ACUI_VERSION', '1.18.4' );
18
 
19
  class ImportExportUsersCustomers{
20
  var $file;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://codection.com/go/donate-import-users-from-csv-with-meta/
4
  Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
5
  Requires at least: 3.4
6
  Tested up to: 5.8.1
7
- Stable tag: 1.18.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -103,6 +103,9 @@ Plugin will automatically detect:
103
 
104
  == Changelog ==
105
 
 
 
 
106
  = 1.18.3 =
107
  * Problem solved converting data that has a format date but that is not wanted to be converted, to timestamps when exporting
108
  * Fixed problems in standard import, in very big databases, there was a problem creating the list of users to assign deleted posts, now this list is created and managed using select2 and AJAX to improve performance and usability
4
  Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
5
  Requires at least: 3.4
6
  Tested up to: 5.8.1
7
+ Stable tag: 1.18.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.18.4 =
107
+ * Improved problem when deleting users, if errors happens but they are notices, we can delete now. Many of the users who have problems with deleting users not present in CSV, was created by the old conditional that checked any kind of error (including notices).
108
+
109
  = 1.18.3 =
110
  * Problem solved converting data that has a format date but that is not wanted to be converted, to timestamps when exporting
111
  * Fixed problems in standard import, in very big databases, there was a problem creating the list of users to assign deleted posts, now this list is created and managed using select2 and AJAX to improve performance and usability