Import users from CSV with meta - Version 1.15.5.11

Version Description

  • Deletion process performance improved
  • Now you can specify if only want to delete users of specified role using a new attribute in the frontend import
Download this release

Release Info

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

Code changes from version 1.15.5.10 to 1.15.5.11

classes/frontend.php CHANGED
@@ -57,6 +57,12 @@ class ACUI_Frontend{
57
  </td>
58
  </tr>
59
 
 
 
 
 
 
 
60
  <tr class="form-field form-required">
61
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
62
  <td>
@@ -237,7 +243,7 @@ class ACUI_Frontend{
237
  }
238
 
239
  function shortcode( $atts ) {
240
- $atts = shortcode_atts( array( 'role' => '' ), $atts );
241
 
242
  ob_start();
243
 
@@ -262,6 +268,9 @@ class ACUI_Frontend{
262
  $form_data[ "sends_email" ] = get_option( "acui_frontend_send_mail" );
263
  $form_data[ "send_email_updated" ] = get_option( "acui_frontend_send_mail_updated" );
264
 
 
 
 
265
  // update
266
  $form_data["update_existing_users" ] = empty( get_option( "acui_frontend_update_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_existing_users" );
267
  $form_data["update_roles_existing_users" ] = empty( get_option( "acui_frontend_update_roles_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_roles_existing_users" );
@@ -269,9 +278,7 @@ class ACUI_Frontend{
269
  // delete
270
  $form_data["delete_users"] = ( get_option( "acui_frontend_delete_users" ) ) ? 'yes' : 'no';
271
  $form_data["delete_users_assign_posts"] = get_option( "acui_frontend_delete_users_assign_posts" );
272
-
273
- // roles
274
- $form_data[ "role" ] = empty( $atts['role'] ) ? get_option( "acui_frontend_role") : $atts['role'];
275
 
276
  // others
277
  $form_data[ "empty_cell_action" ] = "leave";
@@ -281,7 +288,7 @@ class ACUI_Frontend{
281
 
282
  wp_delete_attachment( $csv_file_id, true );
283
 
284
- do_action ( 'acui_post_frontend_import' );
285
  else:
286
  ?>
287
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8" class="acui_frontend_form">
57
  </td>
58
  </tr>
59
 
60
+ <tr class="form-field">
61
+ <th scope="row"><label for=""><?php _e( 'Attribute delete-only-specified-role', 'import-users-from-csv-with-meta' ); ?></label></th>
62
+ <td><?php _e( 'You can use this attribute to make delete only users of the specified role that are not present in the CSV, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[import-users-from-csv-with-meta role="editor" delete-only-specified-role="true"]</pre> <?php _e( 'will only delete (if the deletion is active) the users not present in the CSV with are editors', 'import-users-from-csv-with-meta' ); ?>
63
+ </td>
64
+ </tr>
65
+
66
  <tr class="form-field form-required">
67
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
68
  <td>
243
  }
244
 
245
  function shortcode( $atts ) {
246
+ $atts = shortcode_atts( array( 'role' => '', 'delete-only-specified-role' => false ), $atts );
247
 
248
  ob_start();
249
 
268
  $form_data[ "sends_email" ] = get_option( "acui_frontend_send_mail" );
269
  $form_data[ "send_email_updated" ] = get_option( "acui_frontend_send_mail_updated" );
270
 
271
+ // roles
272
+ $form_data[ "role" ] = empty( $atts['role'] ) ? get_option( "acui_frontend_role") : $atts['role'];
273
+
274
  // update
275
  $form_data["update_existing_users" ] = empty( get_option( "acui_frontend_update_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_existing_users" );
276
  $form_data["update_roles_existing_users" ] = empty( get_option( "acui_frontend_update_roles_existing_users" ) ) ? 'no' : get_option( "acui_frontend_update_roles_existing_users" );
278
  // delete
279
  $form_data["delete_users"] = ( get_option( "acui_frontend_delete_users" ) ) ? 'yes' : 'no';
280
  $form_data["delete_users_assign_posts"] = get_option( "acui_frontend_delete_users_assign_posts" );
281
+ $form_data["delete_users_only_specified_role"] = empty( $form_data[ "role" ] ) ? false : $atts['delete-only-specified-role'];
 
 
282
 
283
  // others
284
  $form_data[ "empty_cell_action" ] = "leave";
288
 
289
  wp_delete_attachment( $csv_file_id, true );
290
 
291
+ do_action( 'acui_post_frontend_import' );
292
  else:
293
  ?>
294
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8" class="acui_frontend_form">
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.10
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.11
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
importer.php CHANGED
@@ -49,6 +49,8 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
49
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
50
  $delete_users = isset( $form_data["delete_users"] ) ? sanitize_text_field( $form_data["delete_users"] ) : '';
51
  $delete_users_assign_posts = isset( $form_data["delete_users_assign_posts"] ) ? sanitize_text_field( $form_data["delete_users_assign_posts"] ) : '';
 
 
52
  $change_role_not_present = isset( $form_data["change_role_not_present"] ) ? sanitize_text_field( $form_data["change_role_not_present"] ) : '';
53
  $change_role_not_present_role = isset( $form_data["change_role_not_present_role"] ) ? sanitize_text_field( $form_data["change_role_not_present_role"] ) : '';
54
  $activate_users_wp_members = ( !isset( $form_data["activate_users_wp_members"] ) || empty( $form_data["activate_users_wp_members"] ) ) ? "no_activate" : sanitize_text_field( $form_data["activate_users_wp_members"] );
@@ -667,20 +669,23 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
667
  if( $delete_users_flag ):
668
  require_once( ABSPATH . 'wp-admin/includes/user.php');
669
 
670
- $all_users = get_users( array(
671
  'fields' => array( 'ID' ),
672
  'role__not_in' => array( 'administrator' )
673
- ) );
674
 
675
- foreach ( $all_users as $user ) {
676
- if( !in_array( $user->ID, $users_registered ) ){
677
- if( !empty( $delete_users_assign_posts ) && get_userdata( $delete_users_assign_posts ) !== false ){
678
- wp_delete_user( $user->ID, $delete_users_assign_posts );
679
- }
680
- else{
681
- wp_delete_user( $user->ID );
682
- }
683
- }
 
 
 
684
  }
685
  endif;
686
 
49
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? sanitize_text_field( $form_data["empty_cell_action"] ) : '';
50
  $delete_users = isset( $form_data["delete_users"] ) ? sanitize_text_field( $form_data["delete_users"] ) : '';
51
  $delete_users_assign_posts = isset( $form_data["delete_users_assign_posts"] ) ? sanitize_text_field( $form_data["delete_users_assign_posts"] ) : '';
52
+ $delete_users_only_specified_role = isset( $form_data["delete_users_only_specified_role"] ) ? sanitize_text_field( $form_data["delete_users_only_specified_role"] ) : false;
53
+
54
  $change_role_not_present = isset( $form_data["change_role_not_present"] ) ? sanitize_text_field( $form_data["change_role_not_present"] ) : '';
55
  $change_role_not_present_role = isset( $form_data["change_role_not_present_role"] ) ? sanitize_text_field( $form_data["change_role_not_present_role"] ) : '';
56
  $activate_users_wp_members = ( !isset( $form_data["activate_users_wp_members"] ) || empty( $form_data["activate_users_wp_members"] ) ) ? "no_activate" : sanitize_text_field( $form_data["activate_users_wp_members"] );
669
  if( $delete_users_flag ):
670
  require_once( ABSPATH . 'wp-admin/includes/user.php');
671
 
672
+ $args = array(
673
  'fields' => array( 'ID' ),
674
  'role__not_in' => array( 'administrator' )
675
+ );
676
 
677
+ if( $delete_users_only_specified_role ){
678
+ $args[ 'role__in' ] = $role_default;
679
+ }
680
+
681
+ $all_users = get_users( $args );
682
+ $all_users_ids = array_map( function( $element ){ return intval( $element->ID ); }, $all_users );
683
+ $users_to_remove = array_diff( $all_users_ids, $users_registered );
684
+
685
+ $delete_users_assign_posts = ( get_userdata( $delete_users_assign_posts ) === false ) ? false : $delete_users_assign_posts;
686
+
687
+ foreach ( $users_to_remove as $user_id ) {
688
+ ( empty( $delete_users_assign_posts ) ) ? wp_delete_user( $user_id ) : wp_delete_user( $user_id, $delete_users_assign_posts );
689
  }
690
  endif;
691
 
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.4
7
- Stable tag: 1.15.5.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -99,6 +99,10 @@ Plugin will automatically detect:
99
 
100
  == Changelog ==
101
 
 
 
 
 
102
  = 1.15.5.10 =
103
  * Extra profile fields now can be reseted
104
 
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.4
7
+ Stable tag: 1.15.5.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
99
 
100
  == Changelog ==
101
 
102
+ = 1.15.5.11 =
103
+ * Deletion process performance improved
104
+ * Now you can specify if only want to delete users of specified role using a new attribute in the frontend import
105
+
106
  = 1.15.5.10 =
107
  * Extra profile fields now can be reseted
108