Import users from CSV with meta - Version 1.17.3.2

Version Description

  • Improved BuddyPress group management when importing, now you can remove users from a group
  • Improved BuddyPress import, now you can use group ids and not only group slugs
Download this release

Release Info

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

Code changes from version 1.17.3.1 to 1.17.3.2

addons/buddypress.php CHANGED
@@ -25,7 +25,7 @@ class ACUI_Buddypress{
25
  add_action( 'acui_documentation_after_plugins_activated', array( $this, 'documentation' ) );
26
  add_filter( 'acui_export_columns', array( $this, 'export_columns' ), 10, 1 );
27
  add_filter( 'acui_export_data', array( $this, 'export_data' ), 10, 3 );
28
- add_action( 'post_acui_import_single_user', array( $this, 'import' ), 10, 3 );
29
  add_action( 'post_acui_import_single_user', array( $this, 'import_avatar' ), 10, 3 );
30
  }
31
 
@@ -133,9 +133,11 @@ class ACUI_Buddypress{
133
  <ul style="list-style:disc outside none; margin-left:2em;">
134
  <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>
135
  <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>
136
- <li><?php _e( "And the role assigned in this group: <em>Administrator, Moderator or Member</em>", 'import-users-from-csv-with-meta' ); ?></li>
 
137
  <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>
138
- <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>
 
139
  <li><?php _e( "If you get some error of this kind:", 'import-users-from-csv-with-meta' ); ?> <code>Fatal error: Class 'BP_XProfile_Group'</code> <?php _e( "please enable Buddypress Extended Profile then import the csv file. You can then disable this afterwards", 'import-users-from-csv-with-meta' ); ?></li>
140
  </ul>
141
  </td>
@@ -148,7 +150,7 @@ class ACUI_Buddypress{
148
  $row[] = $key;
149
  }
150
 
151
- $row[] = 'bp_group';
152
  $row[] = 'bp_member_type';
153
 
154
  return $row;
@@ -165,7 +167,9 @@ class ACUI_Buddypress{
165
  return $row;
166
  }
167
 
168
- function import( $headers, $row, $user_id ){
 
 
169
  foreach( $this->fields as $field ){
170
  $pos = array_search( $field, $headers );
171
 
@@ -205,23 +209,31 @@ class ACUI_Buddypress{
205
  }
206
 
207
  $pos_bp_group = array_search( 'bp_group', $headers );
 
208
  $pos_bp_group_role = array_search( 'bp_group_role', $headers );
209
- if( $pos_bp_group !== FALSE ){
 
210
  $groups = explode( ',', $row[ $pos_bp_group ] );
211
  $groups_role = explode( ',', $row[ $pos_bp_group_role ] );
212
 
213
- for( $j = 0; $j < count( $groups ); $j++ ){
214
- $group_id = BP_Groups_Group::group_exists( $groups[ $j ] );
215
 
216
  if( !empty( $group_id ) ){
217
- groups_join_group( $group_id, $user_id );
 
 
 
218
 
219
- if( $groups_role[ $j ] == 'Moderator' ){
220
- groups_promote_member( $user_id, $group_id, 'mod' );
221
- }
222
- elseif( $groups_role[ $j ] == 'Administrator' ){
223
- groups_promote_member( $user_id, $group_id, 'admin' );
224
- }
 
 
 
225
  }
226
  }
227
  }
@@ -232,6 +244,25 @@ class ACUI_Buddypress{
232
  }
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  function import_avatar( $headers, $row, $user_id ){
236
  $pos = array_search( 'bp_avatar', $headers );
237
 
25
  add_action( 'acui_documentation_after_plugins_activated', array( $this, 'documentation' ) );
26
  add_filter( 'acui_export_columns', array( $this, 'export_columns' ), 10, 1 );
27
  add_filter( 'acui_export_data', array( $this, 'export_data' ), 10, 3 );
28
+ add_action( 'post_acui_import_single_user', array( $this, 'import' ), 10, 6 );
29
  add_action( 'post_acui_import_single_user', array( $this, 'import_avatar' ), 10, 3 );
30
  }
31
 
133
  <ul style="list-style:disc outside none; margin-left:2em;">
134
  <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>
135
  <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>
136
+ <li><?php _e( "And the role assigned in this group:", 'import-users-from-csv-with-meta' ); ?> <em>Administrator, Moderator or Member</em></li>
137
+ <li><?php _e( "You can also use group ids if you know it using a column 'bp_group_id' instead of 'bp_group'", 'import-users-from-csv-with-meta' ); ?></li>
138
  <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>
139
+ <li><?php _e( "But you will have to assign a role for each group:", 'import-users-from-csv-with-meta' ); ?> <em>Moderator,Moderator,Member,Member</em></li>
140
+ <li><?php _e( "If you choose to update roles and group role is empty, user will be removed from the group", 'import-users-from-csv-with-meta' ); ?></li>
141
  <li><?php _e( "If you get some error of this kind:", 'import-users-from-csv-with-meta' ); ?> <code>Fatal error: Class 'BP_XProfile_Group'</code> <?php _e( "please enable Buddypress Extended Profile then import the csv file. You can then disable this afterwards", 'import-users-from-csv-with-meta' ); ?></li>
142
  </ul>
143
  </td>
150
  $row[] = $key;
151
  }
152
 
153
+ $row[] = 'bp_group_id';
154
  $row[] = 'bp_member_type';
155
 
156
  return $row;
167
  return $row;
168
  }
169
 
170
+ function import( $headers, $row, $user_id, $role, $positions, $form_data ){
171
+ $update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? sanitize_text_field( $form_data["update_roles_existing_users"] ) : '';
172
+
173
  foreach( $this->fields as $field ){
174
  $pos = array_search( $field, $headers );
175
 
209
  }
210
 
211
  $pos_bp_group = array_search( 'bp_group', $headers );
212
+ $pos_bp_group_id = array_search( 'bp_group_id', $headers );
213
  $pos_bp_group_role = array_search( 'bp_group_role', $headers );
214
+
215
+ if( $pos_bp_group !== FALSE ){
216
  $groups = explode( ',', $row[ $pos_bp_group ] );
217
  $groups_role = explode( ',', $row[ $pos_bp_group_role ] );
218
 
219
+ for( $j = 0; $j < count( $groups ); $j++ ){
220
+ $group_id = BP_Groups_Group::group_exists( intval( $groups[ $j ] ) );
221
 
222
  if( !empty( $group_id ) ){
223
+ $this->add_user_group( $user_id, $group_id, $groups_role[ $j ], $update_roles_existing_users );
224
+ }
225
+ }
226
+ }
227
 
228
+ if( $pos_bp_group_id !== FALSE ){
229
+ $groups_id = explode( ',', $row[ $pos_bp_group_id ] );
230
+ $groups_role = explode( ',', $row[ $pos_bp_group_role ] );
231
+
232
+ for( $j = 0; $j < count( $groups_id ); $j++ ){
233
+ $group_id = intval( $groups_id[ $j ] );
234
+
235
+ if( !empty( $group_id ) ){
236
+ $this->add_user_group( $user_id, $group_id, $groups_role[ $j ], $update_roles_existing_users );
237
  }
238
  }
239
  }
244
  }
245
  }
246
 
247
+ function add_user_group( $user_id, $group_id, $group_role, $update_roles_existing_users ){
248
+ if( $update_roles_existing_users == 'yes' || $update_roles_existing_users == 'yes_no_override' ){
249
+ $member = new BP_Groups_Member( $user_id, $group_id );
250
+ $member->remove();
251
+ }
252
+
253
+ if( ( $update_roles_existing_users == 'yes' || $update_roles_existing_users == 'yes_no_override' ) && empty( $group_role ) )
254
+ return;
255
+
256
+ groups_join_group( $group_id, $user_id );
257
+
258
+ if( $group_role == 'Moderator' ){
259
+ groups_promote_member( $user_id, $group_id, 'mod' );
260
+ }
261
+ elseif( $group_role == 'Administrator' ){
262
+ groups_promote_member( $user_id, $group_id, 'admin' );
263
+ }
264
+ }
265
+
266
  function import_avatar( $headers, $row, $user_id ){
267
  $pos = array_search( 'bp_avatar', $headers );
268
 
classes/rest-api.php CHANGED
@@ -5,6 +5,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
5
  class ACUI_REST_API{
6
  function __construct(){
7
  add_action( 'rest_api_init', array( $this, 'init' ) );
 
8
  }
9
 
10
  function init() {
5
  class ACUI_REST_API{
6
  function __construct(){
7
  add_action( 'rest_api_init', array( $this, 'init' ) );
8
+ add_filter( 'acui_rest_api_permission_callback', function(){ return true; } );
9
  }
10
 
11
  function init() {
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.3.1
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.17.3.2
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
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.6
7
- Stable tag: 1.17.3.1
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.3.1 =
107
  * New filter to override default permission_callback in rest-api method to call cron
108
 
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.17.3.2
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.3.2 =
107
+ * Improved BuddyPress group management when importing, now you can remove users from a group
108
+ * Improved BuddyPress import, now you can use group ids and not only group slugs
109
+
110
  = 1.17.3.1 =
111
  * New filter to override default permission_callback in rest-api method to call cron
112