Import users from CSV with meta - Version 1.20

Version Description

  • New settings API in plugin
  • Settings API working in backend import (in other tabs it will be working in next versions)
  • Fixed a mispelling in texts
  • New hook to manage if a email is sent to an user (https://wordpress.org/support/topic/stop-sending-mail-for-a-specific-role/#post-15932034)
Download this release

Release Info

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

Code changes from version 1.19.3.1 to 1.20

classes/frontend.php CHANGED
@@ -400,7 +400,7 @@ class ACUI_Frontend{
400
  $form_data["update_roles_existing_users"] = empty( get_option( "acui_frontend_update_roles_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_roles_existing_users" );
401
 
402
  // delete
403
- $form_data["delete_users"] = ( get_option( "acui_frontend_delete_users" ) ) ? 'yes' : 'no';
404
  $form_data["delete_users_assign_posts"] = get_option( "acui_frontend_delete_users_assign_posts" );
405
  $form_data["delete_users_only_specified_role"] = empty( $form_data[ "role" ] ) ? false : $atts['delete-only-specified-role'];
406
 
400
  $form_data["update_roles_existing_users"] = empty( get_option( "acui_frontend_update_roles_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_roles_existing_users" );
401
 
402
  // delete
403
+ $form_data["delete_users_not_present"] = ( get_option( "acui_frontend_delete_users" ) ) ? 'yes' : 'no';
404
  $form_data["delete_users_assign_posts"] = get_option( "acui_frontend_delete_users_assign_posts" );
405
  $form_data["delete_users_only_specified_role"] = empty( $form_data[ "role" ] ) ? false : $atts['delete-only-specified-role'];
406
 
classes/help.php CHANGED
@@ -10,7 +10,7 @@ class ACUI_Help{
10
 
11
  <div class="inside" style="display: block;">
12
  <p><?php _e( 'Hi! we are', 'import-users-from-csv-with-meta' ); ?> <a href="https://twitter.com/fjcarazo" target="_blank" title="Javier Carazo">Javier Carazo</a> <?php _e( 'and the team of', 'import-users-from-csv-with-meta' ) ?> <a href="http://codection.com">Codection</a>, <?php _e( 'developers of this plugin.', 'import-users-from-csv-with-meta' ); ?></p>
13
- <p><?php _e( 'We work everyday with WordPress and WooCommerce, if you need proffessional help, hire us. You can send us a message to', 'import-users-from-csv-with-meta' ); ?> <a href="mailto:contacto@codection.com">contacto@codection.com</a>.</p>
14
  <div style="clear:both;"></div>
15
  </div>
16
  </div>
10
 
11
  <div class="inside" style="display: block;">
12
  <p><?php _e( 'Hi! we are', 'import-users-from-csv-with-meta' ); ?> <a href="https://twitter.com/fjcarazo" target="_blank" title="Javier Carazo">Javier Carazo</a> <?php _e( 'and the team of', 'import-users-from-csv-with-meta' ) ?> <a href="http://codection.com">Codection</a>, <?php _e( 'developers of this plugin.', 'import-users-from-csv-with-meta' ); ?></p>
13
+ <p><?php _e( 'We work daily with WordPress and WooCommerce if you need professional help, hire us. You can send us a message at', 'import-users-from-csv-with-meta' ); ?> <a href="mailto:contacto@codection.com">contacto@codection.com</a>.</p>
14
  <div style="clear:both;"></div>
15
  </div>
16
  </div>
classes/helper.php CHANGED
@@ -467,4 +467,34 @@ class ACUI_Helper{
467
  $user_meta = get_user_meta( $user_id, $meta_key, true );
468
  return is_array( $user_meta ) ? var_export( $user_meta, true ) : $user_meta;
469
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
470
  }
467
  $user_meta = get_user_meta( $user_id, $meta_key, true );
468
  return is_array( $user_meta ) ? var_export( $user_meta, true ) : $user_meta;
469
  }
470
+
471
+ // notices
472
+ static function get_notices(){
473
+ $notices = get_transient( 'acui_notices' );
474
+ delete_transient( 'acui_notices' );
475
+ return is_array( $notices ) ? $notices : array();
476
+ }
477
+
478
+ static function add_notice( $notice ){
479
+ $notices = self::get_notices();
480
+ $notices[] = $notice;
481
+ set_transient( 'acui_notices', $notices, 120 );
482
+ }
483
+
484
+ function get_notice(){
485
+ $notices = self::get_notices();
486
+
487
+ if( count( $notices ) == 0 )
488
+ return false;
489
+
490
+ $return = '';
491
+ foreach( $notices as $key => $notice ){
492
+ $return = $notice;
493
+ unset( $notices[ $key ] );
494
+ set_transient( 'acui_notices', $notices );
495
+ return $return;
496
+ }
497
+
498
+ return false;
499
+ }
500
  }
classes/homepage.php CHANGED
@@ -23,7 +23,19 @@ class ACUI_Homepage{
23
  }
24
 
25
  static function admin_gui(){
26
- $last_roles_used = empty( get_option( 'acui_last_roles_used' ) ) ? array( 'subscriber' ) : get_option( 'acui_last_roles_used' );
 
 
 
 
 
 
 
 
 
 
 
 
27
  ?>
28
  <div class="wrap acui">
29
 
@@ -54,7 +66,7 @@ class ACUI_Homepage{
54
  <?php _e( '<em>or you can choose directly a file from your host,', 'import-users-from-csv-with-meta' ) ?> <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ) ?></a>.</em>
55
  </div>
56
  <div id="introduce_path" style="display:none;">
57
- <input placeholder="<?php _e( 'You have to introduce the path to file, i.e.:' ,'import-users-from-csv-with-meta' ); ?><?php $upload_dir = wp_upload_dir(); echo $upload_dir["path"]; ?>/test.csv" type="text" name="path_to_file" id="path_to_file" value="<?php echo ACUI_Options::get( 'path_to_file' ); ?>" style="width:70%;" />
58
  <em><?php _e( 'or you can upload it directly from your PC', 'import-users-from-csv-with-meta' ); ?>, <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ); ?></a>.</em>
59
  </div>
60
  </td>
@@ -76,7 +88,7 @@ class ACUI_Homepage{
76
  <td>
77
  <?php
78
  foreach ( ACUI_Helper::get_editable_roles() as $key => $value )
79
- ACUIHTML()->checkbox( array( 'label' => translate_user_role( $value ), 'name' => 'role[]', 'compare_value' => $last_roles_used, 'current' => $key, 'array' => true, 'class' => 'roles' ) );
80
  ?>
81
  <p class="description"><?php _e( 'You can also import roles from a CSV column. Please read documentation tab to see how it can be done. If you choose more than one role, the roles would be assigned correctly but you should use some plugin like <a href="https://wordpress.org/plugins/user-role-editor/">User Role Editor</a> to manage them.', 'import-users-from-csv-with-meta' ); ?></p>
82
  </td>
@@ -101,6 +113,7 @@ class ACUI_Homepage{
101
  'name' => 'empty_cell_action',
102
  'show_option_all' => false,
103
  'show_option_none' => false,
 
104
  )); ?>
105
  </td>
106
  </tr>
@@ -109,10 +122,10 @@ class ACUI_Homepage{
109
  <th scope="row"><label for="user_login"><?php _e( 'Send mail', 'import-users-from-csv-with-meta' ); ?></label></th>
110
  <td>
111
  <p id="sends_email_wrapper">
112
- <?php ACUIHTML()->checkbox( array( 'name' => 'sends_email', 'label' => __( 'Do you wish to send a mail from this plugin with credentials and other data? <a href="' . admin_url( 'tools.php?page=acui&tab=mail-options' ) . '">(email template found here)</a>', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => get_option( 'acui_manually_send_mail' ) ) ); ?>
113
  </p>
114
  <p id="send_email_updated_wrapper">
115
- <?php ACUIHTML()->checkbox( array( 'name' => 'send_email_updated', 'label' => __( 'Do you wish to send this mail also to users that are being updated? (not only to the one which are being created)', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => get_option( 'acui_manually_send_mail_updated' ) ) ); ?>
116
  </p>
117
  </td>
118
  </tr>
@@ -120,7 +133,7 @@ class ACUI_Homepage{
120
  <tr class="form-field form-required">
121
  <th scope="row"><label for=""><?php _e( 'Force users to reset their passwords?', 'import-users-from-csv-with-meta' ); ?></label></th>
122
  <td>
123
- <?php ACUIHTML()->checkbox( array( 'name' => 'force_user_reset_password', 'label' => __( 'If a password is set to an user and you activate this option, the user will be forced to reset their password in their first login', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => get_option( 'acui_manually_force_user_reset_password' ) ) ); ?>
124
  </td>
125
  </tr>
126
 
@@ -144,6 +157,7 @@ class ACUI_Homepage{
144
  'name' => 'update_existing_users',
145
  'show_option_all' => false,
146
  'show_option_none' => false,
 
147
  )); ?>
148
  </td>
149
  </tr>
@@ -156,6 +170,7 @@ class ACUI_Homepage{
156
  'name' => 'update_emails_existing_users',
157
  'show_option_all' => false,
158
  'show_option_none' => false,
 
159
  )); ?>
160
  <p class="description"><?php _e( 'What the plugin should do if the plugin find an user, identified by their username, with a different email', 'import-users-from-csv-with-meta' ); ?></p>
161
  </td>
@@ -169,6 +184,7 @@ class ACUI_Homepage{
169
  'name' => 'update_roles_existing_users',
170
  'show_option_all' => false,
171
  'show_option_none' => false,
 
172
  )); ?>
173
  </td>
174
  </tr>
@@ -181,6 +197,7 @@ class ACUI_Homepage{
181
  'name' => 'update_allow_update_passwords',
182
  'show_option_all' => false,
183
  'show_option_none' => false,
 
184
  )); ?>
185
  </td>
186
  </tr>
@@ -198,17 +215,18 @@ class ACUI_Homepage{
198
  <?php do_action( 'acui_homepage_before_users_not_present_rows' ); ?>
199
 
200
  <tr id="acui_delete_users_wrapper" class="form-field form-required">
201
- <th scope="row"><label for="delete_users"><?php _e( 'Delete users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
202
  <td>
203
  <div style="float:left; margin-top: 10px;">
204
- <?php ACUIHTML()->checkbox( array( 'name' => 'delete_users', 'current' => 'yes' ) ); ?>
205
  </div>
206
  <div style="margin-left:25px;">
207
  <?php ACUIHTML()->select( array(
208
- 'options' => array( 'no' => __( 'Never update passwords when updating a user', 'import-users-from-csv-with-meta' ), 'yes_no_override' => __( 'Yes, add new roles and not override existing ones', 'import-users-from-csv-with-meta' ) ),
209
  'name' => 'delete_users_assign_posts',
210
  'show_option_all' => false,
211
  'show_option_none' => __( 'Delete posts of deleted users without assigning to any user or type to search a user', 'import-users-from-csv-with-meta' ),
 
212
  )); ?>
213
  <p class="description"><?php _e( 'Administrators will not be deleted anyway. After delete users, we can choose if we want to assign their posts to another user. If you do not choose some user, content will be deleted.', 'import-users-from-csv-with-meta' ); ?></p>
214
  </div>
@@ -219,7 +237,7 @@ class ACUI_Homepage{
219
  <th scope="row"><label for="change_role_not_present"><?php _e( 'Change role of users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
220
  <td>
221
  <div style="float:left; margin-top: 10px;">
222
- <?php ACUIHTML()->checkbox( array( 'name' => 'change_role_not_present', 'current' => 'yes' ) ); ?>
223
  </div>
224
  <div style="margin-left:25px;">
225
  <?php ACUIHTML()->select( array(
@@ -227,6 +245,7 @@ class ACUI_Homepage{
227
  'name' => 'change_role_not_present_role',
228
  'show_option_all' => false,
229
  'show_option_none' => false,
 
230
  )); ?>
231
  <p class="description"><?php _e( 'After import users which is not present in the CSV and can be changed to a different role.', 'import-users-from-csv-with-meta' ); ?></p>
232
  </div>
@@ -318,7 +337,7 @@ class ACUI_Homepage{
318
  $( '.acui-checkbox.roles[value="no_role"]' ).removeAttr( 'checked' );
319
  } );
320
 
321
- $( '#delete_users' ).on( 'click', function() {
322
  check_delete_users_checked();
323
  });
324
 
@@ -382,7 +401,7 @@ class ACUI_Homepage{
382
  allowClear: true,
383
  placeholder: { id: '', title: '<?php _e( 'Delete posts of deleted users without assigning to any user', 'import-users-from-csv-with-meta' ) ?>' },
384
  data: function( params ) {
385
- if (params.term.trim().length < 3)
386
  throw false;
387
 
388
  var query = {
@@ -393,11 +412,11 @@ class ACUI_Homepage{
393
 
394
  return query;
395
  }
396
- }
397
  });
398
 
399
  function check_delete_users_checked(){
400
- if( $( '#delete_users' ).is( ':checked' ) ){
401
  $( '#delete_users_assign_posts' ).prop( 'disabled', false );
402
  $( '#change_role_not_present' ).prop( 'disabled', true );
403
  $( '#change_role_not_present_role' ).prop( 'disabled', true );
23
  }
24
 
25
  static function admin_gui(){
26
+ $settings = new ACUI_Settings( 'import_backend' );
27
+ $settings->maybe_migrate_old_options( 'import_backend' );
28
+
29
+ if( is_int( $settings->get( 'delete_users_assign_posts' ) ) ){
30
+ $delete_users_assign_posts_user = get_user_by( 'id', $settings->get( 'delete_users_assign_posts' ) );
31
+ $delete_users_assign_posts_options = array( $settings->get( 'delete_users_assign_posts' ) => $delete_users_assign_posts_user->display_name );
32
+ $delete_users_assign_posts_option_selected = $settings->get( 'delete_users_assign_posts' );
33
+ }
34
+ else{
35
+ $delete_users_assign_posts_options = array( 0 => __( 'No user selected', 'import-users-from-csv-with-meta' ) );
36
+ $delete_users_assign_posts_option_selected = 0;
37
+ }
38
+
39
  ?>
40
  <div class="wrap acui">
41
 
66
  <?php _e( '<em>or you can choose directly a file from your host,', 'import-users-from-csv-with-meta' ) ?> <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ) ?></a>.</em>
67
  </div>
68
  <div id="introduce_path" style="display:none;">
69
+ <input placeholder="<?php _e( 'You have to introduce the path to file, i.e.:' ,'import-users-from-csv-with-meta' ); ?><?php $upload_dir = wp_upload_dir(); echo $upload_dir["path"]; ?>/test.csv" type="text" name="path_to_file" id="path_to_file" value="<?php echo $settings->get( 'path_to_file' ); ?>" style="width:70%;" />
70
  <em><?php _e( 'or you can upload it directly from your PC', 'import-users-from-csv-with-meta' ); ?>, <a href="#" class="toggle_upload_path"><?php _e( 'click here', 'import-users-from-csv-with-meta' ); ?></a>.</em>
71
  </div>
72
  </td>
88
  <td>
89
  <?php
90
  foreach ( ACUI_Helper::get_editable_roles() as $key => $value )
91
+ ACUIHTML()->checkbox( array( 'label' => translate_user_role( $value ), 'name' => 'role[]', 'compare_value' => $settings->get( 'role' ), 'current' => $key, 'array' => true, 'class' => 'roles' ) );
92
  ?>
93
  <p class="description"><?php _e( 'You can also import roles from a CSV column. Please read documentation tab to see how it can be done. If you choose more than one role, the roles would be assigned correctly but you should use some plugin like <a href="https://wordpress.org/plugins/user-role-editor/">User Role Editor</a> to manage them.', 'import-users-from-csv-with-meta' ); ?></p>
94
  </td>
113
  'name' => 'empty_cell_action',
114
  'show_option_all' => false,
115
  'show_option_none' => false,
116
+ 'selected' => $settings->get( 'empty_cell_action' ),
117
  )); ?>
118
  </td>
119
  </tr>
122
  <th scope="row"><label for="user_login"><?php _e( 'Send mail', 'import-users-from-csv-with-meta' ); ?></label></th>
123
  <td>
124
  <p id="sends_email_wrapper">
125
+ <?php ACUIHTML()->checkbox( array( 'name' => 'sends_email', 'label' => __( 'Do you wish to send a mail from this plugin with credentials and other data? <a href="' . admin_url( 'tools.php?page=acui&tab=mail-options' ) . '">(email template found here)</a>', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => $settings->get( 'sends_email' ) ) ); ?>
126
  </p>
127
  <p id="send_email_updated_wrapper">
128
+ <?php ACUIHTML()->checkbox( array( 'name' => 'send_email_updated', 'label' => __( 'Do you wish to send this mail also to users that are being updated? (not only to the one which are being created)', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => $settings->get( 'send_email_updated' ) ) ); ?>
129
  </p>
130
  </td>
131
  </tr>
133
  <tr class="form-field form-required">
134
  <th scope="row"><label for=""><?php _e( 'Force users to reset their passwords?', 'import-users-from-csv-with-meta' ); ?></label></th>
135
  <td>
136
+ <?php ACUIHTML()->checkbox( array( 'name' => 'force_user_reset_password', 'label' => __( 'If a password is set to an user and you activate this option, the user will be forced to reset their password in their first login', 'import-users-from-csv-with-meta' ), 'current' => 'yes', 'compare_value' => $settings->get( 'force_user_reset_password' ) ) ); ?>
137
  </td>
138
  </tr>
139
 
157
  'name' => 'update_existing_users',
158
  'show_option_all' => false,
159
  'show_option_none' => false,
160
+ 'selected' => $settings->get( 'update_existing_users' ),
161
  )); ?>
162
  </td>
163
  </tr>
170
  'name' => 'update_emails_existing_users',
171
  'show_option_all' => false,
172
  'show_option_none' => false,
173
+ 'selected' => $settings->get( 'update_emails_existing_users' ),
174
  )); ?>
175
  <p class="description"><?php _e( 'What the plugin should do if the plugin find an user, identified by their username, with a different email', 'import-users-from-csv-with-meta' ); ?></p>
176
  </td>
184
  'name' => 'update_roles_existing_users',
185
  'show_option_all' => false,
186
  'show_option_none' => false,
187
+ 'selected' => $settings->get( 'update_roles_existing_users' ),
188
  )); ?>
189
  </td>
190
  </tr>
197
  'name' => 'update_allow_update_passwords',
198
  'show_option_all' => false,
199
  'show_option_none' => false,
200
+ 'selected' => $settings->get( 'update_allow_update_passwords' ),
201
  )); ?>
202
  </td>
203
  </tr>
215
  <?php do_action( 'acui_homepage_before_users_not_present_rows' ); ?>
216
 
217
  <tr id="acui_delete_users_wrapper" class="form-field form-required">
218
+ <th scope="row"><label for="delete_users_not_present"><?php _e( 'Delete users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
219
  <td>
220
  <div style="float:left; margin-top: 10px;">
221
+ <?php ACUIHTML()->checkbox( array( 'name' => 'delete_users_not_present', 'current' => 'yes', 'compare_value' => $settings->get( 'delete_users_not_present' ) ) ); ?>
222
  </div>
223
  <div style="margin-left:25px;">
224
  <?php ACUIHTML()->select( array(
225
+ 'options' => $delete_users_assign_posts_options,
226
  'name' => 'delete_users_assign_posts',
227
  'show_option_all' => false,
228
  'show_option_none' => __( 'Delete posts of deleted users without assigning to any user or type to search a user', 'import-users-from-csv-with-meta' ),
229
+ 'selected' => $delete_users_assign_posts_option_selected,
230
  )); ?>
231
  <p class="description"><?php _e( 'Administrators will not be deleted anyway. After delete users, we can choose if we want to assign their posts to another user. If you do not choose some user, content will be deleted.', 'import-users-from-csv-with-meta' ); ?></p>
232
  </div>
237
  <th scope="row"><label for="change_role_not_present"><?php _e( 'Change role of users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
238
  <td>
239
  <div style="float:left; margin-top: 10px;">
240
+ <?php ACUIHTML()->checkbox( array( 'name' => 'change_role_not_present', 'current' => 'yes', 'compare_value' => $settings->get( 'change_role_not_present' ) ) ); ?>
241
  </div>
242
  <div style="margin-left:25px;">
243
  <?php ACUIHTML()->select( array(
245
  'name' => 'change_role_not_present_role',
246
  'show_option_all' => false,
247
  'show_option_none' => false,
248
+ 'selected' => $settings->get( 'change_role_not_present_role' ),
249
  )); ?>
250
  <p class="description"><?php _e( 'After import users which is not present in the CSV and can be changed to a different role.', 'import-users-from-csv-with-meta' ); ?></p>
251
  </div>
337
  $( '.acui-checkbox.roles[value="no_role"]' ).removeAttr( 'checked' );
338
  } );
339
 
340
+ $( '#delete_users_not_present' ).on( 'click', function() {
341
  check_delete_users_checked();
342
  });
343
 
401
  allowClear: true,
402
  placeholder: { id: '', title: '<?php _e( 'Delete posts of deleted users without assigning to any user', 'import-users-from-csv-with-meta' ) ?>' },
403
  data: function( params ) {
404
+ if( params.term.trim().length < 3 )
405
  throw false;
406
 
407
  var query = {
412
 
413
  return query;
414
  }
415
+ },
416
  });
417
 
418
  function check_delete_users_checked(){
419
+ if( $( '#delete_users_not_present' ).is( ':checked' ) ){
420
  $( '#delete_users_assign_posts' ).prop( 'disabled', false );
421
  $( '#change_role_not_present' ).prop( 'disabled', true );
422
  $( '#change_role_not_present_role' ).prop( 'disabled', true );
classes/html.php CHANGED
@@ -6,12 +6,6 @@ class ACUI_HTML{
6
  var $settings;
7
 
8
  function __construct(){
9
- $settings = array(
10
- 'common' => array(
11
- 'default_role',
12
-
13
- )
14
- );
15
  }
16
 
17
  private static function is_instantiated() {
6
  var $settings;
7
 
8
  function __construct(){
 
 
 
 
 
 
9
  }
10
 
11
  private static function is_instantiated() {
classes/import.php CHANGED
@@ -20,13 +20,10 @@ class ACUI_Import{
20
 
21
  switch ( $tab ){
22
  case 'homepage':
23
- ACUI_Options::update( 'last_roles_used', ( empty( $_POST['role'] ) ? '' : array_map( 'sanitize_text_field', $_POST['role'] ) ) );
24
- ACUI_Options::update( 'path_to_file', sanitize_text_field( $_POST['path_to_file'] ) );
25
- ACUI_Options::save_options( $_POST );
26
 
27
  if( isset( $_POST['uploadfile'] ) && !empty( $_POST['uploadfile'] ) )
28
  $this->fileupload_process( $_POST, false );
29
- return;
30
  break;
31
 
32
  case 'frontend':
@@ -49,6 +46,7 @@ class ACUI_Import{
49
 
50
  $this->admin_tabs( $tab );
51
  $this->secondary_admin_tabs( $tab, $section, $sections );
 
52
 
53
  switch ( $tab ){
54
  case 'homepage' :
@@ -190,6 +188,17 @@ class ACUI_Import{
190
  }
191
  }
192
 
 
 
 
 
 
 
 
 
 
 
 
193
  function fileupload_process( $form_data, $is_cron = false, $is_frontend = false ) {
194
  if ( !defined( 'DOING_CRON' ) && ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) ){
195
  wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
@@ -251,7 +260,7 @@ class ACUI_Import{
251
  $update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? sanitize_text_field( $form_data["update_roles_existing_users"] ) : 'no';
252
  $update_allow_update_passwords = isset( $form_data["update_allow_update_passwords"] ) ? sanitize_text_field( $form_data["update_allow_update_passwords"] ) : 'yes';
253
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
254
- $delete_users = isset( $form_data["delete_users"] ) ? sanitize_text_field( $form_data["delete_users"] ) : '';
255
  $delete_users_assign_posts = isset( $form_data["delete_users_assign_posts"] ) ? sanitize_text_field( $form_data["delete_users_assign_posts"] ) : '';
256
  $delete_users_only_specified_role = isset( $form_data["delete_users_only_specified_role"] ) ? sanitize_text_field( $form_data["delete_users_only_specified_role"] ) : false;
257
 
@@ -706,6 +715,8 @@ class ACUI_Import{
706
  }
707
 
708
  // send mail
 
 
709
  if( isset( $mail_for_this_user ) && $mail_for_this_user ){
710
  if( !$created && $update_allow_update_passwords == 'no' )
711
  $password = __( 'Password has not been changed', 'import-users-from-csv-with-meta' );
@@ -736,7 +747,7 @@ class ACUI_Import{
736
  $delete_users_flag = false;
737
  $change_role_not_present_flag = false;
738
 
739
- if( $delete_users == 'yes' ){
740
  $delete_users_flag = true;
741
  }
742
 
20
 
21
  switch ( $tab ){
22
  case 'homepage':
23
+ ACUISettings()->save_multiple( 'import_backend', $_POST );
 
 
24
 
25
  if( isset( $_POST['uploadfile'] ) && !empty( $_POST['uploadfile'] ) )
26
  $this->fileupload_process( $_POST, false );
 
27
  break;
28
 
29
  case 'frontend':
46
 
47
  $this->admin_tabs( $tab );
48
  $this->secondary_admin_tabs( $tab, $section, $sections );
49
+ $this->show_notices();
50
 
51
  switch ( $tab ){
52
  case 'homepage' :
188
  }
189
  }
190
 
191
+ function show_notices(){
192
+ $notices = ACUI_Helper::get_notices();
193
+ foreach( $notices as $notice ){
194
+ ?>
195
+ <div class="notice notice-success">
196
+ <p><strong><?php echo $notice; ?></strong></p>
197
+ </div>
198
+ <?php
199
+ }
200
+ }
201
+
202
  function fileupload_process( $form_data, $is_cron = false, $is_frontend = false ) {
203
  if ( !defined( 'DOING_CRON' ) && ( !isset( $form_data['security'] ) || !wp_verify_nonce( $form_data['security'], 'codection-security' ) ) ){
204
  wp_die( __( 'Nonce check failed', 'import-users-from-csv-with-meta' ) );
260
  $update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? sanitize_text_field( $form_data["update_roles_existing_users"] ) : 'no';
261
  $update_allow_update_passwords = isset( $form_data["update_allow_update_passwords"] ) ? sanitize_text_field( $form_data["update_allow_update_passwords"] ) : 'yes';
262
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
263
+ $delete_users_not_present = isset( $form_data["delete_users_not_present"] ) ? sanitize_text_field( $form_data["delete_users_not_present"] ) : '';
264
  $delete_users_assign_posts = isset( $form_data["delete_users_assign_posts"] ) ? sanitize_text_field( $form_data["delete_users_assign_posts"] ) : '';
265
  $delete_users_only_specified_role = isset( $form_data["delete_users_only_specified_role"] ) ? sanitize_text_field( $form_data["delete_users_only_specified_role"] ) : false;
266
 
715
  }
716
 
717
  // send mail
718
+ $mail_for_this_user = apply_filters( 'acui_send_email_for_user', $mail_for_this_user, $headers, $data, $user_id, $role, $positions, $form_data, $is_frontend, $is_cron, $password_changed );
719
+
720
  if( isset( $mail_for_this_user ) && $mail_for_this_user ){
721
  if( !$created && $update_allow_update_passwords == 'no' )
722
  $password = __( 'Password has not been changed', 'import-users-from-csv-with-meta' );
747
  $delete_users_flag = false;
748
  $change_role_not_present_flag = false;
749
 
750
+ if( $delete_users_not_present == 'yes' ){
751
  $delete_users_flag = true;
752
  }
753
 
classes/options.php CHANGED
@@ -6,12 +6,6 @@ class ACUI_Options{
6
  static function get_default_list(){
7
  return array(
8
  self::$prefix . 'columns' => array(),
9
- // homepage
10
- self::$prefix . 'last_roles_used' => array(),
11
- self::$prefix . 'path_to_file' => dirname( __FILE__ ) . '/test.csv',
12
- self::$prefix . 'manually_send_mail' => false,
13
- self::$prefix . 'manually_send_mail_updated' => false,
14
- self::$prefix . 'manually_force_user_reset_password' => false,
15
  // emails
16
  self::$prefix . 'mail_subject' => __('Welcome to', 'import-users-from-csv-with-meta') . ' ' . get_bloginfo("name"),
17
  self::$prefix . 'mail_body' => __('Welcome,', 'import-users-from-csv-with-meta') . '<br/>' . __('Your data to login in this site is:', 'import-users-from-csv-with-meta') . '<br/><ul><li>' . __('URL to login', 'import-users-from-csv-with-meta') . ': **loginurl**</li><li>' . __( 'Username', 'import-users-from-csv-with-meta') . '= **username**</li><li>Password = **password**</li></ul>',
@@ -80,12 +74,7 @@ class ACUI_Options{
80
  }
81
 
82
  static function save_options( $form_data, $is_cron = false, $is_frontend = false ){
83
- if( !$is_frontend && !$is_cron ){
84
- update_option( "acui_manually_send_mail", isset( $form_data["sends_email"] ) && $form_data["sends_email"] == 'yes' );
85
- update_option( "acui_manually_send_mail_updated", isset( $form_data["send_email_updated"] ) && $form_data["send_email_updated"] == 'yes' );
86
- update_option( "acui_manually_force_user_reset_password", isset( $form_data["force_user_reset_password"] ) && $form_data["force_user_reset_password"] == 'yes' );
87
- }
88
- elseif( $is_frontend ){
89
  $form_data["send_mail_admin_frontend_address_list"] = isset( $form_data["send_mail_admin_frontend_address_list"] ) ? $form_data["send_mail_admin_frontend_address_list"] : '';
90
 
91
  update_option( "acui_frontend_send_mail", isset( $form_data["send-mail-frontend"] ) && $form_data["send-mail-frontend"] == "1" );
6
  static function get_default_list(){
7
  return array(
8
  self::$prefix . 'columns' => array(),
 
 
 
 
 
 
9
  // emails
10
  self::$prefix . 'mail_subject' => __('Welcome to', 'import-users-from-csv-with-meta') . ' ' . get_bloginfo("name"),
11
  self::$prefix . 'mail_body' => __('Welcome,', 'import-users-from-csv-with-meta') . '<br/>' . __('Your data to login in this site is:', 'import-users-from-csv-with-meta') . '<br/><ul><li>' . __('URL to login', 'import-users-from-csv-with-meta') . ': **loginurl**</li><li>' . __( 'Username', 'import-users-from-csv-with-meta') . '= **username**</li><li>Password = **password**</li></ul>',
74
  }
75
 
76
  static function save_options( $form_data, $is_cron = false, $is_frontend = false ){
77
+ if( $is_frontend ){
 
 
 
 
 
78
  $form_data["send_mail_admin_frontend_address_list"] = isset( $form_data["send_mail_admin_frontend_address_list"] ) ? $form_data["send_mail_admin_frontend_address_list"] : '';
79
 
80
  update_option( "acui_frontend_send_mail", isset( $form_data["send-mail-frontend"] ) && $form_data["send-mail-frontend"] == "1" );
classes/settings.php CHANGED
@@ -2,14 +2,250 @@
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  class ACUI_Settings{
 
5
  var $settings;
 
 
 
6
 
7
- function __construct(){
8
- $settings = array(
9
- 'common' => array(
10
- 'default_role',
11
-
12
- )
13
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  }
 
 
 
 
 
 
 
 
 
 
15
  }
2
  if ( ! defined( 'ABSPATH' ) ) exit;
3
 
4
  class ACUI_Settings{
5
+ private static $instance;
6
  var $settings;
7
+ var $key;
8
+ var $contexts;
9
+ var $current_context;
10
 
11
+ function __construct( $current_context = '' ){
12
+ $this->settings = apply_filters( 'acui_settings', array(
13
+ 'import_common' => array(
14
+ 'path_to_file' => array(
15
+ 'sanitization' => 'text',
16
+ 'default' => ''
17
+ ),
18
+ 'role' => array(
19
+ 'sanitization' => 'array_text',
20
+ 'default' => array( 'subscriber' )
21
+ ),
22
+ 'empty_cell_action' => array(
23
+ 'sanitization' => 'text',
24
+ 'default' => 'leave'
25
+ ),
26
+ 'sends_email' => array(
27
+ 'sanitization' => 'checkbox',
28
+ 'value' => 'no',
29
+ ),
30
+ 'send_email_updated' => array(
31
+ 'sanitization' => 'checkbox',
32
+ 'value' => 'no',
33
+ ),
34
+ 'update_existing_users' => array(
35
+ 'sanitization' => 'checkbox',
36
+ 'default' => 'no'
37
+ ),
38
+ 'force_user_reset_password' => array(
39
+ 'sanitization' => 'checkbox',
40
+ 'default' => 'no'
41
+ ),
42
+ 'update_emails_existing_users' => array(
43
+ 'sanitization' => 'text',
44
+ 'default' => 'no'
45
+ ),
46
+ 'update_roles_existing_users' => array(
47
+ 'sanitization' => 'text',
48
+ 'default' => 'no'
49
+ ),
50
+ 'update_allow_update_passwords' => array(
51
+ 'sanitization' => 'text',
52
+ 'default' => 'no'
53
+ ),
54
+ 'delete_users_not_present' => array(
55
+ 'sanitization' => 'checkbox',
56
+ 'value' => 'no',
57
+ ),
58
+ 'delete_users_assign_posts' => array(
59
+ 'sanitization' => 'text',
60
+ 'default' => '0'
61
+ ),
62
+ 'change_role_not_present' => array(
63
+ 'sanitization' => 'checkbox',
64
+ 'value' => 'no',
65
+ ),
66
+ 'change_role_not_present_role' => array(
67
+ 'sanitization' => 'text',
68
+ 'default' => 'subscriber'
69
+ ),
70
+ ),
71
+ 'import_backend' => array(),
72
+ 'import_frontend' => array(),
73
+ 'import_cron' => array(),
74
+ 'export_common' => array(),
75
+ 'export_backend' => array(),
76
+ ));
77
+
78
+ $this->key = 'acui_settings';
79
+ $this->contexts = apply_filters( 'acui_contexts', array( 'import_backend', 'import_frontend', 'import_cron', 'export_backend') );
80
+ $this->current_context = $current_context;
81
+
82
+ $this->initialize_settings();
83
+ }
84
+
85
+ private static function is_instantiated() {
86
+ if ( ! empty( self::$instance ) && ( self::$instance instanceof ACUI_Settings ) ) {
87
+ return true;
88
+ }
89
+
90
+ return false;
91
+ }
92
+
93
+ private static function setup_instance() {
94
+ self::$instance = new ACUI_Settings;
95
+ }
96
+
97
+ static function instance() {
98
+ if ( self::is_instantiated() ) {
99
+ return self::$instance;
100
+ }
101
+
102
+ self::setup_instance();
103
+
104
+ return self::$instance;
105
+ }
106
+
107
+ function initialize_settings(){
108
+ $options = get_option( $this->key );
109
+ if( !is_array( $options ) ){
110
+ $options = array();
111
+
112
+ foreach( $this->contexts as $context ){
113
+ $options[ $context ] = array();
114
+ }
115
+
116
+ update_option( $this->key, $options );
117
+ }
118
+ }
119
+
120
+ function get_settings_from_context( $context ){
121
+ switch( $context ){
122
+ case 'import_backend':
123
+ return array_merge( $this->settings['import_common'], $this->settings['import_backend'] );
124
+
125
+ case 'import_frontend':
126
+ return array_merge( $this->settings['import_common'], $this->settings['import_frontend'] );
127
+
128
+ case 'import_cron':
129
+ return array_merge( $this->settings['import_common'], $this->settings['import_cron'] );
130
+
131
+ case 'export_backend':
132
+ return array_merge( $this->settings['export_common'] );
133
+ }
134
+
135
+ return array();
136
+ }
137
+
138
+ function sanitize( $value, $sanitize_type ){
139
+ switch( $sanitize_type ){
140
+ case 'text':
141
+ return sanitize_text_field( $value );
142
+
143
+ case 'array_text':
144
+ return array_map( 'sanitize_text_field', $value );
145
+
146
+ case 'checkbox':
147
+ return ( $value != 'yes' ) ? 'no' : 'yes';
148
+ }
149
+ }
150
+
151
+ function save_multiple( $context, $data ){
152
+ $settings_to_save = $this->get_settings_from_context( $context );
153
+
154
+ $values = array();
155
+
156
+ foreach( $settings_to_save as $setting => $setting_options ){
157
+ $sanitize_type = $setting_options['sanitization'];
158
+ if( !isset( $data[ $setting ] ) && $sanitize_type != 'checkbox' )
159
+ continue;
160
+
161
+ $values[ $setting ] = isset( $data[ $setting ] ) ? $this->sanitize( $data[ $setting ], $sanitize_type ) : 'no';
162
+ }
163
+
164
+ $options = get_option( $this->key );
165
+ $options[ $context ] = $values;
166
+ update_option( $this->key, $options );
167
+ }
168
+
169
+ function save( $option, $value, $context = '' ){
170
+ $context = empty( $context ) ? $this->current_context : $context;
171
+ $settings = $this->get_settings_from_context( $context );
172
+ $options = get_option( $this->key );
173
+ $values = $options[ $context ];
174
+ $values[ $option ] = $this->sanitize( $value, $settings[ $option ]['sanitization'] );
175
+ $options[ $context ] = $values;
176
+ update_option( $this->key, $options );
177
+ }
178
+
179
+ function get( $option, $context = '' ){
180
+ $options = get_option( $this->key );
181
+ $context = empty( $context ) ? $this->current_context : $context;
182
+
183
+ if( !isset( $options[ $context ] ) || !is_array( $options[ $context ] ) )
184
+ return $this->default_option( $option, $context );
185
+
186
+ return isset( $options[ $context ][ $option ] ) ? $options[ $context ][ $option ] : $this->default_option( $option, $context );
187
+ }
188
+
189
+ function default_option( $option, $context = '' ){
190
+ $context = empty( $context ) ? $this->current_context : $context;
191
+ $settings = $this->get_settings_from_context( $context );
192
+
193
+ if( !isset( $settings[ $option ] ) )
194
+ return false;
195
+
196
+ if( !isset( $settings[ $option ]['default'] ) ){
197
+ switch( $settings[ $option ] ){
198
+ case 'text':
199
+ return '';
200
+
201
+ case 'array_text':
202
+ return array();
203
+
204
+ case 'checkbox':
205
+ return false;
206
+ }
207
+ }
208
+
209
+ return $settings[ $option ]['default'];
210
+ }
211
+
212
+ function maybe_migrate_old_options(){
213
+ switch( $this->current_context ){
214
+ case 'import_backend':
215
+ if ( get_option( 'acui_last_roles_used', 'not-exists' ) === 'not-exists' ){
216
+ return;
217
+ }
218
+
219
+ $last_roles_used = empty( get_option( 'acui_last_roles_used' ) ) ? array( 'subscriber' ) : get_option( 'acui_last_roles_used' );
220
+ delete_option( 'acui_last_roles_used' );
221
+ $this->save( 'role', $last_roles_used );
222
+
223
+ $path_to_file = empty( get_option( 'acui_path_to_file' ) ) ? dirname( __FILE__ ) . '/test.csv' : get_option( 'acui_path_to_file' );
224
+ delete_option( 'acui_path_to_file' );
225
+ $this->save( 'path_to_file', $path_to_file );
226
+
227
+ $manually_send_mail = get_option( 'acui_manually_send_mail' ) ? 'yes' : 'no';
228
+ delete_option( 'acui_manually_send_mail' );
229
+ $this->save( 'sends_email', $manually_send_mail );
230
+
231
+ $manually_send_mail_updated = get_option( 'acui_manually_send_mail_updated' ) ? 'yes' : 'no';
232
+ delete_option( 'acui_manually_send_mail_updated' );
233
+ $this->save( 'send_email_updated', $manually_send_mail_updated );
234
+
235
+ $manually_force_user_reset_password = get_option( 'acui_manually_force_user_reset_password' ) ? 'yes' : 'no';
236
+ delete_option( 'acui_manually_force_user_reset_password' );
237
+ $this->save( 'force_user_reset_password', $manually_force_user_reset_password );
238
+ break;
239
+ }
240
  }
241
+
242
+ function show_raw(){
243
+ echo "<pre>";
244
+ var_export( get_option( $this->key ) );
245
+ echo "</pre>";
246
+ }
247
+ }
248
+
249
+ function ACUISettings(){
250
+ return ACUI_Settings::instance();
251
  }
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.19.3.1
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.19.3.1' );
18
 
19
  class ImportExportUsersCustomers{
20
  var $file;
@@ -90,7 +90,6 @@ class ImportExportUsersCustomers{
90
  wp_enqueue_style( 'acui_css', plugins_url( 'assets/style.css', __FILE__ ), false, ACUI_VERSION );
91
  wp_enqueue_style( 'datatable', '//cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css' );
92
  wp_enqueue_script( 'datatable', '//cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js' );
93
- //wp_enqueue_script( 'datatable-select', '//cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js' );
94
 
95
  if( isset( $_GET['tab'] ) && $_GET['tab'] == 'export' ){
96
  ACUI_Exporter::enqueue();
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.20
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
14
  if ( ! defined( 'ABSPATH' ) )
15
  exit;
16
 
17
+ define( 'ACUI_VERSION', '1.20' );
18
 
19
  class ImportExportUsersCustomers{
20
  var $file;
90
  wp_enqueue_style( 'acui_css', plugins_url( 'assets/style.css', __FILE__ ), false, ACUI_VERSION );
91
  wp_enqueue_style( 'datatable', '//cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css' );
92
  wp_enqueue_script( 'datatable', '//cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js' );
 
93
 
94
  if( isset( $_GET['tab'] ) && $_GET['tab'] == 'export' ){
95
  ACUI_Exporter::enqueue();
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: carazo, hornero
3
  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: 6.0
7
- Stable tag: 1.19.3.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -107,8 +107,14 @@ Plugin will automatically detect:
107
 
108
  == Changelog ==
109
 
 
 
 
 
 
 
110
  = 1.19.3.1 =
111
- * Added a message when an email already exists in the system but is used by a different user than the one indicated in the CSV
112
  * Fixed error in documentation when WooCommerce Subscriptions was active
113
 
114
  = 1.19.3 =
3
  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: 6.0.1
7
+ Stable tag: 1.19.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
107
 
108
  == Changelog ==
109
 
110
+ = 1.20 =
111
+ * New settings API in plugin
112
+ * Settings API working in backend import (in other tabs it will be working in next versions)
113
+ * Fixed a mispelling in texts
114
+ * New hook to manage if a email is sent to an user (https://wordpress.org/support/topic/stop-sending-mail-for-a-specific-role/#post-15932034)
115
+
116
  = 1.19.3.1 =
117
+ * Added a message when an email already exists in the system but is used by a different user than the one indicated in the CSV
118
  * Fixed error in documentation when WooCommerce Subscriptions was active
119
 
120
  = 1.19.3 =