Version Description
- Export option included
Download this release
Release Info
Developer | carazo |
Plugin | Import users from CSV with meta |
Version | 1.15 |
Comparing to | |
See all releases |
Code changes from version 1.14.3.10 to 1.15
- classes/export.php +132 -0
- import-users-from-csv-with-meta.php +4 -2
- importer.php +4 -0
- readme.txt +5 -2
classes/export.php
ADDED
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! defined( 'ABSPATH' ) ) exit;
|
3 |
+
|
4 |
+
class ACUI_Exporter{
|
5 |
+
private $path_csv;
|
6 |
+
private $user_data;
|
7 |
+
|
8 |
+
function __construct(){
|
9 |
+
$upload_dir = wp_upload_dir();
|
10 |
+
|
11 |
+
$this->path_csv = $upload_dir['basedir'] . "/export-users.csv";
|
12 |
+
$this->user_data = array( "user_login", "user_email", "ID", "user_pass", "user_nicename", "user_url", "user_registered", "display_name" );
|
13 |
+
|
14 |
+
add_action( 'wp_ajax_acui_export_users_csv', array( $this, 'export_users_csv' ) );
|
15 |
+
}
|
16 |
+
|
17 |
+
public static function admin_gui(){
|
18 |
+
?>
|
19 |
+
<h3><?php _e( 'Export users', 'import-users-from-csv-with-meta' ); ?></h3>
|
20 |
+
<table class="form-table">
|
21 |
+
<tbody>
|
22 |
+
<tr valign="top">
|
23 |
+
<th scope="row"><?php _e( 'Download CSV file with users', 'import-users-from-csv-with-meta' ); ?></th>
|
24 |
+
<td>
|
25 |
+
<form method="POST" target="_blank" enctype="multipart/form-data" action="<?php echo admin_url( 'admin-ajax.php' ); ?>">
|
26 |
+
<input type="hidden" name="action" value="acui_export_users_csv"/>
|
27 |
+
<?php wp_nonce_field( 'codection-security', 'security' ); ?>
|
28 |
+
<input class="button-primary" type="submit" value="<?php _e( 'Download', 'import-users-from-csv-with-meta'); ?>"/>
|
29 |
+
</form>
|
30 |
+
</td>
|
31 |
+
</tr>
|
32 |
+
</tbody>
|
33 |
+
</table>
|
34 |
+
<?php
|
35 |
+
}
|
36 |
+
|
37 |
+
function export_users_csv(){
|
38 |
+
check_ajax_referer( 'codection-security', 'security' );
|
39 |
+
|
40 |
+
$data = array();
|
41 |
+
$row = array();
|
42 |
+
|
43 |
+
// header
|
44 |
+
foreach ( $this->user_data as $key ) {
|
45 |
+
$row[] = $key;
|
46 |
+
}
|
47 |
+
|
48 |
+
foreach ( $this->get_user_meta_key() as $key ) {
|
49 |
+
$row[] = $key;
|
50 |
+
}
|
51 |
+
|
52 |
+
$data[] = $row;
|
53 |
+
$row = array();
|
54 |
+
|
55 |
+
// data
|
56 |
+
$users = $this->get_user_id_list();
|
57 |
+
foreach ( $users as $user ) {
|
58 |
+
$userdata = get_userdata( $user );
|
59 |
+
|
60 |
+
foreach ( $this->user_data as $key ) {
|
61 |
+
$row[] = $userdata->data->{$key};
|
62 |
+
}
|
63 |
+
|
64 |
+
foreach ( $this->get_user_meta_key() as $key ) {
|
65 |
+
$current_data = get_user_meta( $user, $key, true );
|
66 |
+
|
67 |
+
if( is_array( $current_data ) )
|
68 |
+
$row[] = serialize( $current_data );
|
69 |
+
else
|
70 |
+
$row[] = $current_data;
|
71 |
+
}
|
72 |
+
|
73 |
+
$data[] = $row;
|
74 |
+
$row = array();
|
75 |
+
}
|
76 |
+
|
77 |
+
// export to csv
|
78 |
+
$file = fopen( $this->path_csv, "w" );
|
79 |
+
|
80 |
+
foreach ( $data as $line ) {
|
81 |
+
fputcsv( $file, $line );
|
82 |
+
}
|
83 |
+
|
84 |
+
fclose( $file );
|
85 |
+
|
86 |
+
$fsize = filesize( $this->path_csv );
|
87 |
+
$path_parts = pathinfo( $this->path_csv );
|
88 |
+
header( "Content-type: text/csv" );
|
89 |
+
header( "Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"" );
|
90 |
+
header( "Content-length: $fsize" );
|
91 |
+
header( "Cache-control: private" );
|
92 |
+
header('Content-Description: File Transfer');
|
93 |
+
header('Content-Transfer-Encoding: binary');
|
94 |
+
header('Expires: 0');
|
95 |
+
header('Cache-Control: must-revalidate');
|
96 |
+
header('Pragma: public');
|
97 |
+
|
98 |
+
ob_clean();
|
99 |
+
flush();
|
100 |
+
readfile( $this->path_csv );
|
101 |
+
|
102 |
+
unlink( $this->path_csv );
|
103 |
+
|
104 |
+
die();
|
105 |
+
}
|
106 |
+
|
107 |
+
function get_user_meta_key() {
|
108 |
+
global $wpdb;
|
109 |
+
$meta_keys = array();
|
110 |
+
|
111 |
+
$select = "SELECT distinct $wpdb->usermeta.meta_key FROM $wpdb->usermeta";
|
112 |
+
$usermeta = $wpdb->get_results( $select, ARRAY_A );
|
113 |
+
|
114 |
+
foreach ($usermeta as $key => $value) {
|
115 |
+
$meta_keys[] = $value["meta_key"];
|
116 |
+
}
|
117 |
+
return $meta_keys;
|
118 |
+
}
|
119 |
+
|
120 |
+
function get_user_id_list(){
|
121 |
+
$users = get_users( array( 'fields' => array( 'ID' ) ) );
|
122 |
+
$list = array();
|
123 |
+
|
124 |
+
foreach ( $users as $user ) {
|
125 |
+
$list[] = $user->ID;
|
126 |
+
}
|
127 |
+
|
128 |
+
return $list;
|
129 |
+
}
|
130 |
+
}
|
131 |
+
|
132 |
+
$acui_exporter = new ACUI_Exporter();
|
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
|
@@ -23,6 +23,7 @@ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
|
23 |
|
24 |
require_once( "classes/email-templates.php" );
|
25 |
require_once( "classes/homepage.php" );
|
|
|
26 |
require_once( "classes/columns.php" );
|
27 |
require_once( "classes/frontend.php" );
|
28 |
require_once( "classes/doc.php" );
|
@@ -269,7 +270,8 @@ function acui_check_options(){
|
|
269 |
|
270 |
function acui_admin_tabs( $current = 'homepage' ) {
|
271 |
$tabs = array(
|
272 |
-
'homepage' => __( 'Import', 'import-users-from-csv-with-meta' ),
|
|
|
273 |
'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
|
274 |
'cron' => __( 'Cron import', 'import-users-from-csv-with-meta' ),
|
275 |
'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
|
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.15
|
7 |
Author: codection
|
8 |
Author URI: https://codection.com
|
9 |
License: GPL2
|
23 |
|
24 |
require_once( "classes/email-templates.php" );
|
25 |
require_once( "classes/homepage.php" );
|
26 |
+
require_once( "classes/export.php" );
|
27 |
require_once( "classes/columns.php" );
|
28 |
require_once( "classes/frontend.php" );
|
29 |
require_once( "classes/doc.php" );
|
270 |
|
271 |
function acui_admin_tabs( $current = 'homepage' ) {
|
272 |
$tabs = array(
|
273 |
+
'homepage' => __( 'Import', 'import-users-from-csv-with-meta' ),
|
274 |
+
'export' => __( 'Export', 'import-users-from-csv-with-meta' ),
|
275 |
'frontend' => __( 'Frontend', 'import-users-from-csv-with-meta' ),
|
276 |
'cron' => __( 'Cron import', 'import-users-from-csv-with-meta' ),
|
277 |
'columns' => __( 'Extra profile fields', 'import-users-from-csv-with-meta' ),
|
importer.php
CHANGED
@@ -762,6 +762,10 @@ function acui_options(){
|
|
762 |
ACUI_Homepage::admin_gui();
|
763 |
break;
|
764 |
|
|
|
|
|
|
|
|
|
765 |
case 'frontend':
|
766 |
ACUI_Frontend::admin_gui();
|
767 |
break;
|
762 |
ACUI_Homepage::admin_gui();
|
763 |
break;
|
764 |
|
765 |
+
case 'export' :
|
766 |
+
ACUI_Exporter::admin_gui();
|
767 |
+
break;
|
768 |
+
|
769 |
case 'frontend':
|
770 |
ACUI_Frontend::admin_gui();
|
771 |
break;
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: carazo, hornero
|
|
3 |
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.3
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -91,6 +91,9 @@ Plugin will automatically detect:
|
|
91 |
|
92 |
== Changelog ==
|
93 |
|
|
|
|
|
|
|
94 |
= 1.14.3.10 =
|
95 |
* Changed the way HTML emails are declared to prevent problems with plugins like WP HTML Mail
|
96 |
|
3 |
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.3.2
|
7 |
+
Stable tag: 1.15
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
+
= 1.15 =
|
95 |
+
* Export option included
|
96 |
+
|
97 |
= 1.14.3.10 =
|
98 |
* Changed the way HTML emails are declared to prevent problems with plugins like WP HTML Mail
|
99 |
|