Version Description
- You can now import users from the frontend using a shortcode thanks to Nelson Artz Group GmbH & Co. KG
Download this release
Release Info
Developer | carazo |
Plugin | Import users from CSV with meta |
Version | 1.11 |
Comparing to | |
See all releases |
Code changes from version 1.10.13 to 1.11
- import-users-from-csv-with-meta.php +39 -4
- importer.php +94 -3
- include/shortcode-frontend.php +50 -0
- readme.txt +4 -1
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.
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
@@ -53,6 +53,11 @@ function acui_loader(){
|
|
53 |
add_action( "edit_user_profile_update", "acui_save_extra_user_profile_fields" );
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
// addons
|
57 |
foreach ( glob( plugin_dir_path( __FILE__ ) . "addons/*.php" ) as $file ) {
|
58 |
include_once( $file );
|
@@ -86,6 +91,10 @@ function acui_activate(){
|
|
86 |
add_option( "acui_cron_role" );
|
87 |
add_option( "acui_cron_log" );
|
88 |
|
|
|
|
|
|
|
|
|
89 |
add_option( "acui_manually_send_mail", false );
|
90 |
add_option( "acui_manually_send_mail_updated", false );
|
91 |
|
@@ -125,6 +134,10 @@ function acui_delete_options(){
|
|
125 |
delete_option( "acui_cron_role" );
|
126 |
delete_option( "acui_cron_log" );
|
127 |
|
|
|
|
|
|
|
|
|
128 |
delete_option( "acui_manually_send_mail" );
|
129 |
delete_option( "acui_manually_send_mail_updated" );
|
130 |
|
@@ -249,6 +262,7 @@ function acui_check_options(){
|
|
249 |
function acui_admin_tabs( $current = 'homepage' ) {
|
250 |
$tabs = array(
|
251 |
'homepage' => __( 'Import users from CSV', 'import-users-from-csv-with-meta' ),
|
|
|
252 |
'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
|
253 |
'mail-options' => __( 'Mail options', 'import-users-from-csv-with-meta' ),
|
254 |
'smtp-settings' => __( 'SMTP settings', 'import-users-from-csv-with-meta' ),
|
@@ -279,8 +293,8 @@ function acui_admin_tabs( $current = 'homepage' ) {
|
|
279 |
echo '</h2>';
|
280 |
}
|
281 |
|
282 |
-
function acui_fileupload_process( $form_data, $is_cron = false ) {
|
283 |
-
if (
|
284 |
wp_die( 'Nonce problem' );
|
285 |
}
|
286 |
|
@@ -293,7 +307,7 @@ function acui_fileupload_process( $form_data, $is_cron = false ) {
|
|
293 |
if( !file_exists ( $path_to_file ) )
|
294 |
wp_die( __( 'Error, we cannot find the file', 'import-users-from-csv-with-meta' ) . ": $path_to_file" );
|
295 |
|
296 |
-
acui_import_users( $path_to_file, $form_data, 0, $is_cron );
|
297 |
|
298 |
else:
|
299 |
|
@@ -366,6 +380,27 @@ function acui_fileupload_process( $form_data, $is_cron = false ) {
|
|
366 |
endif;
|
367 |
}
|
368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
function acui_manage_extra_profile_fields( $form_data ){
|
370 |
if( isset( $form_data["show-profile-fields"] ) && $form_data["show-profile-fields"] == "yes" ){
|
371 |
update_option( "acui_show_profile_fields", true );
|
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.11
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
53 |
add_action( "edit_user_profile_update", "acui_save_extra_user_profile_fields" );
|
54 |
}
|
55 |
|
56 |
+
// includes
|
57 |
+
foreach ( glob( plugin_dir_path( __FILE__ ) . "include/*.php" ) as $file ) {
|
58 |
+
include_once( $file );
|
59 |
+
}
|
60 |
+
|
61 |
// addons
|
62 |
foreach ( glob( plugin_dir_path( __FILE__ ) . "addons/*.php" ) as $file ) {
|
63 |
include_once( $file );
|
91 |
add_option( "acui_cron_role" );
|
92 |
add_option( "acui_cron_log" );
|
93 |
|
94 |
+
add_option( "acui_frontend_send_mail", false );
|
95 |
+
add_option( "acui_frontend_send_mail_updated", false );
|
96 |
+
add_option( "acui_frontend_role" );
|
97 |
+
|
98 |
add_option( "acui_manually_send_mail", false );
|
99 |
add_option( "acui_manually_send_mail_updated", false );
|
100 |
|
134 |
delete_option( "acui_cron_role" );
|
135 |
delete_option( "acui_cron_log" );
|
136 |
|
137 |
+
delete_option( "acui_frontend_send_mail" );
|
138 |
+
delete_option( "acui_frontend_send_mail_updated" );
|
139 |
+
delete_option( "acui_frontend_role" );
|
140 |
+
|
141 |
delete_option( "acui_manually_send_mail" );
|
142 |
delete_option( "acui_manually_send_mail_updated" );
|
143 |
|
262 |
function acui_admin_tabs( $current = 'homepage' ) {
|
263 |
$tabs = array(
|
264 |
'homepage' => __( 'Import users from CSV', 'import-users-from-csv-with-meta' ),
|
265 |
+
'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
|
266 |
'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
|
267 |
'mail-options' => __( 'Mail options', 'import-users-from-csv-with-meta' ),
|
268 |
'smtp-settings' => __( 'SMTP settings', 'import-users-from-csv-with-meta' ),
|
293 |
echo '</h2>';
|
294 |
}
|
295 |
|
296 |
+
function acui_fileupload_process( $form_data, $is_cron = false, $is_frontend = false ) {
|
297 |
+
if ( !( $is_cron || $is_frontend ) && ( ! isset( $_POST['acui-nonce'] ) || ! wp_verify_nonce( $_POST['acui-nonce'], 'acui-import' ) ) ){
|
298 |
wp_die( 'Nonce problem' );
|
299 |
}
|
300 |
|
307 |
if( !file_exists ( $path_to_file ) )
|
308 |
wp_die( __( 'Error, we cannot find the file', 'import-users-from-csv-with-meta' ) . ": $path_to_file" );
|
309 |
|
310 |
+
acui_import_users( $path_to_file, $form_data, 0, $is_cron, $is_frontend );
|
311 |
|
312 |
else:
|
313 |
|
380 |
endif;
|
381 |
}
|
382 |
|
383 |
+
function acui_manage_frontend_process( $form_data ){
|
384 |
+
if( isset( $form_data["send-mail-frontend"] ) && $form_data["send-mail-frontend"] == "yes" )
|
385 |
+
update_option( "acui_frontend_send_mail", true );
|
386 |
+
else
|
387 |
+
update_option( "acui_frontend_send_mail", false );
|
388 |
+
|
389 |
+
if( isset( $form_data["send-mail-updated-frontend"] ) && $form_data["send-mail-updated-frontend"] == "yes" )
|
390 |
+
update_option( "acui_frontend_send_mail_updated", true );
|
391 |
+
else
|
392 |
+
update_option( "acui_frontend_send_mail_updated", false );
|
393 |
+
|
394 |
+
update_option( "acui_frontend_role", $form_data["role-frontend"] );
|
395 |
+
?>
|
396 |
+
|
397 |
+
<div class="updated">
|
398 |
+
<p><?php _e( 'Settings updated correctly', 'import-users-from-csv-with-meta' ) ?></p>
|
399 |
+
</div>
|
400 |
+
<?php
|
401 |
+
}
|
402 |
+
|
403 |
+
|
404 |
function acui_manage_extra_profile_fields( $form_data ){
|
405 |
if( isset( $form_data["show-profile-fields"] ) && $form_data["show-profile-fields"] == "yes" ){
|
406 |
update_option( "acui_show_profile_fields", true );
|
importer.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
|
5 |
-
function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false ){?>
|
6 |
<div class="wrap">
|
7 |
<h2>Importing users</h2>
|
8 |
<?php
|
@@ -455,6 +455,13 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
|
|
455 |
}
|
456 |
}
|
457 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
458 |
else{
|
459 |
if( isset( $form_data["sends_email"] ) && $form_data["sends_email"] ){
|
460 |
if( $created || ( !$created && ( isset( $form_data["send_email_updated"] ) && $form_data["send_email_updated"] ) ) )
|
@@ -557,8 +564,12 @@ function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false
|
|
557 |
|
558 |
?>
|
559 |
</table>
|
560 |
-
|
561 |
-
|
|
|
|
|
|
|
|
|
562 |
<?php
|
563 |
ini_set('auto_detect_line_endings',FALSE);
|
564 |
|
@@ -588,6 +599,10 @@ function acui_options(){
|
|
588 |
return;
|
589 |
break;
|
590 |
|
|
|
|
|
|
|
|
|
591 |
case 'columns':
|
592 |
acui_manage_extra_profile_fields( $_POST );
|
593 |
break;
|
@@ -948,6 +963,82 @@ function acui_options(){
|
|
948 |
|
949 |
break;
|
950 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
951 |
case 'columns':
|
952 |
$show_profile_fields = get_option( "acui_show_profile_fields");
|
953 |
$headers = get_option("acui_columns");
|
2 |
|
3 |
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
|
5 |
+
function acui_import_users( $file, $form_data, $attach_id = 0, $is_cron = false, $is_frontend = false ){?>
|
6 |
<div class="wrap">
|
7 |
<h2>Importing users</h2>
|
8 |
<?php
|
455 |
}
|
456 |
}
|
457 |
}
|
458 |
+
elseif( $is_frontend ){
|
459 |
+
if( get_option( "acui_frontend_send_mail" ) ){
|
460 |
+
if( $created || ( !$created && get_option( "acui_frontend_send_mail_updated" ) ) ){
|
461 |
+
$mail_for_this_user = true;
|
462 |
+
}
|
463 |
+
}
|
464 |
+
}
|
465 |
else{
|
466 |
if( isset( $form_data["sends_email"] ) && $form_data["sends_email"] ){
|
467 |
if( $created || ( !$created && ( isset( $form_data["send_email_updated"] ) && $form_data["send_email_updated"] ) ) )
|
564 |
|
565 |
?>
|
566 |
</table>
|
567 |
+
|
568 |
+
<?php if( !$is_frontend ): ?>
|
569 |
+
<br/>
|
570 |
+
<p><?php _e( 'Process finished you can go', 'import-users-from-csv-with-meta' ); ?> <a href="<?php echo get_admin_url( null, 'users.php' ); ?>"><?php _e( 'here to see results', 'import-users-from-csv-with-meta' ); ?></a></p>
|
571 |
+
<?php endif; ?>
|
572 |
+
|
573 |
<?php
|
574 |
ini_set('auto_detect_line_endings',FALSE);
|
575 |
|
599 |
return;
|
600 |
break;
|
601 |
|
602 |
+
case 'frontend':
|
603 |
+
acui_manage_frontend_process( $_POST );
|
604 |
+
break;
|
605 |
+
|
606 |
case 'columns':
|
607 |
acui_manage_extra_profile_fields( $_POST );
|
608 |
break;
|
963 |
|
964 |
break;
|
965 |
|
966 |
+
case 'frontend':
|
967 |
+
|
968 |
+
$send_mail_frontend = get_option( "acui_frontend_send_mail");
|
969 |
+
$send_mail_updated_frontend = get_option( "acui_frontend_send_mail_updated");
|
970 |
+
$role = get_option( "acui_frontend_role");
|
971 |
+
|
972 |
+
if( empty( $send_mail_frontend ) )
|
973 |
+
$send_mail_frontend = false;
|
974 |
+
|
975 |
+
if( empty( $send_mail_updated_frontend ) )
|
976 |
+
$send_mail_updated_frontend = false;
|
977 |
+
?>
|
978 |
+
<h3><?php _e( "Execute an import of users in the frontend", 'import-users-from-csv-with-meta' ); ?></h3>
|
979 |
+
|
980 |
+
<form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8">
|
981 |
+
<table class="form-table">
|
982 |
+
<tbody>
|
983 |
+
<tr class="form-field">
|
984 |
+
<th scope="row"><label for=""><?php _e( 'Use this shortcode in any page or post', 'import-users-from-csv-with-meta' ); ?></label></th>
|
985 |
+
<td>
|
986 |
+
<pre>[import-users-from-csv-with-meta]</pre>
|
987 |
+
<input class="button-primary" type="button" id="copy_to_clipboard" value="<?php _e( 'Copy to clipboard', 'import-users-from-csv-with-meta'); ?>"/>
|
988 |
+
</td>
|
989 |
+
</tr>
|
990 |
+
<tr class="form-field form-required">
|
991 |
+
<th scope="row"><label for="send-mail-frontend"><?php _e( 'Send mail when using frontend import?', 'import-users-from-csv-with-meta' ); ?></label></th>
|
992 |
+
<td>
|
993 |
+
<input type="checkbox" name="send-mail-frontend" value="yes" <?php if( $send_mail_frontend == true ) echo "checked='checked'"; ?>/>
|
994 |
+
</td>
|
995 |
+
</tr>
|
996 |
+
<tr class="form-field form-required">
|
997 |
+
<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>
|
998 |
+
<td>
|
999 |
+
<input type="checkbox" name="send-mail-updated-frontend" value="yes" <?php if( $send_mail_updated_frontend == true ) echo "checked='checked'"; ?>/>
|
1000 |
+
</td>
|
1001 |
+
</tr>
|
1002 |
+
<tr class="form-field form-required">
|
1003 |
+
<th scope="row"><label for="role"><?php _e( 'Role', 'import-users-from-csv-with-meta' ); ?></label></th>
|
1004 |
+
<td>
|
1005 |
+
<select id="role-frontend" name="role-frontend">
|
1006 |
+
<?php
|
1007 |
+
if( $role == '' )
|
1008 |
+
echo "<option selected='selected' value=''>" . __( 'Disable role assignement in frontend import', 'import-users-from-csv-with-meta' ) . "</option>";
|
1009 |
+
else
|
1010 |
+
echo "<option value=''>" . __( 'Disable role assignement in frontend import', 'import-users-from-csv-with-meta' ) . "</option>";
|
1011 |
+
|
1012 |
+
$list_roles = acui_get_editable_roles();
|
1013 |
+
foreach ($list_roles as $key => $value) {
|
1014 |
+
if($key == $role)
|
1015 |
+
echo "<option selected='selected' value='$key'>$value</option>";
|
1016 |
+
else
|
1017 |
+
echo "<option value='$key'>$value</option>";
|
1018 |
+
}
|
1019 |
+
?>
|
1020 |
+
</select>
|
1021 |
+
<p class="description"><?php _e( 'Which role would be used to import users?', 'import-users-from-csv-with-meta' ); ?></p>
|
1022 |
+
</td>
|
1023 |
+
</tr>
|
1024 |
+
</tbody>
|
1025 |
+
</table>
|
1026 |
+
<input class="button-primary" type="submit" value="<?php _e( 'Save frontend import options', 'import-users-from-csv-with-meta'); ?>"/>
|
1027 |
+
</form>
|
1028 |
+
|
1029 |
+
<script>
|
1030 |
+
jQuery( document ).ready( function( $ ){
|
1031 |
+
$( '#copy_to_clipboard' ).click( function(){
|
1032 |
+
var $temp = $("<input>");
|
1033 |
+
$("body").append($temp);
|
1034 |
+
$temp.val( '[import-users-from-csv-with-meta]' ).select();
|
1035 |
+
document.execCommand("copy");
|
1036 |
+
$temp.remove();
|
1037 |
+
} );
|
1038 |
+
});
|
1039 |
+
</script>
|
1040 |
+
<?php break;
|
1041 |
+
|
1042 |
case 'columns':
|
1043 |
$show_profile_fields = get_option( "acui_show_profile_fields");
|
1044 |
$headers = get_option("acui_columns");
|
include/shortcode-frontend.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
add_shortcode( 'import-users-from-csv-with-meta', 'acui_frontend' );
|
3 |
+
function acui_frontend() {
|
4 |
+
ob_start();
|
5 |
+
|
6 |
+
if( !current_user_can( 'create_users' ) )
|
7 |
+
die( __( 'Only users who are able to create users can manage this form.', 'import-users-from-csv-with-meta' ) );
|
8 |
+
|
9 |
+
if ( $_FILES && !empty( $_POST ) ) {
|
10 |
+
$nonce = $_POST['acui_nonce'];
|
11 |
+
if ( !isset( $nonce ) || !wp_verify_nonce( $nonce, 'codection-security' ) )
|
12 |
+
die( 'Nonce check failed' );
|
13 |
+
|
14 |
+
foreach ( $_FILES as $file => $array ) {
|
15 |
+
$csv_file_id = acui_frontend_upload_file( $file );
|
16 |
+
|
17 |
+
$form_data = array();
|
18 |
+
$form_data[ "path_to_file" ] = get_attached_file( $csv_file_id );
|
19 |
+
$form_data[ "role" ] = get_option( "acui_frontend_role");
|
20 |
+
$form_data[ "empty_cell_action" ] = "leave";
|
21 |
+
|
22 |
+
acui_fileupload_process( $form_data, false, true );
|
23 |
+
|
24 |
+
wp_delete_attachment( $csv_file_id, true );
|
25 |
+
|
26 |
+
continue;
|
27 |
+
}
|
28 |
+
}
|
29 |
+
?>
|
30 |
+
<form method="POST" enctype="multipart/form-data" action="" accept-charset="utf-8" class="acui_frontend_form">
|
31 |
+
<label><?php _e( 'CSV file <span class="description">(required)</span>', 'import-users-from-csv-with-meta' ); ?></label></th>
|
32 |
+
<input class="acui_frontend_file" type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" />
|
33 |
+
<input class="acui_frontend_submit" type="submit" value="<?php _e( 'Upload and process', 'import-users-from-csv-with-meta' ); ?>"/>
|
34 |
+
|
35 |
+
<?php wp_nonce_field( 'codection-security', 'acui_nonce' ); ?>
|
36 |
+
</form>
|
37 |
+
<?php
|
38 |
+
return ob_get_clean();
|
39 |
+
}
|
40 |
+
|
41 |
+
function acui_frontend_upload_file( $file_handler ) {
|
42 |
+
if ( $_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK ) {
|
43 |
+
__return_false();
|
44 |
+
}
|
45 |
+
require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
|
46 |
+
require_once( ABSPATH . "wp-admin" . '/includes/file.php' );
|
47 |
+
require_once( ABSPATH . "wp-admin" . '/includes/media.php' );
|
48 |
+
$attach_id = media_handle_upload( $file_handler, 0 );
|
49 |
+
return $attach_id;
|
50 |
+
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ 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: 4.9.4
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -70,6 +70,9 @@ Plugin will automatically detect:
|
|
70 |
|
71 |
== Changelog ==
|
72 |
|
|
|
|
|
|
|
73 |
= 1.10.13 =
|
74 |
* You can now import User Groups (https://wordpress.org/plugins/user-groups/) and assign them to the users
|
75 |
|
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: 4.9.4
|
7 |
+
Stable tag: 1.11
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
70 |
|
71 |
== Changelog ==
|
72 |
|
73 |
+
= 1.11 =
|
74 |
+
* You can now import users from the frontend using a shortcode thanks to Nelson Artz Group GmbH & Co. KG
|
75 |
+
|
76 |
= 1.10.13 =
|
77 |
* You can now import User Groups (https://wordpress.org/plugins/user-groups/) and assign them to the users
|
78 |
|