Version Description
- added commit by @cwjordan to allow for fields update time - thanks :)
Download this release
Release Info
Developer | qlstudio |
Plugin | Export User Data |
Version | 0.7.4 |
Comparing to | |
See all releases |
Code changes from version 0.7.3 to 0.7.4
- export-user-data.php +110 -57
- readme.txt +6 -5
export-user-data.php
CHANGED
@@ -1,13 +1,10 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
* @package Export_User_Data
|
4 |
-
* @version 0.7.3
|
5 |
-
*/
|
6 |
/*
|
7 |
Plugin Name: Export User Data
|
8 |
Plugin URI: http://qstudio.us/plugins/
|
9 |
Description: Export User data, metadata and BuddyPressX Profile data.
|
10 |
-
Version: 0.7.
|
11 |
Author: Q Studio
|
12 |
Author URI: http://qstudio.us/
|
13 |
License: GPL2
|
@@ -33,11 +30,13 @@ class Q_EUD_Export_Users {
|
|
33 |
* @since 0.1
|
34 |
**/
|
35 |
public function __construct() {
|
|
|
36 |
add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
|
37 |
add_action( 'init', array( $this, 'generate_data' ) );
|
38 |
add_filter( 'q_eud_exclude_data', array( $this, 'exclude_data' ) );
|
39 |
add_action( 'admin_init', array( $this, 'add_css_and_js' ) );
|
40 |
-
add_action( 'admin_footer', array( $this, '
|
|
|
41 |
}
|
42 |
|
43 |
|
@@ -47,34 +46,40 @@ class Q_EUD_Export_Users {
|
|
47 |
* @since 0.1
|
48 |
**/
|
49 |
public function add_admin_pages() {
|
|
|
50 |
add_users_page( __( 'Export User Data', 'export-user-data' ), __( 'Export User Data', 'export-user-data' ), 'list_users', 'export-user-data', array( $this, 'users_page' ) );
|
51 |
-
|
52 |
}
|
53 |
|
54 |
|
55 |
/* style and interaction */
|
56 |
function add_css_and_js() {
|
|
|
57 |
wp_register_style('q_eud_multi_select_css', plugins_url('css/multi-select.css',__FILE__ ));
|
58 |
wp_enqueue_style('q_eud_multi_select_css');
|
59 |
wp_enqueue_script('q_eud_multi_select_js', plugins_url('js/jquery.multi-select.js',__FILE__ ), array('jquery'), '0.9.8', false );
|
|
|
60 |
}
|
61 |
|
62 |
|
63 |
/* clean that stuff up ## */
|
64 |
public function sanitize($value) {
|
|
|
65 |
$value = str_replace("\r", '', $value);
|
66 |
$value = str_replace("\n", '', $value);
|
67 |
$value = str_replace("\t", '', $value);
|
68 |
return $value;
|
|
|
69 |
}
|
70 |
|
71 |
|
72 |
-
/*
|
73 |
-
function
|
74 |
?>
|
75 |
<script>
|
|
|
76 |
// build super multiselect ##
|
77 |
-
jQuery('#usermeta, #bp_fields').multiSelect();
|
78 |
|
79 |
// show only common ##
|
80 |
jQuery('.usermeta-common').click(function(e){
|
@@ -88,6 +93,18 @@ class Q_EUD_Export_Users {
|
|
88 |
jQuery('#ms-usermeta .ms-selectable li').show();
|
89 |
});
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
</script>
|
92 |
<?php
|
93 |
}
|
@@ -98,7 +115,9 @@ class Q_EUD_Export_Users {
|
|
98 |
* @since 0.1
|
99 |
**/
|
100 |
public function generate_data() {
|
|
|
101 |
if ( isset( $_POST['_wpnonce-q-eud-export-user-page_export'] ) ) {
|
|
|
102 |
check_admin_referer( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' );
|
103 |
|
104 |
// build argument array ##
|
@@ -116,19 +135,25 @@ class Q_EUD_Export_Users {
|
|
116 |
|
117 |
}
|
118 |
|
|
|
119 |
add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
120 |
$users = get_users( $args );
|
121 |
remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
122 |
|
|
|
123 |
if ( ! $users ) {
|
|
|
124 |
$referer = add_query_arg( 'error', 'empty', wp_get_referer() );
|
125 |
wp_redirect( $referer );
|
126 |
exit;
|
|
|
127 |
}
|
128 |
|
|
|
129 |
$sitename = sanitize_key( get_bloginfo( 'name' ) );
|
130 |
-
if ( ! empty( $sitename ) )
|
131 |
-
|
|
|
132 |
|
133 |
// export method ? ##
|
134 |
$export_method = 'excel'; // default to Excel export ##
|
@@ -145,29 +170,30 @@ class Q_EUD_Export_Users {
|
|
145 |
|
146 |
case "csv":
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
|
158 |
case ('excel'):
|
159 |
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
171 |
|
172 |
}
|
173 |
|
@@ -201,6 +227,18 @@ class Q_EUD_Export_Users {
|
|
201 |
}
|
202 |
}
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
// global wpdb object ##
|
205 |
global $wpdb;
|
206 |
|
@@ -213,7 +251,7 @@ class Q_EUD_Export_Users {
|
|
213 |
);
|
214 |
|
215 |
// compile final fields list ##
|
216 |
-
$fields = array_merge( $data_keys, $usermeta_fields, $bp_fields_passed );
|
217 |
|
218 |
// build the document headers ##
|
219 |
$headers = array();
|
@@ -254,7 +292,12 @@ class Q_EUD_Export_Users {
|
|
254 |
$value = $value['field_data'];
|
255 |
}
|
256 |
$value = $this->sanitize($value);
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
258 |
// user data or usermeta ##
|
259 |
} else {
|
260 |
|
@@ -344,26 +387,6 @@ class Q_EUD_Export_Users {
|
|
344 |
|
345 |
// allow array to be filtered ##
|
346 |
$meta_keys_system = apply_filters( 'export_user_data_meta_keys_system', $meta_keys_system );
|
347 |
-
|
348 |
-
/*
|
349 |
-
foreach ( $meta_keys as $key ) {
|
350 |
-
|
351 |
-
foreach ( $meta_keys_system as $drop ) {
|
352 |
-
|
353 |
-
if ( strpos( $key, $drop ) !== false ) {
|
354 |
-
|
355 |
-
#echo 'FOUND -- '.$drop.' in '.$key.'<br />';
|
356 |
-
|
357 |
-
if(($key = array_search($key, $meta_keys)) !== false) {
|
358 |
-
unset($meta_keys[$key]);
|
359 |
-
}
|
360 |
-
|
361 |
-
}
|
362 |
-
|
363 |
-
}
|
364 |
-
|
365 |
-
}
|
366 |
-
*/
|
367 |
|
368 |
// test array ##
|
369 |
#echo '<pre>'; var_dump($meta_keys); echo '</pre>';
|
@@ -454,7 +477,7 @@ class Q_EUD_Export_Users {
|
|
454 |
<th scope="row"><label for="q_eud_xprofile"><?php _e( 'BP xProfile Fields', 'export-user-data' ); ?></label></th>
|
455 |
<td>
|
456 |
<select multiple="multiple" id="bp_fields" name="bp_fields[]">
|
457 |
-
|
458 |
|
459 |
foreach ( $bp_fields as $key ) {
|
460 |
|
@@ -467,11 +490,40 @@ class Q_EUD_Export_Users {
|
|
467 |
echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."'>$key</option>";
|
468 |
|
469 |
}
|
470 |
-
|
|
|
471 |
</select>
|
472 |
</td>
|
473 |
</tr>
|
474 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
|
476 |
} // BP installed and active ##
|
477 |
|
@@ -525,7 +577,7 @@ class Q_EUD_Export_Users {
|
|
525 |
|
526 |
?>
|
527 |
<tr valign="top">
|
528 |
-
<th scope="row"><label><?php _e( '
|
529 |
<td>
|
530 |
<select name="start_date" id="q_eud_users_start_date">
|
531 |
<option value="0"><?php _e( 'Start Date', 'export-user-data' ); ?></option>
|
@@ -606,4 +658,5 @@ class Q_EUD_Export_Users {
|
|
606 |
}
|
607 |
}
|
608 |
|
609 |
-
|
|
1 |
<?php
|
2 |
+
|
|
|
|
|
|
|
3 |
/*
|
4 |
Plugin Name: Export User Data
|
5 |
Plugin URI: http://qstudio.us/plugins/
|
6 |
Description: Export User data, metadata and BuddyPressX Profile data.
|
7 |
+
Version: 0.7.4
|
8 |
Author: Q Studio
|
9 |
Author URI: http://qstudio.us/
|
10 |
License: GPL2
|
30 |
* @since 0.1
|
31 |
**/
|
32 |
public function __construct() {
|
33 |
+
|
34 |
add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
|
35 |
add_action( 'init', array( $this, 'generate_data' ) );
|
36 |
add_filter( 'q_eud_exclude_data', array( $this, 'exclude_data' ) );
|
37 |
add_action( 'admin_init', array( $this, 'add_css_and_js' ) );
|
38 |
+
add_action( 'admin_footer', array( $this, 'jquery' ), 100000 );
|
39 |
+
|
40 |
}
|
41 |
|
42 |
|
46 |
* @since 0.1
|
47 |
**/
|
48 |
public function add_admin_pages() {
|
49 |
+
|
50 |
add_users_page( __( 'Export User Data', 'export-user-data' ), __( 'Export User Data', 'export-user-data' ), 'list_users', 'export-user-data', array( $this, 'users_page' ) );
|
51 |
+
|
52 |
}
|
53 |
|
54 |
|
55 |
/* style and interaction */
|
56 |
function add_css_and_js() {
|
57 |
+
|
58 |
wp_register_style('q_eud_multi_select_css', plugins_url('css/multi-select.css',__FILE__ ));
|
59 |
wp_enqueue_style('q_eud_multi_select_css');
|
60 |
wp_enqueue_script('q_eud_multi_select_js', plugins_url('js/jquery.multi-select.js',__FILE__ ), array('jquery'), '0.9.8', false );
|
61 |
+
|
62 |
}
|
63 |
|
64 |
|
65 |
/* clean that stuff up ## */
|
66 |
public function sanitize($value) {
|
67 |
+
|
68 |
$value = str_replace("\r", '', $value);
|
69 |
$value = str_replace("\n", '', $value);
|
70 |
$value = str_replace("\t", '', $value);
|
71 |
return $value;
|
72 |
+
|
73 |
}
|
74 |
|
75 |
|
76 |
+
/* jquery */
|
77 |
+
function jquery() {
|
78 |
?>
|
79 |
<script>
|
80 |
+
|
81 |
// build super multiselect ##
|
82 |
+
jQuery('#usermeta, #bp_fields, #bp_fields_update_time').multiSelect();
|
83 |
|
84 |
// show only common ##
|
85 |
jQuery('.usermeta-common').click(function(e){
|
93 |
jQuery('#ms-usermeta .ms-selectable li').show();
|
94 |
});
|
95 |
|
96 |
+
// toggle update options ##
|
97 |
+
jQuery(".toggle a").click( function(e) {
|
98 |
+
e.preventDefault();
|
99 |
+
$toggle = jQuery(this).parent().next("div.select");
|
100 |
+
$toggle.toggle();
|
101 |
+
if ( $toggle.is(":visible") ) {
|
102 |
+
jQuery(this).text("Hide Date Options");
|
103 |
+
} else {
|
104 |
+
jQuery(this).text("Show Date Options");
|
105 |
+
}
|
106 |
+
});
|
107 |
+
|
108 |
</script>
|
109 |
<?php
|
110 |
}
|
115 |
* @since 0.1
|
116 |
**/
|
117 |
public function generate_data() {
|
118 |
+
|
119 |
if ( isset( $_POST['_wpnonce-q-eud-export-user-page_export'] ) ) {
|
120 |
+
|
121 |
check_admin_referer( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' );
|
122 |
|
123 |
// build argument array ##
|
135 |
|
136 |
}
|
137 |
|
138 |
+
/* pre_user query */
|
139 |
add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
140 |
$users = get_users( $args );
|
141 |
remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
142 |
|
143 |
+
/* no users found, so chuck and error into the args array */
|
144 |
if ( ! $users ) {
|
145 |
+
|
146 |
$referer = add_query_arg( 'error', 'empty', wp_get_referer() );
|
147 |
wp_redirect( $referer );
|
148 |
exit;
|
149 |
+
|
150 |
}
|
151 |
|
152 |
+
/* get sitename and clean it up */
|
153 |
$sitename = sanitize_key( get_bloginfo( 'name' ) );
|
154 |
+
if ( ! empty( $sitename ) ) {
|
155 |
+
$sitename .= '.';
|
156 |
+
}
|
157 |
|
158 |
// export method ? ##
|
159 |
$export_method = 'excel'; // default to Excel export ##
|
170 |
|
171 |
case "csv":
|
172 |
|
173 |
+
// to csv ##
|
174 |
+
header( 'Content-Description: File Transfer' );
|
175 |
+
header( 'Content-Disposition: attachment; filename='.$filename.'.csv' );
|
176 |
+
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
|
177 |
|
178 |
+
// how to seperate data ##
|
179 |
+
$seperator = ','; // comma for csv ##
|
180 |
+
|
181 |
+
break;
|
182 |
|
183 |
case ('excel'):
|
184 |
|
185 |
+
// to xls ##
|
186 |
+
header( 'Content-Description: File Transfer' );
|
187 |
+
header("Content-Type: application/vnd.ms-excel");
|
188 |
+
header("Content-Disposition: attachment; filename=$filename.xls");
|
189 |
+
header("Pragma: no-cache");
|
190 |
+
header("Expires: 0");
|
191 |
+
#echo "\xEF\xBB\xBF"; // UTF-8 BOM ##
|
192 |
+
|
193 |
+
// how to seperate data ##
|
194 |
+
$seperator = "\t"; // tabbed character ##
|
195 |
+
|
196 |
+
break;
|
197 |
|
198 |
}
|
199 |
|
227 |
}
|
228 |
}
|
229 |
|
230 |
+
// cwjordan: check for x profile fields we want update time for ##
|
231 |
+
$bp_fields_update = isset( $_POST['bp_fields_update_time'] ) ? $_POST['bp_fields_update_time'] : '';
|
232 |
+
$bp_fields_update_passed = array();
|
233 |
+
if ( $bp_fields_update && is_array($bp_fields_update ) ) {
|
234 |
+
foreach( $bp_fields_update as $field ) {
|
235 |
+
// reverse tidy ##
|
236 |
+
$field = str_replace( '__', ' ', $field );
|
237 |
+
// add to array ##
|
238 |
+
$bp_fields_update_passed[] = $field . " Update Date";
|
239 |
+
}
|
240 |
+
}
|
241 |
+
|
242 |
// global wpdb object ##
|
243 |
global $wpdb;
|
244 |
|
251 |
);
|
252 |
|
253 |
// compile final fields list ##
|
254 |
+
$fields = array_merge( $data_keys, $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed );
|
255 |
|
256 |
// build the document headers ##
|
257 |
$headers = array();
|
292 |
$value = $value['field_data'];
|
293 |
}
|
294 |
$value = $this->sanitize($value);
|
295 |
+
// check if this is a BP field we want update date for ##
|
296 |
+
} elseif ( in_array( $field, $bp_fields_update_passed ) ) {
|
297 |
+
global $bp;
|
298 |
+
$real_field = str_replace(" Update Date", "", $field);
|
299 |
+
$field_id = xprofile_get_field_id_from_name( $real_field );
|
300 |
+
$value = $wpdb->get_var ($wpdb->prepare( "SELECT last_updated FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = %d", $user->ID, $field_id ) );
|
301 |
// user data or usermeta ##
|
302 |
} else {
|
303 |
|
387 |
|
388 |
// allow array to be filtered ##
|
389 |
$meta_keys_system = apply_filters( 'export_user_data_meta_keys_system', $meta_keys_system );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
390 |
|
391 |
// test array ##
|
392 |
#echo '<pre>'; var_dump($meta_keys); echo '</pre>';
|
477 |
<th scope="row"><label for="q_eud_xprofile"><?php _e( 'BP xProfile Fields', 'export-user-data' ); ?></label></th>
|
478 |
<td>
|
479 |
<select multiple="multiple" id="bp_fields" name="bp_fields[]">
|
480 |
+
<?php
|
481 |
|
482 |
foreach ( $bp_fields as $key ) {
|
483 |
|
490 |
echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."'>$key</option>";
|
491 |
|
492 |
}
|
493 |
+
|
494 |
+
?>
|
495 |
</select>
|
496 |
</td>
|
497 |
</tr>
|
498 |
<?php
|
499 |
+
|
500 |
+
// allow export of update times ##
|
501 |
+
|
502 |
+
?>
|
503 |
+
<tr valign="top">
|
504 |
+
<th scope="row">
|
505 |
+
<label for="q_eud_xprofile"><?php _e( 'BP xProfile Fields Update Time', 'export-user-data' ); ?></label>
|
506 |
+
</th>
|
507 |
+
<td>
|
508 |
+
<div class="toggle">
|
509 |
+
<a href="#"><?php _e( 'Show Date Options', 'export-user-data' ); ?></a>
|
510 |
+
</div>
|
511 |
+
<div class="select" style="display: none;">
|
512 |
+
<select multiple="multiple" id="bp_fields_update_time" name="bp_fields_update_time[]">
|
513 |
+
<?php
|
514 |
+
|
515 |
+
foreach ( $bp_fields as $key ) {
|
516 |
+
|
517 |
+
echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."'>$key</option>";
|
518 |
+
|
519 |
+
}
|
520 |
+
|
521 |
+
?>
|
522 |
+
</select>
|
523 |
+
</div>
|
524 |
+
</td>
|
525 |
+
</tr>
|
526 |
+
<?php
|
527 |
|
528 |
} // BP installed and active ##
|
529 |
|
577 |
|
578 |
?>
|
579 |
<tr valign="top">
|
580 |
+
<th scope="row"><label><?php _e( 'Registered', 'export-user-data' ); ?></label></th>
|
581 |
<td>
|
582 |
<select name="start_date" id="q_eud_users_start_date">
|
583 |
<option value="0"><?php _e( 'Start Date', 'export-user-data' ); ?></option>
|
658 |
}
|
659 |
}
|
660 |
|
661 |
+
/* instatiate class object */
|
662 |
+
new Q_EUD_Export_Users;
|
readme.txt
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
=== Plugin Name ===
|
2 |
Contributors: Q Studio
|
3 |
-
Tags: user, users, xprofile, usermeta csv, excel, batch, export, save
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.6
|
6 |
-
Stable tag: 0.7.
|
7 |
License: GPLv2
|
8 |
|
9 |
Export users data, metadata and buddypress xprofile data to a csv or Excel file
|
@@ -14,8 +14,6 @@ A plugin that exports ALL user data, meta data and BuddyPress xProfile data.
|
|
14 |
|
15 |
Includes an option to export the users by role, registration date range, usermeta option and two export formats.
|
16 |
|
17 |
-
Based on: http://wordpress.org/plugins/export-users-to-csv/
|
18 |
-
|
19 |
= Features =
|
20 |
|
21 |
* Exports all users fields
|
@@ -60,6 +58,9 @@ Click on the 'Export User Data' link in the 'Users' menu, choose the role and th
|
|
60 |
|
61 |
== Changelog ==
|
62 |
|
|
|
|
|
|
|
63 |
= 0.7.3 =
|
64 |
* fixes to allow exports without selecting extra user date from usermeta or x-profile
|
65 |
|
@@ -71,7 +72,7 @@ Click on the 'Export User Data' link in the 'Users' menu, choose the role and th
|
|
71 |
|
72 |
== Upgrade Notice ==
|
73 |
|
74 |
-
= 0.
|
75 |
Latest.
|
76 |
|
77 |
= 0.5 =
|
1 |
=== Plugin Name ===
|
2 |
Contributors: Q Studio
|
3 |
+
Tags: user, users, xprofile, usermeta, csv, excel, batch, export, save
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.6
|
6 |
+
Stable tag: 0.7.4
|
7 |
License: GPLv2
|
8 |
|
9 |
Export users data, metadata and buddypress xprofile data to a csv or Excel file
|
14 |
|
15 |
Includes an option to export the users by role, registration date range, usermeta option and two export formats.
|
16 |
|
|
|
|
|
17 |
= Features =
|
18 |
|
19 |
* Exports all users fields
|
58 |
|
59 |
== Changelog ==
|
60 |
|
61 |
+
= 0.7.4 =
|
62 |
+
* added commit by @cwjordan to allow for fields update time - thanks :)
|
63 |
+
|
64 |
= 0.7.3 =
|
65 |
* fixes to allow exports without selecting extra user date from usermeta or x-profile
|
66 |
|
72 |
|
73 |
== Upgrade Notice ==
|
74 |
|
75 |
+
= 0.7.4 =
|
76 |
Latest.
|
77 |
|
78 |
= 0.5 =
|