Version Description
- You can choose what to do with users that being updated, their email has changed: you can update it, skip this user, or create a new user with a prefix
Download this release
Release Info
Developer | carazo |
Plugin | Import users from CSV with meta |
Version | 1.16.4 |
Comparing to | |
See all releases |
Code changes from version 1.16.3.6 to 1.16.4
- classes/homepage.php +12 -0
- classes/import.php +48 -1
- import-users-from-csv-with-meta.php +1 -1
- importer.php +64 -55
- readme.txt +5 -2
classes/homepage.php
CHANGED
@@ -110,6 +110,18 @@ class ACUI_Homepage{
|
|
110 |
</td>
|
111 |
</tr>
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
<tr id="acui_update_roles_existing_users_wrapper" class="form-field form-required">
|
114 |
<th scope="row"><label for="update_roles_existing_users"><?php _e( 'Update roles for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
|
115 |
<td>
|
110 |
</td>
|
111 |
</tr>
|
112 |
|
113 |
+
<tr id="acui_update_emails_existing_users_wrapper" class="form-field form-required">
|
114 |
+
<th scope="row"><label for="update_emails_existing_users"><?php _e( 'Update emails?', 'import-users-from-csv-with-meta' ); ?></label></th>
|
115 |
+
<td>
|
116 |
+
<select name="update_emails_existing_users">
|
117 |
+
<option value="yes"><?php _e( 'Yes', 'import-users-from-csv-with-meta' ); ?></option>
|
118 |
+
<option value="create"><?php _e( 'No, but create a new user with a prefix in the username', 'import-users-from-csv-with-meta' ); ?></option>
|
119 |
+
<option value="no"><?php _e( 'No, skip this user', 'import-users-from-csv-with-meta' ); ?></option>
|
120 |
+
</select>
|
121 |
+
<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>
|
122 |
+
</td>
|
123 |
+
</tr>
|
124 |
+
|
125 |
<tr id="acui_update_roles_existing_users_wrapper" class="form-field form-required">
|
126 |
<th scope="row"><label for="update_roles_existing_users"><?php _e( 'Update roles for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
|
127 |
<td>
|
classes/import.php
CHANGED
@@ -1,11 +1,58 @@
|
|
1 |
<?php
|
2 |
|
3 |
class ACUI_Import{
|
4 |
-
public
|
5 |
do {
|
6 |
$rnd_str = sprintf("%06d", mt_rand(1, 999999));
|
7 |
} while( username_exists( $prefix . $rnd_str ) );
|
8 |
|
9 |
return $prefix . $rnd_str;
|
10 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
1 |
<?php
|
2 |
|
3 |
class ACUI_Import{
|
4 |
+
public function get_random_unique_username( $prefix = '' ){
|
5 |
do {
|
6 |
$rnd_str = sprintf("%06d", mt_rand(1, 999999));
|
7 |
} while( username_exists( $prefix . $rnd_str ) );
|
8 |
|
9 |
return $prefix . $rnd_str;
|
10 |
}
|
11 |
+
|
12 |
+
public function maybe_update_email( $user_id, $email, $password, $update_emails_existing_users ){
|
13 |
+
$user_object = get_user_by( 'id', $user_id );
|
14 |
+
|
15 |
+
if( $user_object->user_email == $email )
|
16 |
+
return $user_id;
|
17 |
+
|
18 |
+
switch( $update_emails_existing_users ){
|
19 |
+
case 'yes':
|
20 |
+
$user_id = wp_update_user( array( 'ID' => $user_id, 'user_email' => $email ) );
|
21 |
+
break;
|
22 |
+
|
23 |
+
case 'no':
|
24 |
+
$user_id = 0;
|
25 |
+
break;
|
26 |
+
|
27 |
+
case 'create':
|
28 |
+
$user_id = wp_insert_user( array(
|
29 |
+
'user_login' => $this->get_random_unique_username( 'duplicated_username_' ),
|
30 |
+
'user_email' => $email,
|
31 |
+
'user_pass' => $password
|
32 |
+
) );
|
33 |
+
break;
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
return $user_id;
|
38 |
+
}
|
39 |
+
|
40 |
+
public function basic_css(){
|
41 |
+
?>
|
42 |
+
<style type="text/css">
|
43 |
+
.wrap{
|
44 |
+
overflow-x:auto!important;
|
45 |
+
}
|
46 |
+
|
47 |
+
.wrap table{
|
48 |
+
min-width:800px!important;
|
49 |
+
}
|
50 |
+
|
51 |
+
.wrap table th,
|
52 |
+
.wrap table td{
|
53 |
+
width:200px!important;
|
54 |
+
}
|
55 |
+
</style>
|
56 |
+
<?php
|
57 |
+
}
|
58 |
}
|
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.16.
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
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.16.4
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
importer.php
CHANGED
@@ -14,6 +14,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
14 |
do_action( 'before_acui_import_users' );
|
15 |
|
16 |
global $wpdb;
|
|
|
17 |
$wp_users_fields = acui_get_wp_users_fields();
|
18 |
$acui_not_meta_fields = acui_get_not_meta_fields();
|
19 |
$acui_restricted_fields = acui_get_restricted_fields();
|
@@ -52,6 +53,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
52 |
$role_default = array( $role_default );
|
53 |
array_walk( $role_default, 'sanitize_text_field' );
|
54 |
|
|
|
55 |
$update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? sanitize_text_field( $form_data["update_roles_existing_users"] ) : '';
|
56 |
$update_allow_update_passwords = isset( $form_data["update_allow_update_passwords"] ) ? sanitize_text_field( $form_data["update_allow_update_passwords"] ) : 'yes';
|
57 |
$empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
|
@@ -98,7 +100,10 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
98 |
if( count( $data ) == 1 )
|
99 |
$data = $data[0];
|
100 |
|
101 |
-
if(
|
|
|
|
|
|
|
102 |
echo apply_filters( 'acui_message_csv_file_bad_formed', __( 'CSV file seems to be bad formed. Please use LibreOffice to create and manage CSV to be sure the format is correct', 'import-users-from-csv-with-meta') );
|
103 |
break;
|
104 |
}
|
@@ -148,21 +153,10 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
148 |
$columns = count( $data );
|
149 |
|
150 |
update_option( "acui_columns", $headers_filtered );
|
151 |
-
?>
|
152 |
-
<style type="text/css">
|
153 |
-
.wrap{
|
154 |
-
overflow-x:auto!important;
|
155 |
-
}
|
156 |
-
|
157 |
-
.wrap table{
|
158 |
-
min-width:800px!important;
|
159 |
-
}
|
160 |
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
}
|
165 |
-
</style>
|
166 |
<h3><?php echo apply_filters( 'acui_log_inserting_updating_data_title', __( 'Inserting and updating data', 'import-users-from-csv-with-meta' ) ); ?></h3>
|
167 |
<table>
|
168 |
<tr>
|
@@ -186,7 +180,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
186 |
do_action('pre_acui_import_single_user', $headers, $data );
|
187 |
$data = apply_filters('pre_acui_import_single_user_data', $data, $headers);
|
188 |
|
189 |
-
$username = empty( $data[0] ) ?
|
190 |
$email = $data[1];
|
191 |
$user_id = 0;
|
192 |
$problematic_row = false;
|
@@ -227,6 +221,17 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
227 |
continue;
|
228 |
}
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
if( !empty( $id ) ){ // if user have used id
|
231 |
if( acui_user_id_exists( $id ) ){
|
232 |
if( $update_existing_users == 'no' ){
|
@@ -242,46 +247,45 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
242 |
if( $password !== "" && $update_allow_update_passwords == 'yes' )
|
243 |
wp_set_password( $password, $user_id );
|
244 |
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
}
|
252 |
-
|
253 |
-
$created = false;
|
254 |
}
|
255 |
else{
|
256 |
echo '<script>alert("' . __( 'Problems with ID', 'import-users-from-csv-with-meta' ) . ": $id , " . __( 'username is not the same in the CSV and in database, we are going to skip.', 'import-users-from-csv-with-meta' ) . '");</script>';
|
257 |
continue;
|
258 |
}
|
259 |
-
|
260 |
}
|
261 |
else{
|
262 |
-
$
|
263 |
'ID' => $id,
|
264 |
'user_login' => $username,
|
265 |
'user_email' => $email,
|
266 |
'user_pass' => $password
|
267 |
-
);
|
268 |
-
|
269 |
-
$user_id = wp_insert_user( $userdata );
|
270 |
|
271 |
$created = true;
|
272 |
}
|
273 |
}
|
274 |
-
elseif(
|
275 |
-
$problematic_row = true;
|
276 |
-
$error_importing = true;
|
277 |
-
$data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
|
278 |
-
}
|
279 |
-
elseif( empty( $email) ) { // if email is blank
|
280 |
-
$problematic_row = true;
|
281 |
-
$error_importing = true;
|
282 |
-
$data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
|
283 |
-
}
|
284 |
-
elseif( username_exists( $username ) ){ // if user exists, we take his ID by login, we will update his mail if it has changed
|
285 |
if( $update_existing_users == 'no' ){
|
286 |
continue;
|
287 |
}
|
@@ -292,22 +296,27 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
|
|
292 |
if( $password !== "" && $update_allow_update_passwords == 'yes' )
|
293 |
wp_set_password( $password, $user_id );
|
294 |
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
$
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
}
|
309 |
-
|
310 |
-
$created = false;
|
311 |
}
|
312 |
elseif( email_exists( $email ) && $allow_multiple_accounts == "not_allowed" ){ // if the email is registered, we take the user from this and we don't allow repeated emails
|
313 |
if( $update_existing_users == 'no' ){
|
14 |
do_action( 'before_acui_import_users' );
|
15 |
|
16 |
global $wpdb;
|
17 |
+
$acui_import = new ACUI_Import();
|
18 |
$wp_users_fields = acui_get_wp_users_fields();
|
19 |
$acui_not_meta_fields = acui_get_not_meta_fields();
|
20 |
$acui_restricted_fields = acui_get_restricted_fields();
|
53 |
$role_default = array( $role_default );
|
54 |
array_walk( $role_default, 'sanitize_text_field' );
|
55 |
|
56 |
+
$update_emails_existing_users = isset( $form_data["update_emails_existing_users"] ) ? sanitize_text_field( $form_data["update_emails_existing_users"] ) : 'yes';
|
57 |
$update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? sanitize_text_field( $form_data["update_roles_existing_users"] ) : '';
|
58 |
$update_allow_update_passwords = isset( $form_data["update_allow_update_passwords"] ) ? sanitize_text_field( $form_data["update_allow_update_passwords"] ) : 'yes';
|
59 |
$empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
|
100 |
if( count( $data ) == 1 )
|
101 |
$data = $data[0];
|
102 |
|
103 |
+
if( $data == NULL ){
|
104 |
+
break;
|
105 |
+
}
|
106 |
+
elseif( !is_array( $data ) ){
|
107 |
echo apply_filters( 'acui_message_csv_file_bad_formed', __( 'CSV file seems to be bad formed. Please use LibreOffice to create and manage CSV to be sure the format is correct', 'import-users-from-csv-with-meta') );
|
108 |
break;
|
109 |
}
|
153 |
$columns = count( $data );
|
154 |
|
155 |
update_option( "acui_columns", $headers_filtered );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
+
$acui_import->basic_css();
|
158 |
+
?>
|
159 |
+
|
|
|
|
|
160 |
<h3><?php echo apply_filters( 'acui_log_inserting_updating_data_title', __( 'Inserting and updating data', 'import-users-from-csv-with-meta' ) ); ?></h3>
|
161 |
<table>
|
162 |
<tr>
|
180 |
do_action('pre_acui_import_single_user', $headers, $data );
|
181 |
$data = apply_filters('pre_acui_import_single_user_data', $data, $headers);
|
182 |
|
183 |
+
$username = empty( $data[0] ) ? $acui_import->get_random_unique_username( 'user_' ) : $data[0];
|
184 |
$email = $data[1];
|
185 |
$user_id = 0;
|
186 |
$problematic_row = false;
|
221 |
continue;
|
222 |
}
|
223 |
|
224 |
+
if( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid
|
225 |
+
$problematic_row = true;
|
226 |
+
$error_importing = true;
|
227 |
+
$data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
|
228 |
+
}
|
229 |
+
elseif( empty( $email) ) {
|
230 |
+
$problematic_row = true;
|
231 |
+
$error_importing = true;
|
232 |
+
$data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
|
233 |
+
}
|
234 |
+
|
235 |
if( !empty( $id ) ){ // if user have used id
|
236 |
if( acui_user_id_exists( $id ) ){
|
237 |
if( $update_existing_users == 'no' ){
|
247 |
if( $password !== "" && $update_allow_update_passwords == 'yes' )
|
248 |
wp_set_password( $password, $user_id );
|
249 |
|
250 |
+
$new_user_id = $acui_import->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
|
251 |
+
if( empty( $new_user_id ) ){
|
252 |
+
continue;
|
253 |
+
}
|
254 |
+
|
255 |
+
if( is_wp_error( $new_user_id ) ){
|
256 |
+
$problematic_row = true;
|
257 |
+
$error_importing = true;
|
258 |
+
$data[0] = $new_user_id->get_error_message();
|
259 |
+
$created = false;
|
260 |
+
}
|
261 |
+
elseif( $new_user_id == $user_id)
|
262 |
+
$created = false;
|
263 |
+
else{
|
264 |
+
$user_id = $new_user_id;
|
265 |
+
$new_user = get_user_by( 'id', $new_user_id );
|
266 |
+
$problematic_row = true;
|
267 |
+
$error_importing = true;
|
268 |
+
$data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
|
269 |
+
$created = true;
|
270 |
}
|
|
|
|
|
271 |
}
|
272 |
else{
|
273 |
echo '<script>alert("' . __( 'Problems with ID', 'import-users-from-csv-with-meta' ) . ": $id , " . __( 'username is not the same in the CSV and in database, we are going to skip.', 'import-users-from-csv-with-meta' ) . '");</script>';
|
274 |
continue;
|
275 |
}
|
|
|
276 |
}
|
277 |
else{
|
278 |
+
$user_id = wp_insert_user( array(
|
279 |
'ID' => $id,
|
280 |
'user_login' => $username,
|
281 |
'user_email' => $email,
|
282 |
'user_pass' => $password
|
283 |
+
) );
|
|
|
|
|
284 |
|
285 |
$created = true;
|
286 |
}
|
287 |
}
|
288 |
+
elseif( username_exists( $username ) ){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
if( $update_existing_users == 'no' ){
|
290 |
continue;
|
291 |
}
|
296 |
if( $password !== "" && $update_allow_update_passwords == 'yes' )
|
297 |
wp_set_password( $password, $user_id );
|
298 |
|
299 |
+
$new_user_id = $acui_import->maybe_update_email( $user_id, $email, $password, $update_emails_existing_users );
|
300 |
+
if( empty( $new_user_id ) ){
|
301 |
+
continue;
|
302 |
+
}
|
303 |
+
|
304 |
+
if( is_wp_error( $new_user_id ) ){
|
305 |
+
$problematic_row = true;
|
306 |
+
$error_importing = true;
|
307 |
+
$data[0] = $new_user_id->get_error_message();
|
308 |
+
$created = false;
|
309 |
+
}
|
310 |
+
elseif( $new_user_id == $user_id)
|
311 |
+
$created = false;
|
312 |
+
else{
|
313 |
+
$user_id = $new_user_id;
|
314 |
+
$new_user = get_user_by( 'id', $new_user_id );
|
315 |
+
$problematic_row = true;
|
316 |
+
$error_importing = true;
|
317 |
+
$data[0] = sprintf( __( 'Email has changed, new user created with username %s', 'import-users-from-csv-with-meta' ), $new_user->user_login );
|
318 |
+
$created = true;
|
319 |
}
|
|
|
|
|
320 |
}
|
321 |
elseif( email_exists( $email ) && $allow_multiple_accounts == "not_allowed" ){ // if the email is registered, we take the user from this and we don't allow repeated emails
|
322 |
if( $update_existing_users == 'no' ){
|
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 |
-
Stable tag: 1.16.
|
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.16.3.6 =
|
107 |
* When you are exporting data we scape every first data if it starts with a +, -, =, and @ including a \ to prevent any unwanted formula execution in a spreadsheet that will be working with the CSV
|
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.6
|
7 |
+
Stable tag: 1.16.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.16.4 =
|
107 |
+
* You can choose what to do with users that being updated, their email has changed: you can update it, skip this user, or create a new user with a prefix
|
108 |
+
|
109 |
= 1.16.3.6 =
|
110 |
* When you are exporting data we scape every first data if it starts with a +, -, =, and @ including a \ to prevent any unwanted formula execution in a spreadsheet that will be working with the CSV
|
111 |
|