Import users from CSV with meta - Version 1.17.5.3

Version Description

  • You can now force the users to reset their passwords after login if you have changed the password in the import
  • Some code improvements
Download this release

Release Info

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

Code changes from version 1.17.5.2 to 1.17.5.3

addons/woocommerce.php CHANGED
@@ -15,6 +15,10 @@ class ACUI_WooCommerce{
15
  add_action( 'after_acui_import_users', array( $this, 'clear_transients' ) );
16
  add_filter( 'acui_import_email_body_before_wpautop', array( $this, 'include_overrides_email' ), 10, 5 );
17
  add_action( 'acui_email_wildcards_list_elements', array( $this, 'new_wildcards_email' ) );
 
 
 
 
18
  }
19
 
20
  function fields(){
@@ -118,6 +122,35 @@ class ACUI_WooCommerce{
118
  <li>**woocommercepasswordreseturllink** = <?php _e( 'WooCommerce password reset url with HTML link', 'import-users-from-csv-with-meta' ); ?>
119
  <?php
120
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
  new ACUI_WooCommerce();
15
  add_action( 'after_acui_import_users', array( $this, 'clear_transients' ) );
16
  add_filter( 'acui_import_email_body_before_wpautop', array( $this, 'include_overrides_email' ), 10, 5 );
17
  add_action( 'acui_email_wildcards_list_elements', array( $this, 'new_wildcards_email' ) );
18
+ add_filter( 'acui_force_reset_password_edit_profile_url', array( $this, 'force_reset_password_edit_profile_url' ) );
19
+ add_filter( 'acui_force_reset_password_redirect_condition', array( $this, 'force_reset_password_redirect_condition' ) );
20
+ add_action( 'wp_head', array( $this, 'force_reset_password_notice' ) );
21
+ add_action( 'woocommerce_save_account_details', array( $this, 'force_reset_save_account_details' ) );
22
  }
23
 
24
  function fields(){
122
  <li>**woocommercepasswordreseturllink** = <?php _e( 'WooCommerce password reset url with HTML link', 'import-users-from-csv-with-meta' ); ?>
123
  <?php
124
  }
125
+
126
+ function force_reset_password_edit_profile_url(){
127
+ return wc_get_page_permalink( 'myaccount' );
128
+ }
129
+
130
+ function force_reset_password_redirect_condition(){
131
+ return is_account_page();
132
+ }
133
+
134
+ function force_reset_password_notice(){
135
+ if ( get_user_meta( get_current_user_id(), 'acui_force_reset_password', true ) ) {
136
+ wc_add_notice( apply_filters( 'acui_force_reset_password_message', __( 'Please change your password', 'import-users-from-csv-with-meta' ) ), 'error' );
137
+ }
138
+ }
139
+
140
+ function force_reset_save_account_details( $user_id ){
141
+ $pass1 = $pass2 = '';
142
+
143
+ if ( isset( $_POST['password_1'] ) )
144
+ $pass1 = $_POST['password_1'];
145
+
146
+ if ( isset( $_POST['password_2'] ) )
147
+ $pass2 = $_POST['password_2'];
148
+
149
+ if ( $pass1 != $pass2 || empty( $pass1 ) || empty( $pass2 ) || false !== strpos( stripslashes( $pass1 ), "\\" ) )
150
+ return;
151
+
152
+ delete_user_meta( $user_id, 'acui_force_reset_password' );
153
+ }
154
  }
155
 
156
  new ACUI_WooCommerce();
classes/force-reset-password.php ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) exit;
4
+
5
+ class ACUI_Force_Reset_Password{
6
+ function __construct(){
7
+ }
8
+
9
+ function hooks(){
10
+ add_action( 'post_acui_import_single_user', array( $this, 'new_user' ), 10, 9 );
11
+ add_action( 'personal_options_update', array( $this, 'updated' ) );
12
+ add_action( 'template_redirect', array( $this, 'redirect' ) );
13
+ add_action( 'current_screen', array( $this, 'redirect' ) );
14
+ add_action( 'admin_notices', array( $this, 'notice' ) );
15
+ }
16
+
17
+ function new_user( $headers, $data, $user_id, $role, $positions, $form_data, $is_frontend, $is_cron, $password_changed ){
18
+ if( isset( $form_data["force_user_reset_password"] ) && $form_data["force_user_reset_password"] == 'yes' && $password_changed )
19
+ update_user_meta( $user_id, 'acui_force_reset_password', 1 );
20
+ }
21
+
22
+ function updated( $user_id ){
23
+ $pass1 = $pass2 = '';
24
+
25
+ if ( isset( $_POST['pass1'] ) )
26
+ $pass1 = $_POST['pass1'];
27
+
28
+ if ( isset( $_POST['pass2'] ) )
29
+ $pass2 = $_POST['pass2'];
30
+
31
+ if ( $pass1 != $pass2 || empty( $pass1 ) || empty( $pass2 ) || false !== strpos( stripslashes( $pass1 ), "\\" ) )
32
+ return;
33
+
34
+ delete_user_meta( $user_id, 'acui_force_reset_password' );
35
+ }
36
+
37
+ function redirect() {
38
+ if( is_admin() ) {
39
+ $screen = get_current_screen();
40
+
41
+ if ( in_array( $screen->base, array( 'profile', 'plugins' ) ) )
42
+ return;
43
+ }
44
+
45
+ if( !is_user_logged_in() )
46
+ return;
47
+
48
+ if( apply_filters( 'acui_force_reset_password_redirect_condition', false ) )
49
+ return;
50
+
51
+ if( get_user_meta( get_current_user_id(), 'acui_force_reset_password', true ) ) {
52
+ wp_redirect( apply_filters( 'acui_force_reset_password_edit_profile_url', admin_url( 'profile.php' ) ) );
53
+ die();
54
+ }
55
+ }
56
+
57
+ function notice(){
58
+ if ( get_user_meta( get_current_user_id(), 'acui_force_reset_password', true ) ) {
59
+ printf( '<div class="error"><p>%s</p></div>', apply_filters( 'acui_force_reset_password_message', __( 'Please change your password', 'import-users-from-csv-with-meta' ) ) );
60
+ }
61
+ }
62
+ }
63
+
64
+ $acui_force_reset_password = new ACUI_Force_Reset_Password();
65
+ $acui_force_reset_password->hooks();
classes/homepage.php CHANGED
@@ -80,7 +80,7 @@ class ACUI_Homepage{
80
  </td>
81
  </tr>
82
 
83
- <tr id="acui_send_email_wrapper" class="form-field">
84
  <th scope="row"><label for="user_login"><?php _e( 'Send mail', 'import-users-from-csv-with-meta' ); ?></label></th>
85
  <td>
86
  <p id="sends_email_wrapper">
@@ -93,10 +93,18 @@ class ACUI_Homepage{
93
  </p>
94
  </td>
95
  </tr>
 
 
 
 
 
 
 
 
96
  </tbody>
97
  </table>
98
 
99
- <h2 id="acui_update_users_header"><?php _e( 'Update users', 'import-users-from-csv-with-meta'); ?></h2>
100
 
101
  <table id="acui_update_users_wrapper" class="form-table">
102
  <tbody>
80
  </td>
81
  </tr>
82
 
83
+ <tr id="acui_send_email_wrapper" class="form-field">
84
  <th scope="row"><label for="user_login"><?php _e( 'Send mail', 'import-users-from-csv-with-meta' ); ?></label></th>
85
  <td>
86
  <p id="sends_email_wrapper">
93
  </p>
94
  </td>
95
  </tr>
96
+
97
+ <tr class="form-field form-required">
98
+ <th scope="row"><label for=""><?php _e( 'Force users to reset their passwords?', 'import-users-from-csv-with-meta' ); ?></label></th>
99
+ <td>
100
+ <input type="checkbox" name="force_user_reset_password" value="yes" <?php checked( get_option( 'acui_manually_force_user_reset_password' ) ); ?>/>
101
+ <p class="description"><?php _e( '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' ); ?></p>
102
+ </td>
103
+ </tr>
104
  </tbody>
105
  </table>
106
 
107
+ <h2 id="acui_update_users_header"><?php _e( 'Update users', 'import-users-from-csv-with-meta'); ?></h2>
108
 
109
  <table id="acui_update_users_wrapper" class="form-table">
110
  <tbody>
classes/import.php CHANGED
@@ -158,7 +158,7 @@ class ACUI_Import{
158
  endif;
159
  }
160
 
161
- public function import_users( $file, $form_data, $attach_id = 0, $is_cron = false, $is_frontend = false ){
162
  if ( ! function_exists( 'get_editable_roles' ) ) {
163
  require_once ABSPATH . 'wp-admin/includes/user.php';
164
  }
@@ -166,10 +166,10 @@ class ACUI_Import{
166
  <div class="wrap">
167
  <h2><?php echo apply_filters( 'acui_log_main_title', __('Importing users','import-users-from-csv-with-meta') ); ?></h2>
168
  <?php
169
- set_time_limit(0);
170
 
171
  do_action( 'before_acui_import_users' );
172
-
173
  $acui_helper = new ACUI_Helper();
174
  $restricted_fields = $acui_helper->get_restricted_fields();
175
  $all_roles = array_keys( wp_roles()->roles );
@@ -179,6 +179,9 @@ class ACUI_Import{
179
  $headers = array();
180
  $headers_filtered = array();
181
  $is_backend = !$is_frontend && !$is_cron;
 
 
 
182
  $update_existing_users = isset( $form_data["update_existing_users"] ) ? sanitize_text_field( $form_data["update_existing_users"] ) : '';
183
 
184
  $role_default = isset( $form_data["role"] ) ? $form_data["role"] : array( '' );
@@ -204,9 +207,6 @@ class ACUI_Import{
204
  $allow_multiple_accounts = ( empty( $form_data["allow_multiple_accounts"] ) ) ? "not_allowed" : sanitize_text_field( $form_data["allow_multiple_accounts"] );
205
  }
206
 
207
- update_option( "acui_manually_send_mail", isset( $form_data["sends_email"] ) && $form_data["sends_email"] == 'yes' );
208
- update_option( "acui_manually_send_mail_updated", isset( $form_data["send_email_updated"] ) && $form_data["send_email_updated"] == 'yes' );
209
-
210
  // disable WordPress default emails if this must be disabled
211
  if( !get_option('acui_automatic_wordpress_email') ){
212
  add_filter( 'send_email_change_email', function() { return false; }, 999 );
@@ -305,6 +305,7 @@ class ACUI_Import{
305
  $email = $data[1];
306
  $user_id = 0;
307
  $password_position = $positions["password"];
 
308
  $password = ( $password_position === false ) ? wp_generate_password( apply_filters( 'acui_auto_password_length', 12 ), apply_filters( 'acui_auto_password_special_chars', true ), apply_filters( 'acui_auto_password_extra_special_chars', false ) ) : $data[ $password_position ];
309
  $role_position = $positions["role"];
310
  $role = "";
@@ -362,8 +363,10 @@ class ACUI_Import{
362
  if( $user->user_login == $username ){
363
  $user_id = $id;
364
 
365
- if( $password !== "" && $update_allow_update_passwords == 'yes' )
366
  wp_set_password( $password, $user_id );
 
 
367
 
368
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
369
  if( empty( $new_user_id ) ){
@@ -400,6 +403,7 @@ class ACUI_Import{
400
  ) );
401
 
402
  $created = true;
 
403
  }
404
  }
405
  elseif( username_exists( $username ) ){
@@ -411,8 +415,11 @@ class ACUI_Import{
411
  $user_object = get_user_by( "login", $username );
412
  $user_id = $user_object->ID;
413
 
414
- if( $password !== "" && $update_allow_update_passwords == 'yes' )
415
  wp_set_password( $password, $user_id );
 
 
 
416
 
417
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
418
  if( empty( $new_user_id ) ){
@@ -446,8 +453,11 @@ class ACUI_Import{
446
  $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 );
447
  $errors[] = $acui_helper->new_error( $row, $data[0], 'warning' );
448
 
449
- if( $password !== "" && $update_allow_update_passwords == 'yes' )
450
  wp_set_password( $password, $user_id );
 
 
 
451
 
452
  $created = false;
453
  }
@@ -468,6 +478,7 @@ class ACUI_Import{
468
  }
469
 
470
  $user_id = wp_create_user( $username, $password, $email );
 
471
  }
472
 
473
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
@@ -596,7 +607,7 @@ class ACUI_Import{
596
 
597
  $acui_helper->print_row_imported( $row, $data, $errors );
598
 
599
- do_action( 'post_acui_import_single_user', $headers, $data, $user_id, $role, $positions, $form_data, $is_frontend, $is_cron );
600
 
601
  $mail_for_this_user = false;
602
  if( $is_cron ){
158
  endif;
159
  }
160
 
161
+ function import_users( $file, $form_data, $attach_id = 0, $is_cron = false, $is_frontend = false ){
162
  if ( ! function_exists( 'get_editable_roles' ) ) {
163
  require_once ABSPATH . 'wp-admin/includes/user.php';
164
  }
166
  <div class="wrap">
167
  <h2><?php echo apply_filters( 'acui_log_main_title', __('Importing users','import-users-from-csv-with-meta') ); ?></h2>
168
  <?php
169
+ @set_time_limit( 0 );
170
 
171
  do_action( 'before_acui_import_users' );
172
+
173
  $acui_helper = new ACUI_Helper();
174
  $restricted_fields = $acui_helper->get_restricted_fields();
175
  $all_roles = array_keys( wp_roles()->roles );
179
  $headers = array();
180
  $headers_filtered = array();
181
  $is_backend = !$is_frontend && !$is_cron;
182
+
183
+ ACUI_Options::save_options( $form_data, $is_cron, $is_frontend );
184
+
185
  $update_existing_users = isset( $form_data["update_existing_users"] ) ? sanitize_text_field( $form_data["update_existing_users"] ) : '';
186
 
187
  $role_default = isset( $form_data["role"] ) ? $form_data["role"] : array( '' );
207
  $allow_multiple_accounts = ( empty( $form_data["allow_multiple_accounts"] ) ) ? "not_allowed" : sanitize_text_field( $form_data["allow_multiple_accounts"] );
208
  }
209
 
 
 
 
210
  // disable WordPress default emails if this must be disabled
211
  if( !get_option('acui_automatic_wordpress_email') ){
212
  add_filter( 'send_email_change_email', function() { return false; }, 999 );
305
  $email = $data[1];
306
  $user_id = 0;
307
  $password_position = $positions["password"];
308
+ $password_changed = false;
309
  $password = ( $password_position === false ) ? wp_generate_password( apply_filters( 'acui_auto_password_length', 12 ), apply_filters( 'acui_auto_password_special_chars', true ), apply_filters( 'acui_auto_password_extra_special_chars', false ) ) : $data[ $password_position ];
310
  $role_position = $positions["role"];
311
  $role = "";
363
  if( $user->user_login == $username ){
364
  $user_id = $id;
365
 
366
+ if( $password !== "" && $update_allow_update_passwords == 'yes' ){
367
  wp_set_password( $password, $user_id );
368
+ $password_changed = true;
369
+ }
370
 
371
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
372
  if( empty( $new_user_id ) ){
403
  ) );
404
 
405
  $created = true;
406
+ $password_changed = true;
407
  }
408
  }
409
  elseif( username_exists( $username ) ){
415
  $user_object = get_user_by( "login", $username );
416
  $user_id = $user_object->ID;
417
 
418
+ if( $password !== "" && $update_allow_update_passwords == 'yes' ){
419
  wp_set_password( $password, $user_id );
420
+ $password_changed = true;
421
+ }
422
+
423
 
424
  $new_user_id = $acui_helper->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
425
  if( empty( $new_user_id ) ){
453
  $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 );
454
  $errors[] = $acui_helper->new_error( $row, $data[0], 'warning' );
455
 
456
+ if( $password !== "" && $update_allow_update_passwords == 'yes' ){
457
  wp_set_password( $password, $user_id );
458
+ $password_changed = true;
459
+ }
460
+
461
 
462
  $created = false;
463
  }
478
  }
479
 
480
  $user_id = wp_create_user( $username, $password, $email );
481
+ $password_changed = true;
482
  }
483
 
484
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
607
 
608
  $acui_helper->print_row_imported( $row, $data, $errors );
609
 
610
+ do_action( 'post_acui_import_single_user', $headers, $data, $user_id, $role, $positions, $form_data, $is_frontend, $is_cron, $password_changed );
611
 
612
  $mail_for_this_user = false;
613
  if( $is_cron ){
classes/options.php CHANGED
@@ -9,7 +9,10 @@ class ACUI_Options{
9
  // homepage
10
  self::$prefix . 'last_roles_used' => array(),
11
  self::$prefix . 'path_to_file' => dirname( __FILE__ ) . '/test.csv',
12
- // emails
 
 
 
13
  self::$prefix . 'mail_subject' => __('Welcome to', 'import-users-from-csv-with-meta') . ' ' . get_bloginfo("name"),
14
  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>',
15
  self::$prefix . 'mail_template_id' => 0,
@@ -74,4 +77,12 @@ class ACUI_Options{
74
  $key = self::prepare_key( $key, $class );
75
  return update_option( $key, $value );
76
  }
 
 
 
 
 
 
 
 
77
  }
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>',
18
  self::$prefix . 'mail_template_id' => 0,
77
  $key = self::prepare_key( $key, $class );
78
  return update_option( $key, $value );
79
  }
80
+
81
+ static function save_options( $form_data, $is_cron, $is_frontend ){
82
+ if( !$is_frontend && !$is_cron ){
83
+ update_option( "acui_manually_send_mail", isset( $form_data["sends_email"] ) && $form_data["sends_email"] == 'yes' );
84
+ update_option( "acui_manually_send_mail_updated", isset( $form_data["send_email_updated"] ) && $form_data["send_email_updated"] == 'yes' );
85
+ update_option( "acui_manually_force_user_reset_password", isset( $form_data["force_user_reset_password"] ) && $form_data["force_user_reset_password"] == 'yes' );
86
+ }
87
+ }
88
  }
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.17.5.2
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
@@ -11,6 +11,7 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
  Text Domain: import-users-from-csv-with-meta
12
  Domain Path: /languages
13
  */
 
14
  if ( ! defined( 'ABSPATH' ) )
15
  exit;
16
 
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.17.5.3
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
11
  Text Domain: import-users-from-csv-with-meta
12
  Domain Path: /languages
13
  */
14
+
15
  if ( ! defined( 'ABSPATH' ) )
16
  exit;
17
 
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: 5.7.1
7
- Stable tag: 1.17.5.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -103,6 +103,10 @@ Plugin will automatically detect:
103
 
104
  == Changelog ==
105
 
 
 
 
 
106
  = 1.17.5.2 =
107
  * New hooks into shortcode form to enable include actions from there
108
 
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: 5.7.2
7
+ Stable tag: 1.17.5.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.17.5.3 =
107
+ * You can now force the users to reset their passwords after login if you have changed the password in the import
108
+ * Some code improvements
109
+
110
  = 1.17.5.2 =
111
  * New hooks into shortcode form to enable include actions from there
112