Import users from CSV with meta - Version 1.13

Version Description

  • Now you can delete users that are not in the CSV file, not only when you are doing an import based on a cron task, but also when you do it from the dashboard or with the shortcode in the frontend thanks to mojosolo.com
  • Documentation improved
  • Bug fixed
  • Tested up to 5.1
Download this release

Release Info

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

Code changes from version 1.12.6.2 to 1.13

classes/cron.php CHANGED
@@ -64,6 +64,7 @@ class ACUI_Cron{
64
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8">
65
  <table class="form-table">
66
  <tbody>
 
67
  <tr class="form-field">
68
  <th scope="row"><label for="path_to_file"><?php _e( "Path of file that are going to be imported", 'import-users-from-csv-with-meta' ); ?></label></th>
69
  <td>
@@ -71,6 +72,7 @@ class ACUI_Cron{
71
  <p class="description"><?php _e( 'You have to introduce the path to file, i.e.:', 'import-users-from-csv-with-meta' ); ?> <?php $upload_dir = wp_upload_dir(); echo $upload_dir["path"]; ?>/test.csv</p>
72
  </td>
73
  </tr>
 
74
  <tr class="form-field form-required">
75
  <th scope="row"><label for="period"><?php _e( 'Period', 'import-users-from-csv-with-meta' ); ?></label></th>
76
  <td>
@@ -82,18 +84,21 @@ class ACUI_Cron{
82
  <p class="description"><?php _e( 'How often the event should reoccur?', 'import-users-from-csv-with-meta' ); ?></p>
83
  </td>
84
  </tr>
 
85
  <tr class="form-field form-required">
86
  <th scope="row"><label for="cron-activated"><?php _e( 'Activate periodical import?', 'import-users-from-csv-with-meta' ); ?></label></th>
87
  <td>
88
  <input type="checkbox" name="cron-activated" value="yes" <?php if( $cron_activated == true ) echo "checked='checked'"; ?>/>
89
  </td>
90
  </tr>
 
91
  <tr class="form-field form-required">
92
  <th scope="row"><label for="send-mail-cron"><?php _e( 'Send mail when using periodical import?', 'import-users-from-csv-with-meta' ); ?></label></th>
93
  <td>
94
  <input type="checkbox" name="send-mail-cron" value="yes" <?php if( $send_mail_cron == true ) echo "checked='checked'"; ?>/>
95
  </td>
96
  </tr>
 
97
  <tr class="form-field form-required">
98
  <th scope="row"><label for="send-mail-updated"><?php _e( 'Send mail also to users that are being updated?', 'import-users-from-csv-with-meta' ); ?></label></th>
99
  <td>
@@ -141,6 +146,7 @@ class ACUI_Cron{
141
  </div>
142
  </td>
143
  </tr>
 
144
  <tr class="form-field form-required">
145
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
146
  <td>
@@ -163,6 +169,7 @@ class ACUI_Cron{
163
  <p class="description"><?php _e( 'Which role would be used to import users?', 'import-users-from-csv-with-meta' ); ?></p>
164
  </td>
165
  </tr>
 
166
  <tr class="form-field form-required">
167
  <th scope="row"><label for="update-roles-existing-users"><?php _e( 'Update roles for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
168
  <td>
@@ -183,6 +190,7 @@ class ACUI_Cron{
183
  </div>
184
  </td>
185
  </tr>
 
186
  <tr class="form-field form-required move-file-cron-cell">
187
  <th scope="row"><label for="move-file-cron"><?php _e( 'Auto rename after move?', 'import-users-from-csv-with-meta' ); ?></label></th>
188
  <td>
@@ -194,13 +202,15 @@ class ACUI_Cron{
194
  <p class="description"><?php _e( 'Your file will be renamed after moved, so you will not lost any version of it. The way to rename will be append the time stamp using this date format: YmdHis.', 'import-users-from-csv-with-meta'); ?></p>
195
  </div>
196
  </td>
197
- </tr>
 
198
  <tr class="form-field form-required">
199
  <th scope="row"><label for="log"><?php _e( 'Last actions of schedule task', 'import-users-from-csv-with-meta' ); ?></label></th>
200
  <td>
201
  <pre><?php echo $log; ?></pre>
202
  </td>
203
  </tr>
 
204
  </tbody>
205
  </table>
206
  <input class="button-primary" type="submit" value="<?php _e( 'Save schedule options', 'import-users-from-csv-with-meta'); ?>"/>
64
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8">
65
  <table class="form-table">
66
  <tbody>
67
+
68
  <tr class="form-field">
69
  <th scope="row"><label for="path_to_file"><?php _e( "Path of file that are going to be imported", 'import-users-from-csv-with-meta' ); ?></label></th>
70
  <td>
72
  <p class="description"><?php _e( 'You have to introduce the path to file, i.e.:', 'import-users-from-csv-with-meta' ); ?> <?php $upload_dir = wp_upload_dir(); echo $upload_dir["path"]; ?>/test.csv</p>
73
  </td>
74
  </tr>
75
+
76
  <tr class="form-field form-required">
77
  <th scope="row"><label for="period"><?php _e( 'Period', 'import-users-from-csv-with-meta' ); ?></label></th>
78
  <td>
84
  <p class="description"><?php _e( 'How often the event should reoccur?', 'import-users-from-csv-with-meta' ); ?></p>
85
  </td>
86
  </tr>
87
+
88
  <tr class="form-field form-required">
89
  <th scope="row"><label for="cron-activated"><?php _e( 'Activate periodical import?', 'import-users-from-csv-with-meta' ); ?></label></th>
90
  <td>
91
  <input type="checkbox" name="cron-activated" value="yes" <?php if( $cron_activated == true ) echo "checked='checked'"; ?>/>
92
  </td>
93
  </tr>
94
+
95
  <tr class="form-field form-required">
96
  <th scope="row"><label for="send-mail-cron"><?php _e( 'Send mail when using periodical import?', 'import-users-from-csv-with-meta' ); ?></label></th>
97
  <td>
98
  <input type="checkbox" name="send-mail-cron" value="yes" <?php if( $send_mail_cron == true ) echo "checked='checked'"; ?>/>
99
  </td>
100
  </tr>
101
+
102
  <tr class="form-field form-required">
103
  <th scope="row"><label for="send-mail-updated"><?php _e( 'Send mail also to users that are being updated?', 'import-users-from-csv-with-meta' ); ?></label></th>
104
  <td>
146
  </div>
147
  </td>
148
  </tr>
149
+
150
  <tr class="form-field form-required">
151
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
152
  <td>
169
  <p class="description"><?php _e( 'Which role would be used to import users?', 'import-users-from-csv-with-meta' ); ?></p>
170
  </td>
171
  </tr>
172
+
173
  <tr class="form-field form-required">
174
  <th scope="row"><label for="update-roles-existing-users"><?php _e( 'Update roles for existing users?', 'import-users-from-csv-with-meta' ); ?></label></th>
175
  <td>
190
  </div>
191
  </td>
192
  </tr>
193
+
194
  <tr class="form-field form-required move-file-cron-cell">
195
  <th scope="row"><label for="move-file-cron"><?php _e( 'Auto rename after move?', 'import-users-from-csv-with-meta' ); ?></label></th>
196
  <td>
202
  <p class="description"><?php _e( 'Your file will be renamed after moved, so you will not lost any version of it. The way to rename will be append the time stamp using this date format: YmdHis.', 'import-users-from-csv-with-meta'); ?></p>
203
  </div>
204
  </td>
205
+ </tr>
206
+
207
  <tr class="form-field form-required">
208
  <th scope="row"><label for="log"><?php _e( 'Last actions of schedule task', 'import-users-from-csv-with-meta' ); ?></label></th>
209
  <td>
210
  <pre><?php echo $log; ?></pre>
211
  </td>
212
  </tr>
213
+
214
  </tbody>
215
  </table>
216
  <input class="button-primary" type="submit" value="<?php _e( 'Save schedule options', 'import-users-from-csv-with-meta'); ?>"/>
classes/doc.php CHANGED
@@ -21,7 +21,7 @@ class ACUI_Doc{
21
  </td>
22
  </tr>
23
  <tr valign="top">
24
- <th scope="row"><?php _e( 'id', 'import-users-from-csv-with-meta' ); ?></th>
25
  <td><?php _e( 'You can use a column called id in order to make inserts or updates of an user using the ID used by WordPress in the wp_users table. We have two different cases:', 'import-users-from-csv-with-meta' ); ?>
26
  <ul style="list-style:disc outside none; margin-left:2em;">
27
  <li><?php _e( "If id <strong>doesn't exist in your users table</strong>: WordPress core does not allow us insert it, so it will throw an error of kind: invalid_user_id", 'import-users-from-csv-with-meta' ); ?></li>
@@ -30,7 +30,7 @@ class ACUI_Doc{
30
  </td>
31
  </tr>
32
  <tr valign="top">
33
- <th scope="row"><?php _e( "Passwords", 'import-users-from-csv-with-meta' ); ?></th>
34
  <td><?php _e( "A string that contains user passwords. We have different options for this case:", 'import-users-from-csv-with-meta' ); ?>
35
  <ul style="list-style:disc outside none; margin-left:2em;">
36
  <li><?php _e( "If you <strong>don't create a column for passwords</strong>: passwords will be generated automatically", 'import-users-from-csv-with-meta' ); ?></li>
@@ -39,7 +39,7 @@ class ACUI_Doc{
39
  </td>
40
  </tr>
41
  <tr valign="top">
42
- <th scope="row"><?php _e( "Roles", 'import-users-from-csv-with-meta' ); ?></th>
43
  <td><?php _e( "Plugin can import roles from the CSV. This is how it works:", 'import-users-from-csv-with-meta' ); ?>
44
  <ul style="list-style:disc outside none; margin-left:2em;">
45
  <li><?php _e( "If you <strong>don't create a column for roles</strong>: roles would be chosen from the 'Default role' field in import screen.", 'import-users-from-csv-with-meta' ); ?></li>
21
  </td>
22
  </tr>
23
  <tr valign="top">
24
+ <th scope="row"><?php _e( 'id (column id)', 'import-users-from-csv-with-meta' ); ?></th>
25
  <td><?php _e( 'You can use a column called id in order to make inserts or updates of an user using the ID used by WordPress in the wp_users table. We have two different cases:', 'import-users-from-csv-with-meta' ); ?>
26
  <ul style="list-style:disc outside none; margin-left:2em;">
27
  <li><?php _e( "If id <strong>doesn't exist in your users table</strong>: WordPress core does not allow us insert it, so it will throw an error of kind: invalid_user_id", 'import-users-from-csv-with-meta' ); ?></li>
30
  </td>
31
  </tr>
32
  <tr valign="top">
33
+ <th scope="row"><?php _e( "Passwords (column password)", 'import-users-from-csv-with-meta' ); ?></th>
34
  <td><?php _e( "A string that contains user passwords. We have different options for this case:", 'import-users-from-csv-with-meta' ); ?>
35
  <ul style="list-style:disc outside none; margin-left:2em;">
36
  <li><?php _e( "If you <strong>don't create a column for passwords</strong>: passwords will be generated automatically", 'import-users-from-csv-with-meta' ); ?></li>
39
  </td>
40
  </tr>
41
  <tr valign="top">
42
+ <th scope="row"><?php _e( "Roles (column role)", 'import-users-from-csv-with-meta' ); ?></th>
43
  <td><?php _e( "Plugin can import roles from the CSV. This is how it works:", 'import-users-from-csv-with-meta' ); ?>
44
  <ul style="list-style:disc outside none; margin-left:2em;">
45
  <li><?php _e( "If you <strong>don't create a column for roles</strong>: roles would be chosen from the 'Default role' field in import screen.", 'import-users-from-csv-with-meta' ); ?></li>
classes/frontend.php CHANGED
@@ -4,10 +4,12 @@ if ( ! defined( 'ABSPATH' ) ) exit;
4
 
5
  class ACUI_Frontend{
6
  public static function admin_gui(){
7
- $send_mail_frontend = get_option( "acui_frontend_send_mail");
8
- $send_mail_updated_frontend = get_option( "acui_frontend_send_mail_updated");
9
- $role = get_option( "acui_frontend_role");
10
- $activate_users_wp_members = get_option( "acui_frontend_activate_users_wp_members");
 
 
11
 
12
  if( empty( $send_mail_frontend ) )
13
  $send_mail_frontend = false;
@@ -20,6 +22,7 @@ class ACUI_Frontend{
20
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8">
21
  <table class="form-table">
22
  <tbody>
 
23
  <tr class="form-field">
24
  <th scope="row"><label for=""><?php _e( 'Use this shortcode in any page or post', 'import-users-from-csv-with-meta' ); ?></label></th>
25
  <td>
@@ -27,18 +30,50 @@ class ACUI_Frontend{
27
  <input class="button-primary" type="button" id="copy_to_clipboard" value="<?php _e( 'Copy to clipboard', 'import-users-from-csv-with-meta'); ?>"/>
28
  </td>
29
  </tr>
 
30
  <tr class="form-field form-required">
31
  <th scope="row"><label for="send-mail-frontend"><?php _e( 'Send mail when using frontend import?', 'import-users-from-csv-with-meta' ); ?></label></th>
32
  <td>
33
  <input type="checkbox" name="send-mail-frontend" value="yes" <?php if( $send_mail_frontend == true ) echo "checked='checked'"; ?>/>
34
  </td>
35
  </tr>
 
36
  <tr class="form-field form-required">
37
  <th scope="row"><label for="send-mail-updated-frontend"><?php _e( 'Send mail also to users that are being updated?', 'import-users-from-csv-with-meta' ); ?></label></th>
38
  <td>
39
  <input type="checkbox" name="send-mail-updated-frontend" value="yes" <?php if( $send_mail_updated_frontend == true ) echo "checked='checked'"; ?>/>
40
  </td>
41
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  <tr class="form-field form-required">
43
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
44
  <td>
@@ -67,7 +102,7 @@ class ACUI_Frontend{
67
  <tr class="form-field form-required">
68
  <th scope="row"><label>Activate user when they are being imported?</label></th>
69
  <td>
70
- <select name="activate_users_wp_members">
71
  <option value="no_activate" <?php selected( $activate_users_wp_members,'no_activate', true ); ?>><?php _e( 'Do not activate users', 'import-users-from-csv-with-meta' ); ?></option>
72
  <option value="activate" <?php selected( $activate_users_wp_members,'activate', true ); ?>><?php _e( 'Activate users when they are being imported', 'import-users-from-csv-with-meta' ); ?></option>
73
  </select>
4
 
5
  class ACUI_Frontend{
6
  public static function admin_gui(){
7
+ $send_mail_frontend = get_option( "acui_frontend_send_mail" );
8
+ $send_mail_updated_frontend = get_option( "acui_frontend_send_mail_updated" );
9
+ $delete_users_frontend = get_option( "acui_frontend_delete_users" );
10
+ $delete_users_assign_posts_frontend = get_option( "acui_frontend_delete_users_assign_posts" );
11
+ $role = get_option( "acui_frontend_role" );
12
+ $activate_users_wp_members = get_option( "acui_frontend_activate_users_wp_members" );
13
 
14
  if( empty( $send_mail_frontend ) )
15
  $send_mail_frontend = false;
22
  <form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8">
23
  <table class="form-table">
24
  <tbody>
25
+
26
  <tr class="form-field">
27
  <th scope="row"><label for=""><?php _e( 'Use this shortcode in any page or post', 'import-users-from-csv-with-meta' ); ?></label></th>
28
  <td>
30
  <input class="button-primary" type="button" id="copy_to_clipboard" value="<?php _e( 'Copy to clipboard', 'import-users-from-csv-with-meta'); ?>"/>
31
  </td>
32
  </tr>
33
+
34
  <tr class="form-field form-required">
35
  <th scope="row"><label for="send-mail-frontend"><?php _e( 'Send mail when using frontend import?', 'import-users-from-csv-with-meta' ); ?></label></th>
36
  <td>
37
  <input type="checkbox" name="send-mail-frontend" value="yes" <?php if( $send_mail_frontend == true ) echo "checked='checked'"; ?>/>
38
  </td>
39
  </tr>
40
+
41
  <tr class="form-field form-required">
42
  <th scope="row"><label for="send-mail-updated-frontend"><?php _e( 'Send mail also to users that are being updated?', 'import-users-from-csv-with-meta' ); ?></label></th>
43
  <td>
44
  <input type="checkbox" name="send-mail-updated-frontend" value="yes" <?php if( $send_mail_updated_frontend == true ) echo "checked='checked'"; ?>/>
45
  </td>
46
  </tr>
47
+
48
+ <tr class="form-field form-required">
49
+ <th scope="row"><label for="delete-users-frontend"><?php _e( 'Delete users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
50
+ <td>
51
+ <div style="float:left;">
52
+ <input type="checkbox" name="delete-users-frontend" value="yes" <?php if( $delete_users_frontend == true ) echo "checked='checked'"; ?>/>
53
+ </div>
54
+ <div style="margin-left:25px;">
55
+ <select id="delete-users-assign-posts-frontend" name="delete-users-assign-posts-frontend">
56
+ <?php
57
+ if( $delete_users_assign_posts_frontend == '' )
58
+ echo "<option selected='selected' value=''>" . __( 'Delete posts of deled users without assing to any user', 'import-users-from-csv-with-meta' ) . "</option>";
59
+ else
60
+ echo "<option value=''>" . __( 'Delete posts of deled users without assing to any user', 'import-users-from-csv-with-meta' ) . "</option>";
61
+
62
+ $blogusers = get_users();
63
+
64
+ foreach ( $blogusers as $bloguser ) {
65
+ if( $bloguser->ID == $delete_users_assign_posts_frontend )
66
+ echo "<option selected='selected' value='{$bloguser->ID}'>{$bloguser->display_name}</option>";
67
+ else
68
+ echo "<option value='{$bloguser->ID}'>{$bloguser->display_name}</option>";
69
+ }
70
+ ?>
71
+ </select>
72
+ <p class="description"><?php _e( 'After delete users, we can choose if we want to assign their posts to another user. Please do not delete them or posts will be deleted.', 'import-users-from-csv-with-meta' ); ?></p>
73
+ </div>
74
+ </td>
75
+ </tr>
76
+
77
  <tr class="form-field form-required">
78
  <th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
79
  <td>
102
  <tr class="form-field form-required">
103
  <th scope="row"><label>Activate user when they are being imported?</label></th>
104
  <td>
105
+ <select name="activate-users-wp-members-frontend">
106
  <option value="no_activate" <?php selected( $activate_users_wp_members,'no_activate', true ); ?>><?php _e( 'Do not activate users', 'import-users-from-csv-with-meta' ); ?></option>
107
  <option value="activate" <?php selected( $activate_users_wp_members,'activate', true ); ?>><?php _e( 'Activate users when they are being imported', 'import-users-from-csv-with-meta' ); ?></option>
108
  </select>
classes/homepage.php CHANGED
@@ -116,6 +116,28 @@ class ACUI_Homepage{
116
  </td>
117
  </tr>
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  <?php if( is_plugin_active( 'buddypress/bp-loader.php' ) ):
120
 
121
  if( !class_exists( "BP_XProfile_Group" ) ){
116
  </td>
117
  </tr>
118
 
119
+ <tr class="form-field form-required">
120
+ <th scope="row"><label for="delete_users"><?php _e( 'Delete users that are not present in the CSV?', 'import-users-from-csv-with-meta' ); ?></label></th>
121
+ <td>
122
+ <div style="float:left;">
123
+ <input type="checkbox" name="delete_users" value="yes"/>
124
+ </div>
125
+ <div style="margin-left:25px;">
126
+ <select id="delete_users_assign_posts" name="delete_users_assign_posts">
127
+ <option value=''><?php _e( 'Delete posts of deled users without assing to any user', 'import-users-from-csv-with-meta' ); ?></option>
128
+ <?php
129
+ $blogusers = get_users();
130
+
131
+ foreach ( $blogusers as $bloguser ) {
132
+ echo "<option value='{$bloguser->ID}'>{$bloguser->display_name}</option>";
133
+ }
134
+ ?>
135
+ </select>
136
+ <p class="description"><?php _e( 'After delete users, we can choose if we want to assign their posts to another user. Please do not delete them or posts will be deleted.', 'import-users-from-csv-with-meta' ); ?></p>
137
+ </div>
138
+ </td>
139
+ </tr>
140
+
141
  <?php if( is_plugin_active( 'buddypress/bp-loader.php' ) ):
142
 
143
  if( !class_exists( "BP_XProfile_Group" ) ){
import-users-from-csv-with-meta.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Import users from CSV with meta
4
  Plugin URI: https://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
- Version: 1.12.6.2
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
@@ -101,6 +101,7 @@ function acui_activate(){
101
  add_option( "acui_cron_send_mail", false );
102
  add_option( "acui_cron_send_mail_updated", false );
103
  add_option( "acui_cron_delete_users", false );
 
104
  add_option( "acui_cron_path_to_file" );
105
  add_option( "acui_cron_path_to_move" );
106
  add_option( "acui_cron_path_to_move_auto_rename" );
@@ -112,6 +113,8 @@ function acui_activate(){
112
 
113
  add_option( "acui_frontend_send_mail", false );
114
  add_option( "acui_frontend_send_mail_updated", false );
 
 
115
  add_option( "acui_frontend_role" );
116
 
117
  add_option( "acui_manually_send_mail", false );
@@ -149,6 +152,7 @@ function acui_delete_options(){
149
  delete_option( "acui_cron_send_mail" );
150
  delete_option( "acui_cron_send_mail_updated" );
151
  delete_option( "acui_cron_delete_users" );
 
152
  delete_option( "acui_cron_path_to_file" );
153
  delete_option( "acui_cron_path_to_move" );
154
  delete_option( "acui_cron_path_to_move_auto_rename" );
@@ -160,6 +164,8 @@ function acui_delete_options(){
160
 
161
  delete_option( "acui_frontend_send_mail" );
162
  delete_option( "acui_frontend_send_mail_updated" );
 
 
163
  delete_option( "acui_frontend_role" );
164
 
165
  delete_option( "acui_manually_send_mail" );
@@ -282,11 +288,11 @@ function acui_admin_tabs( $current = 'homepage' ) {
282
  $tabs = array(
283
  'homepage' => __( 'Import', 'import-users-from-csv-with-meta' ),
284
  'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
 
285
  'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
286
  'mail-options' => __( 'Mail options', 'import-users-from-csv-with-meta' ),
287
  'smtp-settings' => __( 'SMTP settings (deprecated)', 'import-users-from-csv-with-meta' ),
288
  'doc' => __( 'Documentation', 'import-users-from-csv-with-meta' ),
289
- 'cron' => __( 'Cron import', 'import-users-from-csv-with-meta' ),
290
  'donate' => __( 'Donate/Patreon', 'import-users-from-csv-with-meta' ),
291
  'shop' => __( 'Shop', 'import-users-from-csv-with-meta' ),
292
  'help' => __( 'Hire an expert', 'import-users-from-csv-with-meta' )
@@ -339,15 +345,11 @@ function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend =
339
 
340
  foreach ( $uploadfiles['name'] as $key => $value ) {
341
 
342
- // look only for uploded files
343
  if ($uploadfiles['error'][$key] == 0) {
344
  $filetmp = $uploadfiles['tmp_name'][$key];
345
 
346
- //clean filename and extract extension
347
  $filename = $uploadfiles['name'][$key];
348
 
349
- // get file info
350
- // @fixme: wp checks the file extension....
351
  $filetype = wp_check_filetype( basename( $filename ), array('csv' => 'text/csv') );
352
  $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
353
  $filename = $filetitle . '.' . $filetype['ext'];
@@ -358,10 +360,6 @@ function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend =
358
  return;
359
  }
360
 
361
- /**
362
- * Check if the filename already exist in the directory and rename the
363
- * file if necessary
364
- */
365
  $i = 0;
366
  while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
367
  $filename = $filetitle . '_' . $i . '.' . $filetype['ext'];
@@ -369,17 +367,11 @@ function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend =
369
  }
370
  $filedest = $upload_dir['path'] . '/' . $filename;
371
 
372
- /**
373
- * Check write permissions
374
- */
375
  if ( !is_writeable( $upload_dir['path'] ) ) {
376
  wp_die( __( 'Unable to write to directory. Is this directory writable by the server?', 'import-users-from-csv-with-meta' ));
377
  return;
378
  }
379
 
380
- /**
381
- * Save temporary file to uploads dir
382
- */
383
  if ( !@move_uploaded_file($filetmp, $filedest) ){
384
  wp_die( __( 'Error, the file', 'import-users-from-csv-with-meta' ) . " $filetmp " . __( 'could not moved to', 'import-users-from-csv-with-meta' ) . " : $filedest");
385
  continue;
@@ -415,8 +407,19 @@ function acui_manage_frontend_process( $form_data ){
415
  else
416
  update_option( "acui_frontend_send_mail_updated", false );
417
 
418
- update_option( "acui_frontend_activate_users_wp_members", $form_data["activate_users_wp_members"] );
419
- update_option( "acui_frontend_role", $form_data["acui_frontend_role"] );
 
 
 
 
 
 
 
 
 
 
 
420
  ?>
421
  <div class="updated">
422
  <p><?php _e( 'Settings updated correctly', 'import-users-from-csv-with-meta' ) ?></p>
3
  Plugin Name: Import users from CSV with meta
4
  Plugin URI: https://www.codection.com
5
  Description: This plugins allows to import users using CSV files to WP database automatically
6
+ Version: 1.13
7
  Author: codection
8
  Author URI: https://codection.com
9
  License: GPL2
101
  add_option( "acui_cron_send_mail", false );
102
  add_option( "acui_cron_send_mail_updated", false );
103
  add_option( "acui_cron_delete_users", false );
104
+ add_option( "acui_cron_delete_users_assign_posts" );
105
  add_option( "acui_cron_path_to_file" );
106
  add_option( "acui_cron_path_to_move" );
107
  add_option( "acui_cron_path_to_move_auto_rename" );
113
 
114
  add_option( "acui_frontend_send_mail", false );
115
  add_option( "acui_frontend_send_mail_updated", false );
116
+ add_option( "acui_frontend_delete_users", false );
117
+ add_option( "acui_frontend_delete_users_assign_posts" );
118
  add_option( "acui_frontend_role" );
119
 
120
  add_option( "acui_manually_send_mail", false );
152
  delete_option( "acui_cron_send_mail" );
153
  delete_option( "acui_cron_send_mail_updated" );
154
  delete_option( "acui_cron_delete_users" );
155
+ delete_option( "acui_cron_delete_users_assign_posts" );
156
  delete_option( "acui_cron_path_to_file" );
157
  delete_option( "acui_cron_path_to_move" );
158
  delete_option( "acui_cron_path_to_move_auto_rename" );
164
 
165
  delete_option( "acui_frontend_send_mail" );
166
  delete_option( "acui_frontend_send_mail_updated" );
167
+ delete_option( "acui_frontend_delete_users" );
168
+ delete_option( "acui_frontend_delete_users_assign_posts" );
169
  delete_option( "acui_frontend_role" );
170
 
171
  delete_option( "acui_manually_send_mail" );
288
  $tabs = array(
289
  'homepage' => __( 'Import', 'import-users-from-csv-with-meta' ),
290
  'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
291
+ 'cron' => __( 'Cron import', 'import-users-from-csv-with-meta' ),
292
  'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
293
  'mail-options' => __( 'Mail options', 'import-users-from-csv-with-meta' ),
294
  'smtp-settings' => __( 'SMTP settings (deprecated)', 'import-users-from-csv-with-meta' ),
295
  'doc' => __( 'Documentation', 'import-users-from-csv-with-meta' ),
 
296
  'donate' => __( 'Donate/Patreon', 'import-users-from-csv-with-meta' ),
297
  'shop' => __( 'Shop', 'import-users-from-csv-with-meta' ),
298
  'help' => __( 'Hire an expert', 'import-users-from-csv-with-meta' )
345
 
346
  foreach ( $uploadfiles['name'] as $key => $value ) {
347
 
 
348
  if ($uploadfiles['error'][$key] == 0) {
349
  $filetmp = $uploadfiles['tmp_name'][$key];
350
 
 
351
  $filename = $uploadfiles['name'][$key];
352
 
 
 
353
  $filetype = wp_check_filetype( basename( $filename ), array('csv' => 'text/csv') );
354
  $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
355
  $filename = $filetitle . '.' . $filetype['ext'];
360
  return;
361
  }
362
 
 
 
 
 
363
  $i = 0;
364
  while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
365
  $filename = $filetitle . '_' . $i . '.' . $filetype['ext'];
367
  }
368
  $filedest = $upload_dir['path'] . '/' . $filename;
369
 
 
 
 
370
  if ( !is_writeable( $upload_dir['path'] ) ) {
371
  wp_die( __( 'Unable to write to directory. Is this directory writable by the server?', 'import-users-from-csv-with-meta' ));
372
  return;
373
  }
374
 
 
 
 
375
  if ( !@move_uploaded_file($filetmp, $filedest) ){
376
  wp_die( __( 'Error, the file', 'import-users-from-csv-with-meta' ) . " $filetmp " . __( 'could not moved to', 'import-users-from-csv-with-meta' ) . " : $filedest");
377
  continue;
407
  else
408
  update_option( "acui_frontend_send_mail_updated", false );
409
 
410
+ if( isset( $form_data["delete-users-frontend"] ) && $form_data["delete-users-frontend"] == "yes" )
411
+ update_option( "acui_frontend_delete_users", true );
412
+ else
413
+ update_option( "acui_frontend_delete_users", false );
414
+
415
+ update_option( "acui_frontend_delete_users_assign_posts", $form_data["delete-users-assign-posts-frontend"] );
416
+
417
+ if( isset( $form_data["activate-users-wp-members-frontend"] ) )
418
+ update_option( "acui_frontend_activate_users_wp_members", $form_data["activate-users-wp-members-frontend"] );
419
+ else
420
+ update_option( "acui_frontend_activate_users_wp_members", 'no_activate' );
421
+
422
+ update_option( "acui_frontend_role", $form_data["role-frontend"] );
423
  ?>
424
  <div class="updated">
425
  <p><?php _e( 'Settings updated correctly', 'import-users-from-csv-with-meta' ) ?></p>
importer.php CHANGED
@@ -43,6 +43,8 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
43
  $role_default = isset( $form_data["role"] ) ? $form_data["role"] : '';
44
  $update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? $form_data["update_roles_existing_users"] : '';
45
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? $form_data["empty_cell_action"] : '';
 
 
46
 
47
  if( $is_frontend ){
48
  $activate_users_wp_members = get_option( "acui_frontend_activate_users_wp_members" );
@@ -97,6 +99,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
97
  echo "<p>" . __('First row represents the form of sheet','import-users-from-csv-with-meta') . "</p>";
98
  $row = 0;
99
  $positions = array();
 
100
 
101
  ini_set('auto_detect_line_endings',TRUE);
102
 
@@ -171,6 +174,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
171
 
172
  if( count( $data ) != $columns ): // if number of columns is not the same that columns in header
173
  echo '<script>alert("' . __( 'Row number', 'import-users-from-csv-with-meta' ) . " $row " . __( 'does not have the same columns than the header, we are going to skip', 'import-users-from-csv-with-meta') . '");</script>';
 
174
  continue;
175
  endif;
176
 
@@ -256,10 +260,12 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
256
  }
257
  elseif( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid
258
  $problematic_row = true;
 
259
  $data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
260
  }
261
  elseif( empty( $email) ) { // if email is blank
262
  $problematic_row = true;
 
263
  $data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
264
  }
265
  elseif( username_exists( $username ) ){ // if user exists, we take his ID by login, we will update his mail if it has changed
@@ -293,6 +299,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
293
 
294
  $data[0] = __( 'User already exists as:', 'import-users-from-csv-with-meta' ) . $user_object->user_login . '<br/>' . __( '(in this CSV file is called:', 'import-users-from-csv-with-meta' ) . $username . ")";
295
  $problematic_row = true;
 
296
 
297
  if( $password !== "" )
298
  wp_set_password( $password, $user_id );
@@ -321,6 +328,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
321
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
322
  $error_string = $user_id->get_error_message();
323
  echo '<script>alert("' . __( 'Problems with user:', 'import-users-from-csv-with-meta' ) . $username . __( ', we are going to skip. \r\nError: ', 'import-users-from-csv-with-meta') . $error_string . '");</script>';
 
324
  continue;
325
  }
326
 
@@ -368,6 +376,7 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
368
 
369
  if ( !empty( $invalid_roles ) ){
370
  $problematic_row = true;
 
371
  if( count( $invalid_roles ) == 1 )
372
  $data[0] = __('Invalid role','import-users-from-csv-with-meta').' (' . reset( $invalid_roles ) . ')';
373
  else
@@ -624,19 +633,38 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false,
624
  wp_delete_attachment( $attach_id );
625
 
626
  // delete all users that have not been imported
627
- if( $is_cron && get_option( "acui_cron_delete_users" ) ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
628
  require_once( ABSPATH . 'wp-admin/includes/user.php');
629
 
630
  $all_users = get_users( array(
631
  'fields' => array( 'ID' ),
632
  'role__not_in' => array( 'administrator' )
633
  ) );
634
- $cron_delete_users_assign_posts = get_option( "acui_cron_delete_users_assign_posts");
635
 
636
  foreach ( $all_users as $user ) {
637
  if( !in_array( $user->ID, $users_registered ) ){
638
- if( !empty( $cron_delete_users_assign_posts ) && get_userdata( $cron_delete_users_assign_posts ) !== false ){
639
- wp_delete_user( $user->ID, $cron_delete_users_assign_posts );
640
  }
641
  else{
642
  wp_delete_user( $user->ID );
43
  $role_default = isset( $form_data["role"] ) ? $form_data["role"] : '';
44
  $update_roles_existing_users = isset( $form_data["update_roles_existing_users"] ) ? $form_data["update_roles_existing_users"] : '';
45
  $empty_cell_action = isset( $form_data["empty_cell_action"] ) ? $form_data["empty_cell_action"] : '';
46
+ $delete_users = isset( $form_data["delete_users"] ) ? $form_data["delete_users"] : '';
47
+ $delete_users_assign_posts = isset( $form_data["delete_users_assign_posts"] ) ? $form_data["delete_users_assign_posts"] : '';
48
 
49
  if( $is_frontend ){
50
  $activate_users_wp_members = get_option( "acui_frontend_activate_users_wp_members" );
99
  echo "<p>" . __('First row represents the form of sheet','import-users-from-csv-with-meta') . "</p>";
100
  $row = 0;
101
  $positions = array();
102
+ $error_importing = false;
103
 
104
  ini_set('auto_detect_line_endings',TRUE);
105
 
174
 
175
  if( count( $data ) != $columns ): // if number of columns is not the same that columns in header
176
  echo '<script>alert("' . __( 'Row number', 'import-users-from-csv-with-meta' ) . " $row " . __( 'does not have the same columns than the header, we are going to skip', 'import-users-from-csv-with-meta') . '");</script>';
177
+ $error_importing = true;
178
  continue;
179
  endif;
180
 
260
  }
261
  elseif( !empty( $email ) && ( ( sanitize_email( $email ) == '' ) ) ){ // if email is invalid
262
  $problematic_row = true;
263
+ $error_importing = true;
264
  $data[0] = __('Invalid EMail','import-users-from-csv-with-meta')." ($email)";
265
  }
266
  elseif( empty( $email) ) { // if email is blank
267
  $problematic_row = true;
268
+ $error_importing = true;
269
  $data[0] = __( 'EMail not specified', 'import-users-from-csv-with-meta' );
270
  }
271
  elseif( username_exists( $username ) ){ // if user exists, we take his ID by login, we will update his mail if it has changed
299
 
300
  $data[0] = __( 'User already exists as:', 'import-users-from-csv-with-meta' ) . $user_object->user_login . '<br/>' . __( '(in this CSV file is called:', 'import-users-from-csv-with-meta' ) . $username . ")";
301
  $problematic_row = true;
302
+ $error_importing = true;
303
 
304
  if( $password !== "" )
305
  wp_set_password( $password, $user_id );
328
  if( is_wp_error( $user_id ) ){ // in case the user is generating errors after this checks
329
  $error_string = $user_id->get_error_message();
330
  echo '<script>alert("' . __( 'Problems with user:', 'import-users-from-csv-with-meta' ) . $username . __( ', we are going to skip. \r\nError: ', 'import-users-from-csv-with-meta') . $error_string . '");</script>';
331
+ $error_importing = true;
332
  continue;
333
  }
334
 
376
 
377
  if ( !empty( $invalid_roles ) ){
378
  $problematic_row = true;
379
+ $error_importing = true;
380
  if( count( $invalid_roles ) == 1 )
381
  $data[0] = __('Invalid role','import-users-from-csv-with-meta').' (' . reset( $invalid_roles ) . ')';
382
  else
633
  wp_delete_attachment( $attach_id );
634
 
635
  // delete all users that have not been imported
636
+ $delete_users_flag = false;
637
+
638
+ if( $delete_users == 'yes' ){
639
+ $delete_users_flag = true;
640
+ }
641
+
642
+ if( $is_cron && get_option( "acui_cron_delete_users" ) ){
643
+ $delete_users_flag = true;
644
+ $delete_users_assign_posts = get_option( "acui_cron_delete_users_assign_posts");
645
+ }
646
+
647
+ if( $is_frontend && get_option( "acui_frontend_delete_users" ) ){
648
+ $delete_users_flag = true;
649
+ $delete_users_assign_posts = get_option( "acui_frontend_delete_users_assign_posts");
650
+ }
651
+
652
+ if( $error_importing ) // if there is some problem of some kind importing we won't proceed with delete to avoid problems
653
+ $delete_users_flag = false;
654
+
655
+ if( $delete_users_flag ):
656
  require_once( ABSPATH . 'wp-admin/includes/user.php');
657
 
658
  $all_users = get_users( array(
659
  'fields' => array( 'ID' ),
660
  'role__not_in' => array( 'administrator' )
661
  ) );
662
+
663
 
664
  foreach ( $all_users as $user ) {
665
  if( !in_array( $user->ID, $users_registered ) ){
666
+ if( !empty( $delete_users_assign_posts ) && get_userdata( $delete_users_assign_posts ) !== false ){
667
+ wp_delete_user( $user->ID, $delete_users_assign_posts );
668
  }
669
  else{
670
  wp_delete_user( $user->ID );
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: carazo, hornero
3
  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: 5.0.3
7
- Stable tag: 1.12.6.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -74,6 +74,12 @@ Plugin will automatically detect:
74
 
75
  == Changelog ==
76
 
 
 
 
 
 
 
77
  = 1.12.6.2 =
78
  * Notices fixed
79
  * Some file deleted and some urls fixed
3
  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: 5.1
7
+ Stable tag: 1.13
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
74
 
75
  == Changelog ==
76
 
77
+ = 1.13 =
78
+ * Now you can delete users that are not in the CSV file, not only when you are doing an import based on a cron task, but also when you do it from the dashboard or with the shortcode in the frontend thanks to mojosolo.com
79
+ * Documentation improved
80
+ * Bug fixed
81
+ * Tested up to 5.1
82
+
83
  = 1.12.6.2 =
84
  * Notices fixed
85
  * Some file deleted and some urls fixed