Import users from CSV with meta - Version 1.10.4

Version Description

  • Now you can assign BuddyPress groups and assign roles in import thanks to TNTP (tntp.org)
  • Import optimization
  • Readme fixed
Download this release

Release Info

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

Code changes from version 1.10.3.1 to 1.10.4

Files changed (3) hide show
  1. import-users-from-csv-with-meta.php +12 -11
  2. importer.php +62 -10
  3. readme.txt +6 -4
import-users-from-csv-with-meta.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Import users from CSV with meta
4
  Plugin URI: http://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
  Author: codection
7
- Version: 1.10.3.1
8
  Author URI: http://codection.com
9
  Text Domain: import-users-from-csv-with-meta
10
  Domain Path: /languages
@@ -15,6 +15,8 @@ if ( ! defined( 'ABSPATH' ) ) exit;
15
  $url_plugin = WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), "", plugin_basename( __FILE__ ) );
16
  $wp_users_fields = array( "id", "user_nicename", "user_url", "display_name", "nickname", "first_name", "last_name", "description", "jabber", "aim", "yim", "user_registered", "password", "user_pass", "locale" );
17
  $wp_min_fields = array("Username", "Email");
 
 
18
 
19
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
20
 
@@ -431,18 +433,17 @@ function acui_cron_process_auto_rename () {
431
  }
432
 
433
  function acui_extra_user_profile_fields( $user ) {
434
- global $wp_users_fields;
435
- global $wp_min_fields;
436
 
437
  $headers = get_option("acui_columns");
438
- if( is_array($headers) && !empty($headers) ):
439
  ?>
440
  <h3>Extra profile information</h3>
441
 
442
  <table class="form-table"><?php
443
 
444
- foreach ($headers as $column):
445
- if(in_array($column, $wp_min_fields) || in_array($column, $wp_users_fields))
446
  continue;
447
  ?>
448
  <tr>
@@ -457,15 +458,15 @@ function acui_extra_user_profile_fields( $user ) {
457
  }
458
 
459
  function acui_save_extra_user_profile_fields( $user_id ){
460
- global $wp_users_fields;
461
- global $wp_min_fields;
462
  $headers = get_option("acui_columns");
463
 
464
  $post_filtered = filter_input_array( INPUT_POST );
465
 
466
- if( is_array($headers) && count($headers) > 0 ):
467
- foreach ($headers as $column){
468
- if(in_array($column, $wp_min_fields) || in_array($column, $wp_users_fields))
469
  continue;
470
 
471
  $column_sanitized = str_replace(" ", "_", $column);
4
  Plugin URI: http://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
  Author: codection
7
+ Version: 1.10.4
8
  Author URI: http://codection.com
9
  Text Domain: import-users-from-csv-with-meta
10
  Domain Path: /languages
15
  $url_plugin = WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), "", plugin_basename( __FILE__ ) );
16
  $wp_users_fields = array( "id", "user_nicename", "user_url", "display_name", "nickname", "first_name", "last_name", "description", "jabber", "aim", "yim", "user_registered", "password", "user_pass", "locale" );
17
  $wp_min_fields = array("Username", "Email");
18
+ $acui_fields = array( "bp_group", "bp_group_role" );
19
+ $acui_restricted_fields = array_merge( $wp_users_fields, $wp_min_fields, $acui_fields );
20
 
21
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
22
 
433
  }
434
 
435
  function acui_extra_user_profile_fields( $user ) {
436
+ global $acui_restricted_fields;
 
437
 
438
  $headers = get_option("acui_columns");
439
+ if( is_array( $headers ) && !empty( $headers ) ):
440
  ?>
441
  <h3>Extra profile information</h3>
442
 
443
  <table class="form-table"><?php
444
 
445
+ foreach ( $headers as $column ):
446
+ if( in_array( $column, $acui_restricted_fields ) )
447
  continue;
448
  ?>
449
  <tr>
458
  }
459
 
460
  function acui_save_extra_user_profile_fields( $user_id ){
461
+ global $acui_restricted_fields;
462
+
463
  $headers = get_option("acui_columns");
464
 
465
  $post_filtered = filter_input_array( INPUT_POST );
466
 
467
+ if( is_array( $headers ) && count( $headers ) > 0 ):
468
+ foreach ( $headers as $column ){
469
+ if( in_array( $column, $acui_restricted_fields ) )
470
  continue;
471
 
472
  $column_sanitized = str_replace(" ", "_", $column);
importer.php CHANGED
@@ -13,6 +13,8 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
13
  global $wpdb;
14
  global $wp_users_fields;
15
  global $wp_min_fields;
 
 
16
 
17
  if( is_plugin_active( 'wp-access-areas/wp-access-areas.php' ) ){
18
  $wpaa_labels = WPAA_AccessArea::get_available_userlabels();
@@ -94,17 +96,17 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
94
  $password_position = false;
95
  $id_position = false;
96
 
97
- foreach ( $wp_users_fields as $wp_users_field ) {
98
- $positions[ $wp_users_field ] = false;
99
  }
100
 
101
  foreach($data as $element){
102
  $headers[] = $element;
103
 
104
- if( in_array( strtolower($element) , $wp_users_fields ) )
105
  $positions[ strtolower($element) ] = $i;
106
 
107
- if( !in_array( strtolower( $element ), $wp_users_fields ) && !in_array( $element, $wp_min_fields ) && !in_array( $element, $buddypress_fields ) )
108
  $headers_filtered[] = $element;
109
 
110
  $i++;
@@ -279,7 +281,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
279
  update_user_meta( $user_id, "pending", true );
280
 
281
  if( $columns > 2 ){
282
- for( $i=2 ; $i<$columns; $i++ ):
283
  $data[$i] = apply_filters( 'pre_acui_import_single_user_single_data', $data[$i], $headers[$i], $i);
284
 
285
  if( !empty( $data ) ){
@@ -290,10 +292,13 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
290
  $wpdb->update( $wpdb->users, array( 'user_pass' => $data[ $i ] ), array( 'ID' => $user_id ) );
291
  }
292
  elseif( in_array( $headers[ $i ], $wp_users_fields ) ){ // wp_user data
293
- if( empty( $data[ $i ] ) && $empty_cell_action == "leave" )
294
  continue;
295
- else
296
- wp_update_user( array( 'ID' => $user_id, $headers[ $i ] => $data[ $i ] ) );
 
 
 
297
  }
298
  elseif( strtolower( $headers[ $i ] ) == "wp-access-areas" && is_plugin_active( 'wp-access-areas/wp-access-areas.php' ) ){ // wp-access-areas
299
  $active_labels = array_map( 'trim', explode( "#", $data[ $i ] ) );
@@ -306,10 +311,37 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
306
  acui_set_cap_for_user( $wpa_label->capability , $user_object , false );
307
  }
308
  }
 
 
309
  }
310
  elseif( in_array( $headers[ $i ], $buddypress_fields ) ){ // buddypress
311
  xprofile_set_field_data( $headers[ $i ], $user_id, $data[ $i ] );
 
312
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
313
  else{ // wp_usermeta data
314
 
315
  if( $data[ $i ] === '' ){
@@ -318,8 +350,10 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
318
  else
319
  continue;
320
  }
321
- else
322
  update_user_meta( $user_id, $headers[ $i ], $data[ $i ] );
 
 
323
  }
324
 
325
  }
@@ -911,7 +945,25 @@ function acui_options()
911
  </td>
912
  </tr>
913
 
914
- <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
915
  <tr valign="top">
916
  <th scope="row"><?php _e( "Important notice", 'import-users-from-csv-with-meta' ); ?></th>
917
  <td><?php _e( "You can upload as many files as you want, but all must have the same columns. If you upload another file, the columns will change to the form of last file uploaded.", 'import-users-from-csv-with-meta' ); ?></td>
13
  global $wpdb;
14
  global $wp_users_fields;
15
  global $wp_min_fields;
16
+ global $acui_fields;
17
+ global $acui_restricted_fields;
18
 
19
  if( is_plugin_active( 'wp-access-areas/wp-access-areas.php' ) ){
20
  $wpaa_labels = WPAA_AccessArea::get_available_userlabels();
96
  $password_position = false;
97
  $id_position = false;
98
 
99
+ foreach ( $acui_restricted_fields as $acui_restricted_field ) {
100
+ $positions[ $acui_restricted_field ] = false;
101
  }
102
 
103
  foreach($data as $element){
104
  $headers[] = $element;
105
 
106
+ if( in_array( strtolower($element) , $acui_restricted_fields ) )
107
  $positions[ strtolower($element) ] = $i;
108
 
109
+ if( !in_array( strtolower( $element ), $acui_restricted_fields ) && !in_array( $element, $buddypress_fields ) )
110
  $headers_filtered[] = $element;
111
 
112
  $i++;
281
  update_user_meta( $user_id, "pending", true );
282
 
283
  if( $columns > 2 ){
284
+ for( $i = 2 ; $i < $columns; $i++ ):
285
  $data[$i] = apply_filters( 'pre_acui_import_single_user_single_data', $data[$i], $headers[$i], $i);
286
 
287
  if( !empty( $data ) ){
292
  $wpdb->update( $wpdb->users, array( 'user_pass' => $data[ $i ] ), array( 'ID' => $user_id ) );
293
  }
294
  elseif( in_array( $headers[ $i ], $wp_users_fields ) ){ // wp_user data
295
+ if( empty( $data[ $i ] ) && $empty_cell_action == "leave" ){
296
  continue;
297
+ }
298
+ else{
299
+ wp_update_user( array( 'ID' => $user_id, $headers[ $i ] => $data[ $i ] ) );
300
+ continue;
301
+ }
302
  }
303
  elseif( strtolower( $headers[ $i ] ) == "wp-access-areas" && is_plugin_active( 'wp-access-areas/wp-access-areas.php' ) ){ // wp-access-areas
304
  $active_labels = array_map( 'trim', explode( "#", $data[ $i ] ) );
311
  acui_set_cap_for_user( $wpa_label->capability , $user_object , false );
312
  }
313
  }
314
+
315
+ continue;
316
  }
317
  elseif( in_array( $headers[ $i ], $buddypress_fields ) ){ // buddypress
318
  xprofile_set_field_data( $headers[ $i ], $user_id, $data[ $i ] );
319
+ continue;
320
  }
321
+ elseif( $headers[ $i ] == 'bp_group' ){ // buddypress group
322
+ $groups = explode( ',', $data[ $i ] );
323
+ $groups_role = explode( ',', $data[ $positions[ 'bp_group_role' ] ] );
324
+
325
+ for( $j = 0; $j < count( $groups ); $j++ ){
326
+ $group_id = BP_Groups_Group::group_exists( $groups[ $j ] );
327
+
328
+ if( !empty( $group_id ) ){
329
+ groups_join_group( $group_id, $user_id );
330
+
331
+ if( $groups_role[ $j ] == 'Moderator' ){
332
+ groups_promote_member( $user_id, $group_id, 'mod' );
333
+ }
334
+ elseif( $groups_role[ $j ] == 'Administrator' ){
335
+ groups_promote_member( $user_id, $group_id, 'admin' );
336
+ }
337
+ }
338
+ }
339
+
340
+ continue;
341
+ }
342
+ elseif( $headers[ $i ] == 'bp_group_role' ){
343
+ continue;
344
+ }
345
  else{ // wp_usermeta data
346
 
347
  if( $data[ $i ] === '' ){
350
  else
351
  continue;
352
  }
353
+ else{
354
  update_user_meta( $user_id, $headers[ $i ], $data[ $i ] );
355
+ continue;
356
+ }
357
  }
358
 
359
  }
945
  </td>
946
  </tr>
947
 
948
+ <?php endif; ?>
949
+
950
+ <?php if( is_plugin_active( 'buddypress/bp-loader.php' ) ): ?>
951
+
952
+ <tr valign="top">
953
+ <th scope="row"><?php _e( "BuddyPress is activated", 'import-users-from-csv-with-meta' ); ?></th>
954
+ <td><?php _e( "You can use the <strong>profile fields</strong> you have created and also you can set one or more groups for each user. For example:", 'import-users-from-csv-with-meta' ); ?>
955
+ <ul style="list-style:disc outside none; margin-left:2em;">
956
+ <li><?php _e( "If you want to assign an user to a group you have to create a column 'bp_group' and a column 'bp_group_role'", 'import-users-from-csv-with-meta' ); ?></li>
957
+ <li><?php _e( "Then in each cell you have to fill with the BuddyPress <strong>group slug</strong>", 'import-users-from-csv-with-meta' ); ?></li>
958
+ <li><?php _e( "And the role assigned in this group: <em>Administrator, Moderator or Member</em>", 'import-users-from-csv-with-meta' ); ?></li>
959
+ <li><?php _e( "You can do it with multiple groups at the same time using commas to separate different groups, in bp_group column, i.e.: <em>group_1, group_2, group_3</em>", 'import-users-from-csv-with-meta' ); ?></li>
960
+ <li><?php _e( "But you will have to assign a role for each group: <em>Moderator,Moderator,Member,Member</em>", 'import-users-from-csv-with-meta' ); ?></li>
961
+ </ul>
962
+ </td>
963
+ </tr>
964
+
965
+ <?php endif; ?>
966
+
967
  <tr valign="top">
968
  <th scope="row"><?php _e( "Important notice", 'import-users-from-csv-with-meta' ); ?></th>
969
  <td><?php _e( "You can upload as many files as you want, but all must have the same columns. If you upload another file, the columns will change to the form of last file uploaded.", 'import-users-from-csv-with-meta' ); ?></td>
readme.txt CHANGED
@@ -4,11 +4,9 @@ Donate link: http://paypal.me/codection
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: 4.7.2
7
- Stable tag: 1.10.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
- Text Domain: import-users-from-csv-with-meta
11
- Domain Path: /languages
12
 
13
  A plugin to import users using CSV files to WP database automatically including custom user meta
14
 
@@ -62,7 +60,6 @@ Plugin will automatically detect:
62
  * It also will **auto detect line-ending** to prevent problems with different OS.
63
  * Finally, it will **detect the delimiter** being used in CSV file ("," or ";" or "|")
64
 
65
-
66
  == Screenshots ==
67
 
68
  1. Plugin link from dashboard
@@ -73,6 +70,11 @@ Plugin will automatically detect:
73
 
74
  == Changelog ==
75
 
 
 
 
 
 
76
  = 1.10.3.1 =
77
  * Bug fixed in SMTP settings page
78
 
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: 4.7.2
7
+ Stable tag: 1.10.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
 
 
10
 
11
  A plugin to import users using CSV files to WP database automatically including custom user meta
12
 
60
  * It also will **auto detect line-ending** to prevent problems with different OS.
61
  * Finally, it will **detect the delimiter** being used in CSV file ("," or ";" or "|")
62
 
 
63
  == Screenshots ==
64
 
65
  1. Plugin link from dashboard
70
 
71
  == Changelog ==
72
 
73
+ = 1.10.4 =
74
+ * Now you can assign BuddyPress groups and assign roles in import thanks to TNTP (tntp.org)
75
+ * Import optimization
76
+ * Readme fixed
77
+
78
  = 1.10.3.1 =
79
  * Bug fixed in SMTP settings page
80