Import users from CSV with meta - Version 1.15.5.5

Version Description

  • Groups can be now imported by their name instead only of their ids
Download this release

Release Info

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

Code changes from version 1.15.5.4 to 1.15.5.5

addons/groups.php CHANGED
@@ -9,6 +9,7 @@ if( !is_plugin_active( 'groups/groups.php' ) ){
9
  add_filter( 'acui_restricted_fields', 'acui_g_restricted_fields', 10, 1 );
10
  add_action( 'acui_documentation_after_plugins_activated', 'acui_g_documentation_after_plugins_activated' );
11
  add_action( 'post_acui_import_single_user', 'acui_g_post_import_single_user', 10, 3 );
 
12
 
13
  function acui_g_restricted_fields( $acui_restricted_fields ){
14
  return array_merge( $acui_restricted_fields, array( 'group_id' ) );
@@ -23,6 +24,8 @@ function acui_g_documentation_after_plugins_activated(){
23
  <ul style="list-style:disc outside none; margin-left:2em;">
24
  <li><?php _e( "group_id as the column title", 'import-users-from-csv-with-meta' ); ?></li>
25
  <li><?php _e( "The value of each cell will be the ID of the group that you want to assign to this user", 'import-users-from-csv-with-meta' ); ?></li>
 
 
26
  <li><?php _e( "If you want to import multiple values, you can use a list using commas to separate items", 'import-users-from-csv-with-meta' ); ?></li>
27
  </ul>
28
  </td>
@@ -41,15 +44,42 @@ function acui_g_post_import_single_user( $headers, $row, $user_id ){
41
  $user_groups_csv = array_filter( $user_groups_csv, function( $value ){ return $value !== ''; } );
42
 
43
  // groups that user belongs to
44
- $groups_user = new Groups_User( $user_id );
45
  $user_group_ids = $groups_user->group_ids;
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  // first we look into all current user groups, if they do not appear in CSV it will be removed
48
  foreach ( $user_group_ids as $user_group_id ) {
49
  if( !in_array( $user_group_id, $user_groups_csv ) )
50
  Groups_User_Group::delete( $user_id, $user_group_id );
51
  }
52
-
53
  // finally we loop into groups that are present in CSV data, if they already exists, we do nothing, if not, we add it
54
  foreach ( $user_groups_csv as $user_group_csv ) {
55
  if( !in_array( $user_group_csv, $user_group_ids ) )
9
  add_filter( 'acui_restricted_fields', 'acui_g_restricted_fields', 10, 1 );
10
  add_action( 'acui_documentation_after_plugins_activated', 'acui_g_documentation_after_plugins_activated' );
11
  add_action( 'post_acui_import_single_user', 'acui_g_post_import_single_user', 10, 3 );
12
+ add_action( 'post_acui_import_single_user', 'acui_g_post_import_single_user_by_name', 11, 3 );
13
 
14
  function acui_g_restricted_fields( $acui_restricted_fields ){
15
  return array_merge( $acui_restricted_fields, array( 'group_id' ) );
24
  <ul style="list-style:disc outside none; margin-left:2em;">
25
  <li><?php _e( "group_id as the column title", 'import-users-from-csv-with-meta' ); ?></li>
26
  <li><?php _e( "The value of each cell will be the ID of the group that you want to assign to this user", 'import-users-from-csv-with-meta' ); ?></li>
27
+ <li><?php _e( "Another option is use group_name as the column title", 'import-users-from-csv-with-meta' ); ?></li>
28
+ <li><?php _e( "The value of each cell will be the name of the group that you want to assign to this user", 'import-users-from-csv-with-meta' ); ?></li>
29
  <li><?php _e( "If you want to import multiple values, you can use a list using commas to separate items", 'import-users-from-csv-with-meta' ); ?></li>
30
  </ul>
31
  </td>
44
  $user_groups_csv = array_filter( $user_groups_csv, function( $value ){ return $value !== ''; } );
45
 
46
  // groups that user belongs to
47
+ $groups_user = new Groups_User( $user_id );
48
  $user_group_ids = $groups_user->group_ids;
49
 
50
+ acui_g_add_groups_user( $user_id, $user_groups_csv );
51
+ }
52
+
53
+ function acui_g_post_import_single_user_by_name( $headers, $row, $user_id ){
54
+ $pos = array_search( 'group_name', $headers );
55
+
56
+ if( $pos === FALSE )
57
+ return;
58
+
59
+ // groups that appears in the CSV
60
+ $user_groups_name_csv = explode( ',', $row[ $pos ] );
61
+ $user_groups_name_csv = array_filter( $user_groups_name_csv, function( $value ){ return $value !== ''; } );
62
+ $user_groups_csv = array();
63
+
64
+ foreach ( $user_groups_name_csv as $user_group_name_csv ) {
65
+ $group = Groups_Group::read_by_name( $user_group_name_csv );
66
+ $user_groups_csv[] = $group->group_id;
67
+ }
68
+
69
+ acui_g_add_groups_user( $user_id, $user_groups_csv );
70
+ }
71
+
72
+ function acui_g_add_groups_user( $user_id, $user_groups_csv ){
73
+ // groups that user belongs to
74
+ $groups_user = new Groups_User( $user_id );
75
+ $user_group_ids = empty( $groups_user->group_ids ) ? array() : $groups_user->group_ids;
76
+
77
  // first we look into all current user groups, if they do not appear in CSV it will be removed
78
  foreach ( $user_group_ids as $user_group_id ) {
79
  if( !in_array( $user_group_id, $user_groups_csv ) )
80
  Groups_User_Group::delete( $user_id, $user_group_id );
81
  }
82
+
83
  // finally we loop into groups that are present in CSV data, if they already exists, we do nothing, if not, we add it
84
  foreach ( $user_groups_csv as $user_group_csv ) {
85
  if( !in_array( $user_group_csv, $user_group_ids ) )
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.15.5.4
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.15.5.5
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
importer.php CHANGED
@@ -732,7 +732,7 @@ function acui_options(){
732
 
733
  switch ( $tab ){
734
  case 'homepage':
735
- update_option( 'acui_last_roles_used', array_map( 'sanitize_text_field', $_POST['role'] ) );
736
  acui_fileupload_process( $_POST, false );
737
  return;
738
  break;
732
 
733
  switch ( $tab ){
734
  case 'homepage':
735
+ update_option( 'acui_last_roles_used', ( empty( $_POST['role'] ) ? '' : array_map( 'sanitize_text_field', $_POST['role'] ) ) );
736
  acui_fileupload_process( $_POST, false );
737
  return;
738
  break;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://codection.com/go/donate-import-users-from-csv-with-meta/
4
  Tags: csv, import, importer, meta data, meta, user, users, user meta, editor, profile, custom, fields, delimiter, update, insert
5
  Requires at least: 3.4
6
  Tested up to: 5.3.2
7
- Stable tag: 1.15.5.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -98,6 +98,9 @@ Plugin will automatically detect:
98
 
99
  == Changelog ==
100
 
 
 
 
101
  = 1.15.5.4 =
102
  * Bug fixed in frontend import, roles being updated when it shouldn't be updated thanks to @widevents for reporting (https://wordpress.org/support/topic/change-role-of-users-that-are-not-present-in-the-csv-works-without-ckeckbox-on/)
103
 
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.3.2
7
+ Stable tag: 1.15.5.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
98
 
99
  == Changelog ==
100
 
101
+ = 1.15.5.5 =
102
+ * Groups can be now imported by their name instead only of their ids
103
+
104
  = 1.15.5.4 =
105
  * Bug fixed in frontend import, roles being updated when it shouldn't be updated thanks to @widevents for reporting (https://wordpress.org/support/topic/change-role-of-users-that-are-not-present-in-the-csv-works-without-ckeckbox-on/)
106