Version Description
- added xml template for Excel exports - thanks to phil@fixitlab.com :)
Download this release
Release Info
Developer | qlstudio |
Plugin | Export User Data |
Version | 0.7.8 |
Comparing to | |
See all releases |
Code changes from version 0.7.6 to 0.7.8
- export-user-data.php +301 -211
- readme.txt +5 -4
- xml-template.php +38 -0
export-user-data.php
CHANGED
@@ -4,7 +4,7 @@
|
|
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.
|
8 |
Author: Q Studio
|
9 |
Author URI: http://qstudio.us/
|
10 |
License: GPL2
|
@@ -120,215 +120,296 @@ class Q_EUD_Export_Users {
|
|
120 |
*
|
121 |
* @since 0.1
|
122 |
**/
|
123 |
-
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
// build argument array ##
|
130 |
-
$args = array(
|
131 |
-
'fields' => 'all_with_meta',
|
132 |
-
'role' => stripslashes( $_POST['role'] )
|
133 |
-
);
|
134 |
-
|
135 |
-
// did the user request a specific program ? ##
|
136 |
-
if ( isset( $_POST['program'] ) && $_POST['program'] != '' ) {
|
137 |
-
|
138 |
-
$args['meta_key'] = 'member_of_club';
|
139 |
-
$args['meta_value'] = (int)$_POST['program'];
|
140 |
-
$args['meta_compare'] = '=';
|
141 |
-
|
142 |
-
}
|
143 |
-
|
144 |
-
/* pre_user query */
|
145 |
-
add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
146 |
-
$users = get_users( $args );
|
147 |
-
remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
148 |
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
exit;
|
155 |
-
|
156 |
-
}
|
157 |
|
158 |
-
|
159 |
-
|
160 |
-
if ( ! empty( $sitename ) ) {
|
161 |
-
$sitename .= '.';
|
162 |
-
}
|
163 |
-
|
164 |
-
// export method ? ##
|
165 |
-
$export_method = 'excel'; // default to Excel export ##
|
166 |
-
if ( isset( $_POST['format'] ) && $_POST['format'] != '' ) {
|
167 |
-
|
168 |
-
$export_method = $_POST['format'];
|
169 |
-
|
170 |
-
}
|
171 |
-
|
172 |
-
// set export filename structure ##
|
173 |
-
$filename = $sitename . 'users.' . date( 'Y-m-d-H-i-s' );
|
174 |
-
|
175 |
-
switch ( $export_method ) {
|
176 |
-
|
177 |
-
case "csv":
|
178 |
-
|
179 |
-
// to csv ##
|
180 |
-
header( 'Content-Description: File Transfer' );
|
181 |
-
header( 'Content-Disposition: attachment; filename='.$filename.'.csv' );
|
182 |
-
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
|
183 |
|
184 |
-
|
185 |
-
|
|
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
case ('excel'):
|
190 |
-
|
191 |
-
// to xls ##
|
192 |
-
header( 'Content-Description: File Transfer' );
|
193 |
-
header("Content-Type: application/vnd.ms-excel");
|
194 |
-
header("Content-Disposition: attachment; filename=$filename.xls");
|
195 |
-
header("Pragma: no-cache");
|
196 |
-
header("Expires: 0");
|
197 |
-
#echo "\xEF\xBB\xBF"; // UTF-8 BOM ##
|
198 |
-
|
199 |
-
// how to seperate data ##
|
200 |
-
$seperator = "\t"; // tabbed character ##
|
201 |
-
|
202 |
-
break;
|
203 |
-
|
204 |
-
}
|
205 |
-
|
206 |
-
// line break ##
|
207 |
-
$breaker = "\n";
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
$usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
|
214 |
-
$usermeta_fields = array();
|
215 |
-
if ( $usermeta && is_array($usermeta) ) {
|
216 |
-
foreach( $usermeta as $field ) {
|
217 |
-
$usermeta_fields[] = $field;
|
218 |
-
}
|
219 |
-
}
|
220 |
-
|
221 |
-
// check for selected x profile fields ##
|
222 |
-
$bp_fields = isset( $_POST['bp_fields'] ) ? $_POST['bp_fields'] : '';
|
223 |
-
$bp_fields_passed = array();
|
224 |
-
if ( $bp_fields && is_array($bp_fields) ) {
|
225 |
-
foreach( $bp_fields as $field ) {
|
226 |
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
231 |
-
|
|
|
232 |
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
}
|
235 |
-
|
236 |
-
// cwjordan: check for x profile fields we want update time for ##
|
237 |
-
$bp_fields_update = isset( $_POST['bp_fields_update_time'] ) ? $_POST['bp_fields_update_time'] : '';
|
238 |
-
$bp_fields_update_passed = array();
|
239 |
-
if ( $bp_fields_update && is_array($bp_fields_update ) ) {
|
240 |
-
foreach( $bp_fields_update as $field ) {
|
241 |
-
// reverse tidy ##
|
242 |
-
$field = str_replace( '__', ' ', $field );
|
243 |
-
// add to array ##
|
244 |
-
$bp_fields_update_passed[] = $field . " Update Date";
|
245 |
-
}
|
246 |
-
}
|
247 |
-
|
248 |
-
// global wpdb object ##
|
249 |
-
global $wpdb;
|
250 |
-
|
251 |
-
// exportable user data ##
|
252 |
-
$data_keys = array(
|
253 |
-
'ID', 'user_login', 'user_pass',
|
254 |
-
'user_nicename', 'user_email', 'user_url',
|
255 |
-
'user_registered', /*'user_activation_key',*/ /*'user_status',*/
|
256 |
-
'display_name'
|
257 |
-
);
|
258 |
-
|
259 |
-
// compile final fields list ##
|
260 |
-
$fields = array_merge( $data_keys, $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed );
|
261 |
-
|
262 |
-
// build the document headers ##
|
263 |
-
$headers = array();
|
264 |
-
foreach ( $fields as $key => $field ) {
|
265 |
-
|
266 |
-
// rename programs field ##
|
267 |
-
if ( $field == 'member_of_club' ){
|
268 |
-
$field = 'Program';
|
269 |
-
}
|
270 |
|
271 |
-
|
272 |
-
|
273 |
-
else
|
274 |
-
$headers[] = '"' . $field . '"';
|
275 |
-
|
276 |
-
}
|
277 |
-
|
278 |
-
// echo headers ##
|
279 |
-
echo implode( $seperator, $headers ) . $breaker;
|
280 |
|
281 |
-
|
282 |
-
foreach ( $users as $user ) {
|
283 |
-
|
284 |
-
$data = array();
|
285 |
-
foreach ( $fields as $field ) {
|
286 |
-
|
287 |
-
// BP loaded ? ##
|
288 |
-
if ( function_exists ('bp_is_active') ) {
|
289 |
-
$bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID);
|
290 |
-
}
|
291 |
-
|
292 |
-
// check if this is a BP field ##
|
293 |
-
if ( in_array( $field, $bp_fields_passed ) ) {
|
294 |
-
|
295 |
-
$value = $bp_data[$field];
|
296 |
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
} elseif ( in_array( $field, $bp_fields_update_passed ) ) {
|
303 |
-
global $bp;
|
304 |
-
$real_field = str_replace(" Update Date", "", $field);
|
305 |
-
$field_id = xprofile_get_field_id_from_name( $real_field );
|
306 |
-
$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 ) );
|
307 |
-
// user data or usermeta ##
|
308 |
-
} else {
|
309 |
-
|
310 |
-
$value = isset( $user->{$field} ) ? $user->{$field} : '';
|
311 |
-
$value = is_array( $value ) ? serialize( $value ) : $value;
|
312 |
-
|
313 |
-
}
|
314 |
-
|
315 |
-
// correct program value to Program Name ##
|
316 |
-
if ( $field == 'member_of_club' ){
|
317 |
-
$value = get_the_title($value);
|
318 |
-
}
|
319 |
-
|
320 |
-
$data[] = '"' . str_replace( '"', '""', $value ) . '"';
|
321 |
-
|
322 |
-
}
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
/**
|
334 |
* Content of the settings page
|
@@ -620,12 +701,16 @@ class Q_EUD_Export_Users {
|
|
620 |
|
621 |
// data to exclude from export ##
|
622 |
public function exclude_data() {
|
|
|
623 |
$exclude = array( 'user_pass', 'user_activation_key' );
|
624 |
return $exclude;
|
|
|
625 |
}
|
626 |
|
|
|
627 |
public function pre_user_query( $user_search ) {
|
628 |
-
|
|
|
629 |
|
630 |
$where = '';
|
631 |
|
@@ -639,29 +724,34 @@ class Q_EUD_Export_Users {
|
|
639 |
$user_search->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 $where", $user_search->query_where );
|
640 |
|
641 |
return $user_search;
|
|
|
642 |
}
|
643 |
|
|
|
644 |
private function export_date_options() {
|
645 |
-
|
|
|
646 |
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
|
661 |
-
|
662 |
-
|
663 |
-
|
|
|
664 |
}
|
|
|
665 |
}
|
666 |
|
667 |
/* instatiate class object */
|
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.8
|
8 |
Author: Q Studio
|
9 |
Author URI: http://qstudio.us/
|
10 |
License: GPL2
|
120 |
*
|
121 |
* @since 0.1
|
122 |
**/
|
123 |
+
public function generate_data() {
|
124 |
|
125 |
+
if ( ! isset( $_POST['_wpnonce-q-eud-export-user-page_export'] ) ) {
|
126 |
+
|
127 |
+
return false;
|
128 |
+
|
129 |
+
}
|
130 |
|
131 |
+
check_admin_referer( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
+
// build argument array ##
|
134 |
+
$args = array(
|
135 |
+
'fields' => 'all_with_meta',
|
136 |
+
'role' => stripslashes( $_POST['role'] )
|
137 |
+
);
|
|
|
|
|
|
|
138 |
|
139 |
+
// did the user request a specific program ? ##
|
140 |
+
if ( isset( $_POST['program'] ) && $_POST['program'] != '' ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
+
$args['meta_key'] = 'member_of_club';
|
143 |
+
$args['meta_value'] = (int)$_POST['program'];
|
144 |
+
$args['meta_compare'] = '=';
|
145 |
|
146 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
/* pre_user query */
|
149 |
+
add_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
150 |
+
$users = get_users( $args );
|
151 |
+
remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
|
153 |
+
/* no users found, so chuck and error into the args array */
|
154 |
+
if ( ! $users ) {
|
155 |
|
156 |
+
$referer = add_query_arg( 'error', 'empty', wp_get_referer() );
|
157 |
+
wp_redirect( $referer );
|
158 |
+
exit;
|
159 |
|
160 |
+
}
|
161 |
+
|
162 |
+
/* get sitename and clean it up */
|
163 |
+
$sitename = sanitize_key( get_bloginfo( 'name' ) );
|
164 |
+
if ( ! empty( $sitename ) ) {
|
165 |
+
$sitename .= '.';
|
166 |
+
}
|
167 |
+
|
168 |
+
// export method ? ##
|
169 |
+
$export_method = 'excel'; // default to Excel export ##
|
170 |
+
if ( isset( $_POST['format'] ) && $_POST['format'] != '' ) {
|
171 |
+
|
172 |
+
$export_method = $_POST['format'];
|
173 |
+
|
174 |
+
}
|
175 |
+
|
176 |
+
// set export filename structure ##
|
177 |
+
$filename = $sitename . 'users.' . date( 'Y-m-d-H-i-s' );
|
178 |
+
|
179 |
+
switch ( $export_method ) {
|
180 |
+
|
181 |
+
case "csv":
|
182 |
+
|
183 |
+
// to csv ##
|
184 |
+
header( 'Content-Description: File Transfer' );
|
185 |
+
header( 'Content-Disposition: attachment; filename='.$filename.'.csv' );
|
186 |
+
header( 'Content-Type: text/csv; charset=' . get_option( 'blog_charset' ), true );
|
187 |
+
|
188 |
+
// set a csv check flag
|
189 |
+
$is_csv = true;
|
190 |
+
|
191 |
+
// nothing here
|
192 |
+
$doc_begin = '';
|
193 |
+
|
194 |
+
//preformat
|
195 |
+
$pre = '';
|
196 |
+
|
197 |
+
// how to seperate data ##
|
198 |
+
$seperator = ','; // comma for csv ##
|
199 |
+
|
200 |
+
// line break ##
|
201 |
+
$breaker = "\n";
|
202 |
+
|
203 |
+
// nothing here
|
204 |
+
$doc_end = '';
|
205 |
+
|
206 |
+
break;
|
207 |
+
|
208 |
+
case ('excel'):
|
209 |
+
|
210 |
+
// to xls ##
|
211 |
+
|
212 |
+
header( 'Content-Description: File Transfer' );
|
213 |
+
header("Content-Type: application/vnd.ms-excel");
|
214 |
+
header("Content-Disposition: attachment; filename=$filename.xls");
|
215 |
+
header("Pragma: no-cache");
|
216 |
+
header("Expires: 0");
|
217 |
+
#echo "\xEF\xBB\xBF"; // UTF-8 BOM ##
|
218 |
+
|
219 |
+
|
220 |
+
// set a csv check flag
|
221 |
+
$is_csv = false;
|
222 |
+
|
223 |
+
//grab the template file (for tidy formatting)
|
224 |
+
include( 'xml-template.php' );
|
225 |
+
|
226 |
+
// open xml
|
227 |
+
$doc_begin = $xml_doc_begin;
|
228 |
+
|
229 |
+
//preformat
|
230 |
+
$pre = $xml_pre;
|
231 |
+
|
232 |
+
// how to seperate data ##
|
233 |
+
$seperator = $xml_seperator;
|
234 |
+
|
235 |
+
// line break ##
|
236 |
+
$breaker = $xml_breaker;
|
237 |
+
|
238 |
+
// close xml
|
239 |
+
$doc_end = $xml_doc_end;
|
240 |
+
|
241 |
+
break;
|
242 |
+
|
243 |
+
}
|
244 |
+
|
245 |
+
|
246 |
+
// function to exclude data ##
|
247 |
+
$exclude_data = apply_filters( 'q_eud_exclude_data', array() );
|
248 |
+
|
249 |
+
// check for selected usermeta fields ##
|
250 |
+
$usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
|
251 |
+
$usermeta_fields = array();
|
252 |
+
|
253 |
+
if ( $usermeta && is_array($usermeta) ) {
|
254 |
+
foreach( $usermeta as $field ) {
|
255 |
+
$usermeta_fields[] = $field;
|
256 |
+
}
|
257 |
+
}
|
258 |
+
|
259 |
+
// check for selected x profile fields ##
|
260 |
+
$bp_fields = isset( $_POST['bp_fields'] ) ? $_POST['bp_fields'] : '';
|
261 |
+
$bp_fields_passed = array();
|
262 |
+
if ( $bp_fields && is_array($bp_fields) ) {
|
263 |
+
|
264 |
+
foreach( $bp_fields as $field ) {
|
265 |
+
|
266 |
+
// reverse tidy ##
|
267 |
+
$field = str_replace( '__', ' ', $field );
|
268 |
+
|
269 |
+
// add to array ##
|
270 |
+
$bp_fields_passed[] = $field;
|
271 |
+
|
272 |
+
}
|
273 |
+
|
274 |
+
}
|
275 |
+
|
276 |
+
// cwjordan: check for x profile fields we want update time for ##
|
277 |
+
$bp_fields_update = isset( $_POST['bp_fields_update_time'] ) ? $_POST['bp_fields_update_time'] : '';
|
278 |
+
$bp_fields_update_passed = array();
|
279 |
+
if ( $bp_fields_update && is_array($bp_fields_update ) ) {
|
280 |
+
|
281 |
+
foreach( $bp_fields_update as $field ) {
|
282 |
+
|
283 |
+
// reverse tidy ##
|
284 |
+
$field = str_replace( '__', ' ', $field );
|
285 |
+
|
286 |
+
// add to array ##
|
287 |
+
$bp_fields_update_passed[] = $field . " Update Date";
|
288 |
+
|
289 |
+
}
|
290 |
+
|
291 |
+
}
|
292 |
+
|
293 |
+
// global wpdb object ##
|
294 |
+
global $wpdb;
|
295 |
+
|
296 |
+
// exportable user data ##
|
297 |
+
$data_keys = array(
|
298 |
+
'ID'
|
299 |
+
, 'user_login'
|
300 |
+
#, 'user_pass'
|
301 |
+
,'user_nicename'
|
302 |
+
, 'user_email'
|
303 |
+
, 'user_url'
|
304 |
+
,'user_registered'
|
305 |
+
#, /*'user_activation_key',*/ /*'user_status',*/
|
306 |
+
,'display_name'
|
307 |
+
);
|
308 |
+
|
309 |
+
// compile final fields list ##
|
310 |
+
$fields = array_merge( $data_keys, $usermeta_fields, $bp_fields_passed, $bp_fields_update_passed );
|
311 |
+
|
312 |
+
// build the document headers ##
|
313 |
+
$headers = array();
|
314 |
+
|
315 |
+
foreach ( $fields as $key => $field ) {
|
316 |
+
|
317 |
+
// rename programs field ##
|
318 |
+
if ( $field == 'member_of_club' ){
|
319 |
+
$field = 'Program';
|
320 |
+
}
|
321 |
+
|
322 |
+
if ( in_array( $field, $exclude_data ) ) {
|
323 |
+
|
324 |
+
unset( $fields[$key] );
|
325 |
+
|
326 |
+
} else {
|
327 |
+
|
328 |
+
if ( $is_csv ) {
|
329 |
+
|
330 |
+
$headers[] = '"' . $field . '"';
|
331 |
+
|
332 |
+
} else {
|
333 |
+
|
334 |
+
$headers[] = $field;
|
335 |
+
#echo '<script>console.log("Echoing header cell: '.$field.'")</script>';
|
336 |
+
|
337 |
+
}
|
338 |
+
|
339 |
+
}
|
340 |
+
|
341 |
+
}
|
342 |
+
|
343 |
+
//open doc wrapper..
|
344 |
+
echo $doc_begin;
|
345 |
+
|
346 |
+
// echo headers ##
|
347 |
+
echo $pre . implode( $seperator, $headers ) . $breaker;
|
348 |
+
|
349 |
+
// build row values for each user ##
|
350 |
+
foreach ( $users as $user ) {
|
351 |
+
|
352 |
+
$data = array();
|
353 |
+
|
354 |
+
foreach ( $fields as $field ) {
|
355 |
+
|
356 |
+
// BP loaded ? ##
|
357 |
+
if ( function_exists ('bp_is_active') ) {
|
358 |
+
$bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID);
|
359 |
+
}
|
360 |
+
|
361 |
+
// check if this is a BP field ##
|
362 |
+
if ( in_array( $field, $bp_fields_passed ) ) {
|
363 |
+
|
364 |
+
$value = $bp_data[$field];
|
365 |
+
|
366 |
+
if ( is_array( $value ) ) {
|
367 |
+
$value = $value['field_data'];
|
368 |
}
|
369 |
+
$value = $this->sanitize($value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
|
371 |
+
// check if this is a BP field we want update date for ##
|
372 |
+
} elseif ( in_array( $field, $bp_fields_update_passed ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
+
global $bp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
|
376 |
+
$real_field = str_replace(" Update Date", "", $field);
|
377 |
+
$field_id = xprofile_get_field_id_from_name( $real_field );
|
378 |
+
$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 ) );
|
379 |
+
// user data or usermeta ##
|
380 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
|
382 |
+
$value = isset( $user->{$field} ) ? $user->{$field} : '';
|
383 |
+
$value = is_array( $value ) ? serialize( $value ) : $value;
|
384 |
+
|
385 |
+
}
|
386 |
+
|
387 |
+
// correct program value to Program Name ##
|
388 |
+
if ( $field == 'member_of_club' ) {
|
389 |
+
$value = get_the_title($value);
|
390 |
+
}
|
391 |
+
|
392 |
+
if ( $is_csv ) {
|
393 |
+
$data[] = '"' . str_replace( '"', '""', $value ) . '"';
|
394 |
+
} else {
|
395 |
+
$data[] = $value;
|
396 |
+
}
|
397 |
+
|
398 |
+
}
|
399 |
+
|
400 |
+
// echo row data ##
|
401 |
+
echo $pre . implode( $seperator, $data ) . $breaker;
|
402 |
+
|
403 |
+
}
|
404 |
+
|
405 |
+
// close doc wrapper..
|
406 |
+
echo $doc_end;
|
407 |
+
|
408 |
+
// stop PHP, so file can export correctly ##
|
409 |
+
exit;
|
410 |
+
|
411 |
+
|
412 |
+
}
|
413 |
|
414 |
/**
|
415 |
* Content of the settings page
|
701 |
|
702 |
// data to exclude from export ##
|
703 |
public function exclude_data() {
|
704 |
+
|
705 |
$exclude = array( 'user_pass', 'user_activation_key' );
|
706 |
return $exclude;
|
707 |
+
|
708 |
}
|
709 |
|
710 |
+
|
711 |
public function pre_user_query( $user_search ) {
|
712 |
+
|
713 |
+
global $wpdb;
|
714 |
|
715 |
$where = '';
|
716 |
|
724 |
$user_search->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 $where", $user_search->query_where );
|
725 |
|
726 |
return $user_search;
|
727 |
+
|
728 |
}
|
729 |
|
730 |
+
|
731 |
private function export_date_options() {
|
732 |
+
|
733 |
+
global $wpdb, $wp_locale;
|
734 |
|
735 |
+
$months = $wpdb->get_results( "
|
736 |
+
SELECT DISTINCT YEAR( user_registered ) AS year, MONTH( user_registered ) AS month
|
737 |
+
FROM $wpdb->users
|
738 |
+
ORDER BY user_registered DESC
|
739 |
+
" );
|
740 |
|
741 |
+
$month_count = count( $months );
|
742 |
+
if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
|
743 |
+
return;
|
744 |
|
745 |
+
foreach ( $months as $date ) {
|
746 |
+
if ( 0 == $date->year )
|
747 |
+
continue;
|
748 |
|
749 |
+
$month = zeroise( $date->month, 2 );
|
750 |
+
echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
|
751 |
+
}
|
752 |
+
|
753 |
}
|
754 |
+
|
755 |
}
|
756 |
|
757 |
/* instatiate class object */
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: qlstudio
|
3 |
Tags: user, users, xprofile, usermeta csv, excel, batch, export, save
|
4 |
Requires at least: 3.2
|
5 |
-
Tested up to: 3.
|
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.2 =
|
64 |
* fixes to allow exports without selecting extra user date from usermeta or x-profile
|
65 |
|
2 |
Contributors: qlstudio
|
3 |
Tags: user, users, xprofile, usermeta csv, excel, batch, export, save
|
4 |
Requires at least: 3.2
|
5 |
+
Tested up to: 3.8
|
6 |
+
Stable tag: 0.7.8
|
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.8 =
|
62 |
+
* added xml template for Excel exports - thanks to phil@fixitlab.com :)
|
63 |
+
|
64 |
= 0.7.2 =
|
65 |
* fixes to allow exports without selecting extra user date from usermeta or x-profile
|
66 |
|
xml-template.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* XML template for excel file format
|
5 |
+
*
|
6 |
+
* @since 0.7.7
|
7 |
+
**/
|
8 |
+
|
9 |
+
$xml_doc_begin =
|
10 |
+
'<?xml version="1.0"?>
|
11 |
+
<?mso-application progid="Excel.Sheet"?>
|
12 |
+
<Workbook
|
13 |
+
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
|
14 |
+
xmlns:o="urn:schemas-microsoft-com:office:office"
|
15 |
+
xmlns:x="urn:schemas-microsoft-com:office:excel"
|
16 |
+
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
|
17 |
+
xmlns:html="http://www.w3.org/TR/REC-html40">
|
18 |
+
<Worksheet ss:Name="Exported Users">
|
19 |
+
<Table>';
|
20 |
+
|
21 |
+
$xml_pre = '
|
22 |
+
<Row>
|
23 |
+
<Cell>
|
24 |
+
<Data ss:Type="String">';
|
25 |
+
|
26 |
+
$xml_seperator = '</Data>
|
27 |
+
</Cell>
|
28 |
+
<Cell>
|
29 |
+
<Data ss:Type="String">';
|
30 |
+
|
31 |
+
$xml_breaker = '</Data>
|
32 |
+
</Cell>
|
33 |
+
</Row>';
|
34 |
+
|
35 |
+
$xml_doc_end = '
|
36 |
+
</Table>
|
37 |
+
</Worksheet>
|
38 |
+
</Workbook>';
|