Export User Data - Version 0.8

Version Description

  • moved plugin instatiation to the WP hook: init
  • moved bp calls outside export loop
  • added extra isset calls on values in export loop to clean up error log not sets
Download this release

Release Info

Developer qlstudio
Plugin Icon wp plugin Export User Data
Version 0.8
Comparing to
See all releases

Code changes from version 0.7.8 to 0.8

Files changed (2) hide show
  1. export-user-data.php +209 -152
  2. readme.txt +17 -12
export-user-data.php CHANGED
@@ -4,99 +4,140 @@
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
11
  Text Domain: export-user-data
12
  */
13
 
14
- load_plugin_textdomain( 'export-user-data', false, basename( dirname( __FILE__ ) ) . '/languages' );
15
-
16
- /**
17
- * Main plugin class
18
- *
19
- * @since 0.1
20
- **/
21
- class Q_EUD_Export_Users {
22
-
23
- /**
24
- * Class contructor
25
- *
26
- * @since 0.1
27
- **/
28
- public function __construct() {
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
- add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
31
- add_action( 'init', array( $this, 'generate_data' ) );
32
- add_filter( 'q_eud_exclude_data', array( $this, 'exclude_data' ) );
33
- add_action( 'admin_enqueue_scripts', array( $this, 'add_css_and_js' ), 1 );
34
- add_action( 'admin_footer', array( $this, 'jquery' ), 100000 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- }
37
 
38
-
39
  /**
40
- * Add administration menus
41
- *
42
- * @since 0.1
43
- **/
44
- public function add_admin_pages() {
45
-
 
46
  add_users_page( __( 'Export User Data', 'export-user-data' ), __( 'Export User Data', 'export-user-data' ), 'list_users', 'export-user-data', array( $this, 'users_page' ) );
47
-
48
- }
49
-
50
-
51
  /* style and interaction */
52
- function add_css_and_js($hook) {
53
-
 
54
  // load the scripts on only the plugin admin page
55
  if (isset( $_GET['page'] ) && ( $_GET['page'] == 'export-user-data' ) ) {
56
-
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
  }
64
 
65
-
66
  /* clean that stuff up ## */
67
- public function sanitize($value) {
68
-
 
69
  $value = str_replace("\r", '', $value);
70
  $value = str_replace("\n", '', $value);
71
  $value = str_replace("\t", '', $value);
72
  return $value;
73
-
74
  }
75
-
76
-
77
  /* jquery */
78
- function jquery() {
79
-
 
80
  // load the scripts on only the plugin admin page
81
  if (isset( $_GET['page'] ) && ( $_GET['page'] == 'export-user-data' ) ) {
82
  ?>
83
  <script>
84
-
85
  // build super multiselect ##
86
  jQuery('#usermeta, #bp_fields, #bp_fields_update_time').multiSelect();
87
-
88
  // show only common ##
89
  jQuery('.usermeta-common').click(function(e){
90
  e.preventDefault();
91
  jQuery('#ms-usermeta .ms-selectable li.system').hide();
92
  });
93
-
94
  // show all ##
95
  jQuery('.usermeta-all').click(function(e){
96
  e.preventDefault();
97
  jQuery('#ms-usermeta .ms-selectable li').show();
98
  });
99
-
100
  // toggle update options ##
101
  jQuery(".toggle a").click( function(e) {
102
  e.preventDefault();
@@ -108,32 +149,33 @@ class Q_EUD_Export_Users {
108
  jQuery(this).text("Show Date Options");
109
  }
110
  });
111
-
112
  </script>
113
  <?php
114
  }
115
 
116
  }
117
-
118
- /**
119
- * Process content of CSV file
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 ? ##
@@ -150,7 +192,7 @@ class Q_EUD_Export_Users {
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() );
@@ -208,15 +250,12 @@ class Q_EUD_Export_Users {
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
 
@@ -276,7 +315,7 @@ class Q_EUD_Export_Users {
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
 
@@ -295,15 +334,16 @@ class Q_EUD_Export_Users {
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 ##
@@ -351,15 +391,15 @@ class Q_EUD_Export_Users {
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
 
@@ -376,11 +416,12 @@ class Q_EUD_Export_Users {
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
 
@@ -407,32 +448,34 @@ class Q_EUD_Export_Users {
407
 
408
  // stop PHP, so file can export correctly ##
409
  exit;
410
-
411
-
412
  }
413
 
414
- /**
415
- * Content of the settings page
416
- *
417
- * @since 0.1
418
- **/
419
- public function users_page() {
 
 
420
  if ( ! current_user_can( 'list_users' ) ) {
421
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'export-user-data' ) );
422
  }
423
  ?>
424
 
425
  <div class="wrap">
426
- <h2><?php _e( 'Export User Data', 'export-user-data' ); ?></h2>
427
  <?php
428
-
429
  // nothing happening? ##
430
- if ( isset( $_GET['error'] ) ) {
431
  echo '<div class="updated"><p><strong>' . __( 'No users found.', 'export-user-data' ) . '</strong></p></div>';
432
- }
433
-
434
  ?>
435
- <form method="post" action="" enctype="multipart/form-data">
436
  <?php wp_nonce_field( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' ); ?>
437
  <table class="form-table">
438
  <?php
@@ -443,7 +486,7 @@ class Q_EUD_Export_Users {
443
 
444
  // get meta_key value from object ##
445
  $meta_keys = wp_list_pluck( $meta_keys, 'meta_key' );
446
-
447
  // let's note some of them odd keys ##
448
  $meta_keys_system = array(
449
  'metaboxhidden',
@@ -471,16 +514,16 @@ class Q_EUD_Export_Users {
471
  'wdfb',
472
  'users_per_page',
473
  );
474
-
475
  // allow array to be filtered ##
476
  $meta_keys_system = apply_filters( 'export_user_data_meta_keys_system', $meta_keys_system );
477
-
478
  // test array ##
479
  #echo '<pre>'; var_dump($meta_keys); echo '</pre>';
480
-
481
  // check if we got anything ? ##
482
  if ( $meta_keys ) {
483
-
484
  ?>
485
  <tr valign="top">
486
  <th scope="row">
@@ -509,10 +552,10 @@ class Q_EUD_Export_Users {
509
  $display_key = str_replace( "_", " ", ucwords($display_key) );
510
 
511
  #echo "<label for='".esc_attr( $key )."' title='".esc_attr( $key )."'><input id='".esc_attr( $key )."' type='checkbox' name='usermeta[]' value='".esc_attr( $key )."'/> $display_key</label><br />";
512
-
513
  // class ##
514
  $usermeta_class = 'normal';
515
-
516
  foreach ( $meta_keys_system as $drop ) {
517
 
518
  if ( strpos( $key, $drop ) !== false ) {
@@ -520,25 +563,25 @@ class Q_EUD_Export_Users {
520
  #echo 'FOUND -- '.$drop.' in '.$key.'<br />';
521
 
522
  if(($key = array_search($key, $meta_keys)) !== false) {
523
-
524
  $usermeta_class = 'system';
525
-
526
  }
527
-
528
  }
529
-
530
  }
531
-
532
  // print key ##
533
  echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."' class='".$usermeta_class."'>$display_key</option>";
534
-
535
  }
536
  ?>
537
  </select>
538
  </td>
539
  </tr>
540
  <?php
541
-
542
  } // meta_keys found ##
543
 
544
  ?>
@@ -546,45 +589,45 @@ class Q_EUD_Export_Users {
546
 
547
  // buddypress x profile data ##
548
  if ( function_exists ('bp_is_active') ) {
549
-
550
  // grab all buddypress x profile fields ##
551
  $bp_fields = $wpdb->get_results( "SELECT distinct(name) FROM ".$wpdb->base_prefix."bp_xprofile_fields WHERE parent_id = 0" );
552
 
553
  // get name value from object ##
554
  $bp_fields = wp_list_pluck( $bp_fields, 'name' );
555
-
556
  // test array ##
557
  #echo '<pre>'; var_dump($bp_fields); echo '</pre>';
558
-
559
  // allow array to be filtered ##
560
  $bp_fields = apply_filters( 'export_user_data_bp_fields', $bp_fields );
561
-
562
  ?>
563
  <tr valign="top">
564
  <th scope="row"><label for="q_eud_xprofile"><?php _e( 'BP xProfile Fields', 'export-user-data' ); ?></label></th>
565
  <td>
566
  <select multiple="multiple" id="bp_fields" name="bp_fields[]">
567
  <?php
568
-
569
  foreach ( $bp_fields as $key ) {
570
 
571
  // tidy up key ##
572
  $key_tidy = str_replace( ' ', '__', ($key));
573
-
574
  #echo "<label for='".esc_attr( $key_tidy )."'><input id='".esc_attr( $key_tidy )."' type='checkbox' name='bp_fields[]' value='".esc_attr( $key_tidy )."'/> $key</label><br />";
575
-
576
  // print key ##
577
  echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."'>$key</option>";
578
 
579
  }
580
-
581
  ?>
582
  </select>
583
  </td>
584
  </tr>
585
  <?php
586
 
587
- // allow export of update times ##
588
 
589
  ?>
590
  <tr valign="top">
@@ -611,7 +654,7 @@ class Q_EUD_Export_Users {
611
  </td>
612
  </tr>
613
  <?php
614
-
615
  } // BP installed and active ##
616
 
617
  ?>
@@ -632,10 +675,10 @@ class Q_EUD_Export_Users {
632
  </td>
633
  </tr>
634
  <?php
635
-
636
  // clubs ? ##
637
  if ( post_type_exists( 'club' ) ) {
638
-
639
  ?>
640
  <tr valign="top">
641
  <th scope="row"><label for="q_eud_users_program"><?php _e( 'Programs', 'export-user-data' ); ?></label></th>
@@ -659,9 +702,9 @@ class Q_EUD_Export_Users {
659
  </td>
660
  </tr>
661
  <?php
662
-
663
  } // clubs ##
664
-
665
  ?>
666
  <tr valign="top">
667
  <th scope="row"><label><?php _e( 'Registered', 'export-user-data' ); ?></label></th>
@@ -676,7 +719,7 @@ class Q_EUD_Export_Users {
676
  </select>
677
  </td>
678
  </tr>
679
-
680
  <tr valign="top">
681
  <th scope="row"><label for="q_eud_users_format"><?php _e( 'Format', 'export-user-data' ); ?></label></th>
682
  <td>
@@ -695,21 +738,28 @@ class Q_EUD_Export_Users {
695
  <input type="hidden" name="_wp_http_referer" value="<?php echo $_SERVER['REQUEST_URI'] ?>" />
696
  <input type="submit" class="button-primary" value="<?php _e( 'Export', 'export-user-data' ); ?>" />
697
  </p>
698
- </form>
699
  <?php
700
- }
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 = '';
@@ -724,12 +774,20 @@ class Q_EUD_Export_Users {
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( "
@@ -749,10 +807,9 @@ class Q_EUD_Export_Users {
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 */
758
- new Q_EUD_Export_Users;
 
 
 
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.8
8
  Author: Q Studio
9
+ Author URI: http://qstudio.us
10
  License: GPL2
11
  Text Domain: export-user-data
12
  */
13
 
14
+ // quick check :) ##
15
+ defined( 'ABSPATH' ) OR exit;
16
+
17
+ /* Check for Class */
18
+ if ( ! class_exists( 'Q_EUD_Export_Users' ) )
19
+ {
20
+
21
+ // instatiate class via hook, only if inside admin
22
+ if ( is_admin() ) {
23
+
24
+ // instatiate plugin via WP hook - not too early, not too late ##
25
+ add_action( 'init', array ( 'Q_EUD_Export_Users', 'init' ), 0 );
26
+
27
+ }
28
+
29
+ /*
30
+ * Load plugin text-domain
31
+ */
32
+ load_plugin_textdomain( 'export-user-data', false, basename( dirname( __FILE__ ) ) . '/languages' );
33
+
34
+
35
+ /**
36
+ * Main plugin class
37
+ *
38
+ * @since 0.1
39
+ **/
40
+ class Q_EUD_Export_Users {
41
 
42
+ /**
43
+ * Creates a new instance.
44
+ *
45
+ * @wp-hook init
46
+ * @see __construct()
47
+ * @since 0.1
48
+ * @return void
49
+ */
50
+ public static function init()
51
+ {
52
+ new self;
53
+ }
54
+
55
+ /**
56
+ * Class contructor
57
+ *
58
+ * @since 0.1
59
+ **/
60
+ public function __construct()
61
+ {
62
+
63
+ if (is_admin() ) {
64
+
65
+ add_action( 'admin_menu', array( $this, 'add_admin_pages' ) );
66
+ add_action( 'init', array( $this, 'generate_data' ) );
67
+ add_filter( 'q_eud_exclude_data', array( $this, 'exclude_data' ) );
68
+ add_action( 'admin_enqueue_scripts', array( $this, 'add_css_and_js' ), 1 );
69
+ add_action( 'admin_footer', array( $this, 'jquery' ), 100000 );
70
+
71
+ }
72
+
73
+ }
74
 
 
75
 
 
76
  /**
77
+ * Add administration menus
78
+ *
79
+ * @since 0.1
80
+ **/
81
+ public function add_admin_pages()
82
+ {
83
+
84
  add_users_page( __( 'Export User Data', 'export-user-data' ), __( 'Export User Data', 'export-user-data' ), 'list_users', 'export-user-data', array( $this, 'users_page' ) );
85
+
86
+ }
87
+
88
+
89
  /* style and interaction */
90
+ function add_css_and_js( $hook )
91
+ {
92
+
93
  // load the scripts on only the plugin admin page
94
  if (isset( $_GET['page'] ) && ( $_GET['page'] == 'export-user-data' ) ) {
95
+
96
  wp_register_style('q_eud_multi_select_css', plugins_url('css/multi-select.css',__FILE__ ));
97
  wp_enqueue_style('q_eud_multi_select_css');
98
  wp_enqueue_script('q_eud_multi_select_js', plugins_url('js/jquery.multi-select.js',__FILE__ ), array('jquery'), '0.9.8', false );
99
+
100
  }
101
+
102
  }
103
 
104
+
105
  /* clean that stuff up ## */
106
+ public function sanitize( $value )
107
+ {
108
+
109
  $value = str_replace("\r", '', $value);
110
  $value = str_replace("\n", '', $value);
111
  $value = str_replace("\t", '', $value);
112
  return $value;
113
+
114
  }
115
+
116
+
117
  /* jquery */
118
+ function jquery()
119
+ {
120
+
121
  // load the scripts on only the plugin admin page
122
  if (isset( $_GET['page'] ) && ( $_GET['page'] == 'export-user-data' ) ) {
123
  ?>
124
  <script>
125
+
126
  // build super multiselect ##
127
  jQuery('#usermeta, #bp_fields, #bp_fields_update_time').multiSelect();
128
+
129
  // show only common ##
130
  jQuery('.usermeta-common').click(function(e){
131
  e.preventDefault();
132
  jQuery('#ms-usermeta .ms-selectable li.system').hide();
133
  });
134
+
135
  // show all ##
136
  jQuery('.usermeta-all').click(function(e){
137
  e.preventDefault();
138
  jQuery('#ms-usermeta .ms-selectable li').show();
139
  });
140
+
141
  // toggle update options ##
142
  jQuery(".toggle a").click( function(e) {
143
  e.preventDefault();
149
  jQuery(this).text("Show Date Options");
150
  }
151
  });
152
+
153
  </script>
154
  <?php
155
  }
156
 
157
  }
158
+
159
+ /**
160
+ * Process content of CSV file
161
+ *
162
+ * @since 0.1
163
+ **/
164
+ public function generate_data()
165
+ {
166
+
167
  if ( ! isset( $_POST['_wpnonce-q-eud-export-user-page_export'] ) ) {
168
+
169
  return false;
170
+
171
  }
172
+
173
  check_admin_referer( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' );
174
 
175
  // build argument array ##
176
  $args = array(
177
+ 'fields' => 'all_with_meta',
178
+ 'role' => stripslashes( $_POST['role'] )
179
  );
180
 
181
  // did the user request a specific program ? ##
192
  $users = get_users( $args );
193
  remove_action( 'pre_user_query', array( $this, 'pre_user_query' ) );
194
 
195
+ /* no users found, so chuck an error into the args array and exit the export */
196
  if ( ! $users ) {
197
 
198
  $referer = add_query_arg( 'error', 'empty', wp_get_referer() );
250
  case ('excel'):
251
 
252
  // to xls ##
 
253
  header( 'Content-Description: File Transfer' );
254
  header("Content-Type: application/vnd.ms-excel");
255
  header("Content-Disposition: attachment; filename=$filename.xls");
256
  header("Pragma: no-cache");
257
  header("Expires: 0");
258
+
 
 
259
  // set a csv check flag
260
  $is_csv = false;
261
 
315
  // cwjordan: check for x profile fields we want update time for ##
316
  $bp_fields_update = isset( $_POST['bp_fields_update_time'] ) ? $_POST['bp_fields_update_time'] : '';
317
  $bp_fields_update_passed = array();
318
+ if ( $bp_fields_update && is_array( $bp_fields_update ) ) {
319
 
320
  foreach( $bp_fields_update as $field ) {
321
 
334
 
335
  // exportable user data ##
336
  $data_keys = array(
337
+ 'ID'
338
+ , 'user_login'
339
+ #, 'user_pass'
340
+ , 'user_nicename'
341
+ , 'user_email'
342
+ , 'user_url'
343
+ , 'user_registered'
344
+ #, 'user_activation_key'
345
+ #, 'user_status',
346
+ , 'display_name'
347
  );
348
 
349
  // compile final fields list ##
391
 
392
  $data = array();
393
 
394
+ // BP loaded ? ##
395
+ if ( function_exists ('bp_is_active') ) {
396
+ $bp_data = BP_XProfile_ProfileData::get_all_for_user($user->ID);
397
+ }
398
 
399
+ foreach ( $fields as $field ) {
 
 
 
400
 
401
  // check if this is a BP field ##
402
+ if ( isset($bp_data) && isset($bp_data[$field]) && in_array( $field, $bp_fields_passed ) ) {
403
 
404
  $value = $bp_data[$field];
405
 
416
  $real_field = str_replace(" Update Date", "", $field);
417
  $field_id = xprofile_get_field_id_from_name( $real_field );
418
  $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 ) );
419
+
420
  // user data or usermeta ##
421
  } else {
422
 
423
  $value = isset( $user->{$field} ) ? $user->{$field} : '';
424
+ $value = is_array( $value ) ? serialize( $value ) : $value; // maybe serialize the value ##
425
 
426
  }
427
 
448
 
449
  // stop PHP, so file can export correctly ##
450
  exit;
451
+
452
+
453
  }
454
 
455
+ /**
456
+ * Content of the settings page
457
+ *
458
+ * @since 0.1
459
+ **/
460
+ public function users_page()
461
+ {
462
+
463
  if ( ! current_user_can( 'list_users' ) ) {
464
  wp_die( __( 'You do not have sufficient permissions to access this page.', 'export-user-data' ) );
465
  }
466
  ?>
467
 
468
  <div class="wrap">
469
+ <h2><?php _e( 'Export User Data', 'export-user-data' ); ?></h2>
470
  <?php
471
+
472
  // nothing happening? ##
473
+ if ( isset( $_GET['error'] ) ) {
474
  echo '<div class="updated"><p><strong>' . __( 'No users found.', 'export-user-data' ) . '</strong></p></div>';
475
+ }
476
+
477
  ?>
478
+ <form method="post" action="" enctype="multipart/form-data">
479
  <?php wp_nonce_field( 'q-eud-export-user-page_export', '_wpnonce-q-eud-export-user-page_export' ); ?>
480
  <table class="form-table">
481
  <?php
486
 
487
  // get meta_key value from object ##
488
  $meta_keys = wp_list_pluck( $meta_keys, 'meta_key' );
489
+
490
  // let's note some of them odd keys ##
491
  $meta_keys_system = array(
492
  'metaboxhidden',
514
  'wdfb',
515
  'users_per_page',
516
  );
517
+
518
  // allow array to be filtered ##
519
  $meta_keys_system = apply_filters( 'export_user_data_meta_keys_system', $meta_keys_system );
520
+
521
  // test array ##
522
  #echo '<pre>'; var_dump($meta_keys); echo '</pre>';
523
+
524
  // check if we got anything ? ##
525
  if ( $meta_keys ) {
526
+
527
  ?>
528
  <tr valign="top">
529
  <th scope="row">
552
  $display_key = str_replace( "_", " ", ucwords($display_key) );
553
 
554
  #echo "<label for='".esc_attr( $key )."' title='".esc_attr( $key )."'><input id='".esc_attr( $key )."' type='checkbox' name='usermeta[]' value='".esc_attr( $key )."'/> $display_key</label><br />";
555
+
556
  // class ##
557
  $usermeta_class = 'normal';
558
+
559
  foreach ( $meta_keys_system as $drop ) {
560
 
561
  if ( strpos( $key, $drop ) !== false ) {
563
  #echo 'FOUND -- '.$drop.' in '.$key.'<br />';
564
 
565
  if(($key = array_search($key, $meta_keys)) !== false) {
566
+
567
  $usermeta_class = 'system';
568
+
569
  }
570
+
571
  }
572
+
573
  }
574
+
575
  // print key ##
576
  echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."' class='".$usermeta_class."'>$display_key</option>";
577
+
578
  }
579
  ?>
580
  </select>
581
  </td>
582
  </tr>
583
  <?php
584
+
585
  } // meta_keys found ##
586
 
587
  ?>
589
 
590
  // buddypress x profile data ##
591
  if ( function_exists ('bp_is_active') ) {
592
+
593
  // grab all buddypress x profile fields ##
594
  $bp_fields = $wpdb->get_results( "SELECT distinct(name) FROM ".$wpdb->base_prefix."bp_xprofile_fields WHERE parent_id = 0" );
595
 
596
  // get name value from object ##
597
  $bp_fields = wp_list_pluck( $bp_fields, 'name' );
598
+
599
  // test array ##
600
  #echo '<pre>'; var_dump($bp_fields); echo '</pre>';
601
+
602
  // allow array to be filtered ##
603
  $bp_fields = apply_filters( 'export_user_data_bp_fields', $bp_fields );
604
+
605
  ?>
606
  <tr valign="top">
607
  <th scope="row"><label for="q_eud_xprofile"><?php _e( 'BP xProfile Fields', 'export-user-data' ); ?></label></th>
608
  <td>
609
  <select multiple="multiple" id="bp_fields" name="bp_fields[]">
610
  <?php
611
+
612
  foreach ( $bp_fields as $key ) {
613
 
614
  // tidy up key ##
615
  $key_tidy = str_replace( ' ', '__', ($key));
616
+
617
  #echo "<label for='".esc_attr( $key_tidy )."'><input id='".esc_attr( $key_tidy )."' type='checkbox' name='bp_fields[]' value='".esc_attr( $key_tidy )."'/> $key</label><br />";
618
+
619
  // print key ##
620
  echo "<option value='".esc_attr( $key )."' title='".esc_attr( $key )."'>$key</option>";
621
 
622
  }
623
+
624
  ?>
625
  </select>
626
  </td>
627
  </tr>
628
  <?php
629
 
630
+ // allow export of update times ##
631
 
632
  ?>
633
  <tr valign="top">
654
  </td>
655
  </tr>
656
  <?php
657
+
658
  } // BP installed and active ##
659
 
660
  ?>
675
  </td>
676
  </tr>
677
  <?php
678
+
679
  // clubs ? ##
680
  if ( post_type_exists( 'club' ) ) {
681
+
682
  ?>
683
  <tr valign="top">
684
  <th scope="row"><label for="q_eud_users_program"><?php _e( 'Programs', 'export-user-data' ); ?></label></th>
702
  </td>
703
  </tr>
704
  <?php
705
+
706
  } // clubs ##
707
+
708
  ?>
709
  <tr valign="top">
710
  <th scope="row"><label><?php _e( 'Registered', 'export-user-data' ); ?></label></th>
719
  </select>
720
  </td>
721
  </tr>
722
+
723
  <tr valign="top">
724
  <th scope="row"><label for="q_eud_users_format"><?php _e( 'Format', 'export-user-data' ); ?></label></th>
725
  <td>
738
  <input type="hidden" name="_wp_http_referer" value="<?php echo $_SERVER['REQUEST_URI'] ?>" />
739
  <input type="submit" class="button-primary" value="<?php _e( 'Export', 'export-user-data' ); ?>" />
740
  </p>
741
+ </form>
742
  <?php
743
+ }
744
+
745
+ /**
746
+ * Data to exclude from export
747
+ */
748
+ public function exclude_data()
749
+ {
750
+
751
  $exclude = array( 'user_pass', 'user_activation_key' );
752
  return $exclude;
 
 
753
 
754
+ }
755
+
756
+
757
+ /*
758
+ * Pre User Query
759
+ */
760
+ public function pre_user_query( $user_search )
761
+ {
762
+
763
  global $wpdb;
764
 
765
  $where = '';
774
  $user_search->query_where = str_replace( 'WHERE 1=1', "WHERE 1=1 $where", $user_search->query_where );
775
 
776
  return $user_search;
 
 
777
 
778
+ }
779
+
780
+
781
+ /**
782
+ * Export Date Options
783
+ *
784
+ * @global type $wpdb
785
+ * @global type $wp_locale
786
+ * @return type
787
+ */
788
+ private function export_date_options()
789
+ {
790
+
791
  global $wpdb, $wp_locale;
792
 
793
  $months = $wpdb->get_results( "
807
  $month = zeroise( $date->month, 2 );
808
  echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
809
  }
 
 
 
 
810
 
811
+ }
812
+
813
+ }
814
+
815
+ }
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Plugin Name ===
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
@@ -22,29 +22,29 @@ Includes an option to export the users by role, registration date range, usermet
22
  * Exports users by date range
23
  * Export user BuddyPress xProfile data
24
 
25
- For feature request and bug reports, [please use the forums](http://wordpress.org/tags/export-users-data).
 
 
26
 
27
  == Installation ==
28
 
29
  For an automatic installation through WordPress:
30
 
31
  1. Go to the 'Add New' plugins screen in your WordPress admin area
32
- 1. Search for 'Export User Data'
33
- 1. Click 'Install Now' and activate the plugin
34
- 1. Go the 'Users' menu, under 'Export User Data'
35
-
36
 
37
  For a manual installation via FTP:
38
 
39
  1. Upload the `export-user-data` directory to the `/wp-content/plugins/` directory
40
- 1. Activate the plugin through the 'Plugins' screen in your WordPress admin area
41
- 1. Go the 'Users' menu, under 'Export User Data'
42
-
43
 
44
  To upload the plugin through WordPress, instead of FTP:
45
 
46
  1. Upload the downloaded zip file on the 'Add New' plugins screen (see the 'Upload' tab) in your WordPress admin area and activate.
47
- 1. Go the 'Users' menu, under 'Export User Data'
48
 
49
  == Frequently Asked Questions ==
50
 
@@ -58,6 +58,11 @@ Click on the 'Export User Data' link in the 'Users' menu, choose the role and th
58
 
59
  == Changelog ==
60
 
 
 
 
 
 
61
  = 0.7.8 =
62
  * added xml template for Excel exports - thanks to phil@fixitlab.com :)
63
 
1
  === Plugin Name ===
2
  Contributors: qlstudio
3
+ Tags: user, users, xprofile, usermeta csv, excel, batch, export, save, download
4
  Requires at least: 3.2
5
+ Tested up to: 3.8.1
6
+ Stable tag: 0.8
7
  License: GPLv2
8
 
9
  Export users data, metadata and buddypress xprofile data to a csv or Excel file
22
  * Exports users by date range
23
  * Export user BuddyPress xProfile data
24
 
25
+ For feature request and bug reports, [please use the WP Support Website](http://www.wp-support.co/view/categories/export-user-data).
26
+
27
+ Please do not use the Wordpress.org forum to report bugs, as we no longer monitor or respond to questions there.
28
 
29
  == Installation ==
30
 
31
  For an automatic installation through WordPress:
32
 
33
  1. Go to the 'Add New' plugins screen in your WordPress admin area
34
+ 2. Search for 'Export User Data'
35
+ 3. Click 'Install Now' and activate the plugin
36
+ 4. Go the 'Users' menu, under 'Export User Data'
 
37
 
38
  For a manual installation via FTP:
39
 
40
  1. Upload the `export-user-data` directory to the `/wp-content/plugins/` directory
41
+ 2. Activate the plugin through the 'Plugins' screen in your WordPress admin area
42
+ 3. Go the 'Users' menu, under 'Export User Data'
 
43
 
44
  To upload the plugin through WordPress, instead of FTP:
45
 
46
  1. Upload the downloaded zip file on the 'Add New' plugins screen (see the 'Upload' tab) in your WordPress admin area and activate.
47
+ 2. Go the 'Users' menu, under 'Export User Data'
48
 
49
  == Frequently Asked Questions ==
50
 
58
 
59
  == Changelog ==
60
 
61
+ = 0.8 =
62
+ * moved plugin instatiation to the WP hook: init
63
+ * moved bp calls outside export loop
64
+ * added extra isset calls on values in export loop to clean up error log not sets
65
+
66
  = 0.7.8 =
67
  * added xml template for Excel exports - thanks to phil@fixitlab.com :)
68