Version Description
- Now you can filter the columns that are going to be exported using the shortcode and the attribute columns
Download this release
Release Info
Developer | carazo |
Plugin | Import users from CSV with meta |
Version | 1.17.6 |
Comparing to | |
See all releases |
Code changes from version 1.17.5.7 to 1.17.6
- classes/export.php +50 -17
- classes/frontend.php +12 -7
- import-users-from-csv-with-meta.php +1 -1
- readme.txt +4 -1
classes/export.php
CHANGED
@@ -137,7 +137,7 @@ class ACUI_Exporter{
|
|
137 |
return array_merge( array_flip( $columns ), $row );
|
138 |
}
|
139 |
|
140 |
-
|
141 |
if( strlen( $value ) == 0 )
|
142 |
return $value;
|
143 |
|
@@ -149,7 +149,7 @@ class ACUI_Exporter{
|
|
149 |
return $value;
|
150 |
}
|
151 |
|
152 |
-
|
153 |
$timestamp_keys = apply_filters( 'acui_export_timestamp_keys', array( 'wc_last_active' ) );
|
154 |
$non_date_keys = apply_filters( 'acui_export_non_date_keys', array() );
|
155 |
$original_value = $value;
|
@@ -179,6 +179,15 @@ class ACUI_Exporter{
|
|
179 |
return implode( ',', $user->roles );
|
180 |
}
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
function export_users_csv(){
|
183 |
check_ajax_referer( 'codection-security', 'security' );
|
184 |
|
@@ -192,8 +201,10 @@ class ACUI_Exporter{
|
|
192 |
$convert_timestamp = isset( $_POST['convert_timestamp'] ) && !empty( $_POST['convert_timestamp'] );
|
193 |
$datetime_format = ( $convert_timestamp ) ? sanitize_text_field( $_POST['datetime_format'] ) : '';
|
194 |
$order_fields_alphabetically = isset( $_POST['order_fields_alphabetically'] ) && !empty( $_POST['order_fields_alphabetically'] );
|
195 |
-
|
196 |
-
|
|
|
|
|
197 |
case 'COMMA':
|
198 |
$delimiter = ",";
|
199 |
break;
|
@@ -219,13 +230,14 @@ class ACUI_Exporter{
|
|
219 |
$row = array();
|
220 |
|
221 |
// header
|
222 |
-
foreach ( $this->
|
223 |
-
|
224 |
}
|
225 |
|
226 |
-
|
|
|
227 |
|
228 |
-
foreach ( $this->get_user_meta_keys() as $key ) {
|
229 |
$row[] = $key;
|
230 |
}
|
231 |
|
@@ -239,18 +251,20 @@ class ACUI_Exporter{
|
|
239 |
foreach ( $users as $user ) {
|
240 |
$userdata = get_userdata( $user );
|
241 |
|
242 |
-
|
243 |
$key = apply_filters( 'acui_export_get_key_user_data', $key );
|
244 |
$row[ $key ] = self::prepare( $key, $userdata->data->{$key}, $datetime_format, $user );
|
245 |
}
|
246 |
|
247 |
-
|
|
|
248 |
|
249 |
-
foreach ( $this->get_user_meta_keys() as $key ) {
|
250 |
$row[ $key ] = self::prepare( $key, get_user_meta( $user, $key, true ), $datetime_format, $user );
|
251 |
}
|
252 |
|
253 |
-
|
|
|
254 |
|
255 |
$row = apply_filters( 'acui_export_data', $row, $user, $datetime_format, $columns, $order_fields_alphabetically );
|
256 |
|
@@ -290,7 +304,22 @@ class ACUI_Exporter{
|
|
290 |
wp_die();
|
291 |
}
|
292 |
|
293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
global $wpdb;
|
295 |
$meta_keys = array();
|
296 |
|
@@ -301,7 +330,8 @@ class ACUI_Exporter{
|
|
301 |
if( $value["meta_key"] == 'role' )
|
302 |
continue;
|
303 |
|
304 |
-
|
|
|
305 |
}
|
306 |
|
307 |
return apply_filters( 'acui_export_get_user_meta_keys', $meta_keys );
|
@@ -340,15 +370,18 @@ class ACUI_Exporter{
|
|
340 |
return ( $key == 'source_user_id' ) ? 'ID' : $key;
|
341 |
}
|
342 |
|
343 |
-
function maybe_fill_empty_data( $row, $user_id ){
|
344 |
if( empty( $row['user_login'] ) || empty( $row['user_email'] ) ){
|
345 |
$user = new WP_User( $user_id );
|
346 |
|
347 |
if( $user->ID == 0 )
|
348 |
return $row;
|
349 |
|
350 |
-
|
351 |
-
|
|
|
|
|
|
|
352 |
}
|
353 |
|
354 |
return $row;
|
137 |
return array_merge( array_flip( $columns ), $row );
|
138 |
}
|
139 |
|
140 |
+
static function clean_bad_characters_formulas( $value ){
|
141 |
if( strlen( $value ) == 0 )
|
142 |
return $value;
|
143 |
|
149 |
return $value;
|
150 |
}
|
151 |
|
152 |
+
static function prepare( $key, $value, $datetime_format, $user = 0 ){
|
153 |
$timestamp_keys = apply_filters( 'acui_export_timestamp_keys', array( 'wc_last_active' ) );
|
154 |
$non_date_keys = apply_filters( 'acui_export_non_date_keys', array() );
|
155 |
$original_value = $value;
|
179 |
return implode( ',', $user->roles );
|
180 |
}
|
181 |
|
182 |
+
function manage_filtered_columns( $filtered_columns ){
|
183 |
+
$filtered_columns = ( is_array( $filtered_columns ) ) ? array_walk( $filtered_columns, 'sanitize_text_field' ) : explode( ',', sanitize_text_field( $filtered_columns ) );
|
184 |
+
|
185 |
+
if( empty( $filtered_columns[0] ) )
|
186 |
+
$filtered_columns = array();
|
187 |
+
|
188 |
+
return $filtered_columns;
|
189 |
+
}
|
190 |
+
|
191 |
function export_users_csv(){
|
192 |
check_ajax_referer( 'codection-security', 'security' );
|
193 |
|
201 |
$convert_timestamp = isset( $_POST['convert_timestamp'] ) && !empty( $_POST['convert_timestamp'] );
|
202 |
$datetime_format = ( $convert_timestamp ) ? sanitize_text_field( $_POST['datetime_format'] ) : '';
|
203 |
$order_fields_alphabetically = isset( $_POST['order_fields_alphabetically'] ) && !empty( $_POST['order_fields_alphabetically'] );
|
204 |
+
$filtered_columns = ( isset( $_POST['columns'] ) && !empty( $_POST['columns'] ) ) ? $_POST['columns'] : array();
|
205 |
+
$filtered_columns = $this->manage_filtered_columns( $filtered_columns );
|
206 |
+
|
207 |
+
switch ( $delimiter ) {
|
208 |
case 'COMMA':
|
209 |
$delimiter = ",";
|
210 |
break;
|
230 |
$row = array();
|
231 |
|
232 |
// header
|
233 |
+
foreach ( $this->get_user_data( $filtered_columns ) as $key ) {
|
234 |
+
$row[] = $key;
|
235 |
}
|
236 |
|
237 |
+
if( count( $filtered_columns ) == 0 || in_array( 'role', $filtered_columns ) )
|
238 |
+
$row[] = "role";
|
239 |
|
240 |
+
foreach ( $this->get_user_meta_keys( $filtered_columns ) as $key ) {
|
241 |
$row[] = $key;
|
242 |
}
|
243 |
|
251 |
foreach ( $users as $user ) {
|
252 |
$userdata = get_userdata( $user );
|
253 |
|
254 |
+
foreach ( $this->get_user_data( $filtered_columns ) as $key ) {
|
255 |
$key = apply_filters( 'acui_export_get_key_user_data', $key );
|
256 |
$row[ $key ] = self::prepare( $key, $userdata->data->{$key}, $datetime_format, $user );
|
257 |
}
|
258 |
|
259 |
+
if( count( $filtered_columns ) == 0 || in_array( 'role', $filtered_columns ) )
|
260 |
+
$row[] = $this->get_role( $user );
|
261 |
|
262 |
+
foreach ( $this->get_user_meta_keys( $filtered_columns ) as $key ) {
|
263 |
$row[ $key ] = self::prepare( $key, get_user_meta( $user, $key, true ), $datetime_format, $user );
|
264 |
}
|
265 |
|
266 |
+
if( count( $filtered_columns ) == 0 || in_array( 'user_email', $filtered_columns ) || in_array( 'user_login', $filtered_columns ) )
|
267 |
+
$row = $this->maybe_fill_empty_data( $row, $user, $filtered_columns );
|
268 |
|
269 |
$row = apply_filters( 'acui_export_data', $row, $user, $datetime_format, $columns, $order_fields_alphabetically );
|
270 |
|
304 |
wp_die();
|
305 |
}
|
306 |
|
307 |
+
function get_user_data( $filtered_columns ){
|
308 |
+
if( count( $filtered_columns ) == 0 )
|
309 |
+
return $this->user_data;
|
310 |
+
|
311 |
+
var_export( $filtered_columns );
|
312 |
+
|
313 |
+
$result = array();
|
314 |
+
foreach( $this->user_data as $column ){
|
315 |
+
if( in_array( $column, $filtered_columns ) )
|
316 |
+
$result[] = $column;
|
317 |
+
}
|
318 |
+
|
319 |
+
return $result;
|
320 |
+
}
|
321 |
+
|
322 |
+
function get_user_meta_keys( $filtered_columns ) {
|
323 |
global $wpdb;
|
324 |
$meta_keys = array();
|
325 |
|
330 |
if( $value["meta_key"] == 'role' )
|
331 |
continue;
|
332 |
|
333 |
+
if( count( $filtered_columns ) == 0 || in_array( $value["meta_key"], $filtered_columns ) )
|
334 |
+
$meta_keys[] = $value["meta_key"];
|
335 |
}
|
336 |
|
337 |
return apply_filters( 'acui_export_get_user_meta_keys', $meta_keys );
|
370 |
return ( $key == 'source_user_id' ) ? 'ID' : $key;
|
371 |
}
|
372 |
|
373 |
+
function maybe_fill_empty_data( $row, $user_id, $filtered_columns ){
|
374 |
if( empty( $row['user_login'] ) || empty( $row['user_email'] ) ){
|
375 |
$user = new WP_User( $user_id );
|
376 |
|
377 |
if( $user->ID == 0 )
|
378 |
return $row;
|
379 |
|
380 |
+
if( count( $filtered_columns ) == 0 || in_array( 'user_login', $filtered_columns ) )
|
381 |
+
$row['user_login'] = $user->user_login;
|
382 |
+
|
383 |
+
if( count( $filtered_columns ) == 0 || in_array( 'user_email', $filtered_columns ) )
|
384 |
+
$row['user_email'] = $user->user_email;
|
385 |
}
|
386 |
|
387 |
return $row;
|
classes/frontend.php
CHANGED
@@ -239,31 +239,37 @@ class ACUI_Frontend{
|
|
239 |
|
240 |
<tr class="form-field">
|
241 |
<th scope="row"><label for=""><?php _e( 'Attribute role', 'import-users-from-csv-with-meta' ); ?></label></th>
|
242 |
-
<td><?php _e( 'You can use role as attribute to choose directly in the shortcode the role to use during the export. Remind that you must use the role slug, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[
|
243 |
</td>
|
244 |
</tr>
|
245 |
|
246 |
<tr class="form-field">
|
247 |
<th scope="row"><label for=""><?php _e( 'Attribute from', 'import-users-from-csv-with-meta' ); ?></label></th>
|
248 |
-
<td><?php _e( 'You can use from attribute to filter users created from a specified date. Date format has to be: Y-m-d, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[
|
249 |
</td>
|
250 |
</tr>
|
251 |
|
252 |
<tr class="form-field">
|
253 |
<th scope="row"><label for=""><?php _e( 'Attribute to', 'import-users-from-csv-with-meta' ); ?></label></th>
|
254 |
-
<td><?php _e( 'You can use from attribute to filter users created before a specified date. Date format has to be: Y-m-d, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[
|
255 |
</td>
|
256 |
</tr>
|
257 |
|
258 |
<tr class="form-field">
|
259 |
<th scope="row"><label for=""><?php _e( 'Attribute delimiter', 'import-users-from-csv-with-meta' ); ?></label></th>
|
260 |
-
<td><?php _e( 'You can use delimiter attribute to set which delimiter is going to be used, allowed values are:', 'import-users-from-csv-with-meta' ); ?> COMMA, COLON, SEMICOLON, TAB <pre>[
|
261 |
</td>
|
262 |
</tr>
|
263 |
|
264 |
<tr class="form-field">
|
265 |
<th scope="row"><label for=""><?php _e( 'Attribute order-alphabetically', 'import-users-from-csv-with-meta' ); ?></label></th>
|
266 |
-
<td><?php _e( 'You can use order-alphabetically attribute to order alphabetically the fields, for example', 'import-users-from-csv-with-meta' ); ?> <pre>[
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
</td>
|
268 |
</tr>
|
269 |
|
@@ -443,7 +449,7 @@ class ACUI_Frontend{
|
|
443 |
}
|
444 |
|
445 |
function shortcode_export( $atts ) {
|
446 |
-
$atts = shortcode_atts( array( 'role' => '', 'from' => '', 'to' => '', 'delimiter' => '', 'order-alphabetically' => '' ), $atts );
|
447 |
|
448 |
ob_start();
|
449 |
|
@@ -465,6 +471,5 @@ class ACUI_Frontend{
|
|
465 |
return ob_get_clean();
|
466 |
}
|
467 |
}
|
468 |
-
|
469 |
$acui_frontend = new ACUI_Frontend();
|
470 |
$acui_frontend->hooks();
|
239 |
|
240 |
<tr class="form-field">
|
241 |
<th scope="row"><label for=""><?php _e( 'Attribute role', 'import-users-from-csv-with-meta' ); ?></label></th>
|
242 |
+
<td><?php _e( 'You can use role as attribute to choose directly in the shortcode the role to use during the export. Remind that you must use the role slug, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[export-users role="editor"]</pre>
|
243 |
</td>
|
244 |
</tr>
|
245 |
|
246 |
<tr class="form-field">
|
247 |
<th scope="row"><label for=""><?php _e( 'Attribute from', 'import-users-from-csv-with-meta' ); ?></label></th>
|
248 |
+
<td><?php _e( 'You can use from attribute to filter users created from a specified date. Date format has to be: Y-m-d, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[export-users from="<?php echo date( 'Y-m-d' ); ?>"]</pre>
|
249 |
</td>
|
250 |
</tr>
|
251 |
|
252 |
<tr class="form-field">
|
253 |
<th scope="row"><label for=""><?php _e( 'Attribute to', 'import-users-from-csv-with-meta' ); ?></label></th>
|
254 |
+
<td><?php _e( 'You can use from attribute to filter users created before a specified date. Date format has to be: Y-m-d, for example:', 'import-users-from-csv-with-meta' ); ?> <pre>[export-users to="<?php echo date( 'Y-m-d' ); ?>"]</pre>
|
255 |
</td>
|
256 |
</tr>
|
257 |
|
258 |
<tr class="form-field">
|
259 |
<th scope="row"><label for=""><?php _e( 'Attribute delimiter', 'import-users-from-csv-with-meta' ); ?></label></th>
|
260 |
+
<td><?php _e( 'You can use delimiter attribute to set which delimiter is going to be used, allowed values are:', 'import-users-from-csv-with-meta' ); ?> COMMA, COLON, SEMICOLON, TAB <pre>[export-users delimiter="SEMICOLON"]</pre>
|
261 |
</td>
|
262 |
</tr>
|
263 |
|
264 |
<tr class="form-field">
|
265 |
<th scope="row"><label for=""><?php _e( 'Attribute order-alphabetically', 'import-users-from-csv-with-meta' ); ?></label></th>
|
266 |
+
<td><?php _e( 'You can use order-alphabetically attribute to order alphabetically the fields, for example', 'import-users-from-csv-with-meta' ); ?> <pre>[export-users order-alphabetically]</pre>
|
267 |
+
</td>
|
268 |
+
</tr>
|
269 |
+
|
270 |
+
<tr class="form-field">
|
271 |
+
<th scope="row"><label for=""><?php _e( 'Attribute columns', 'import-users-from-csv-with-meta' ); ?></label></th>
|
272 |
+
<td><?php _e( 'You can use columns attribute to set which columns must be exported. Use a list of fields separated by commas, for example', 'import-users-from-csv-with-meta' ); ?> <pre>[export-users columns="user_email,first_name,last_name"]</pre>
|
273 |
</td>
|
274 |
</tr>
|
275 |
|
449 |
}
|
450 |
|
451 |
function shortcode_export( $atts ) {
|
452 |
+
$atts = shortcode_atts( array( 'role' => '', 'from' => '', 'to' => '', 'delimiter' => '', 'order-alphabetically' => '', 'columns' => '' ), $atts );
|
453 |
|
454 |
ob_start();
|
455 |
|
471 |
return ob_get_clean();
|
472 |
}
|
473 |
}
|
|
|
474 |
$acui_frontend = new ACUI_Frontend();
|
475 |
$acui_frontend->hooks();
|
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.
|
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.6
|
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.7.2
|
7 |
-
Stable tag: 1.17.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -103,6 +103,9 @@ Plugin will automatically detect:
|
|
103 |
|
104 |
== Changelog ==
|
105 |
|
|
|
|
|
|
|
106 |
= 1.17.5.7 =
|
107 |
* Email templates are being sent translated in the current WPML language if column locale is not set
|
108 |
* Warning fixed in ACF addon
|
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.7.2
|
7 |
+
Stable tag: 1.17.6
|
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.6 =
|
107 |
+
* Now you can filter the columns that are going to be exported using the shortcode and the attribute columns
|
108 |
+
|
109 |
= 1.17.5.7 =
|
110 |
* Email templates are being sent translated in the current WPML language if column locale is not set
|
111 |
* Warning fixed in ACF addon
|