Export User Data - Version 2.2.1

Version Description

Download this release

Release Info

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

Code changes from version 2.1.3 to 2.2.1

CHANGELOG.md CHANGED
@@ -1,8 +1,18 @@
1
  ## Changelog ##
2
 
 
 
 
 
 
 
 
 
 
 
3
  *** 2.1.3 ***
4
 
5
- * FIX - wrong name for our own plugin :( thanks @kgagne !
6
 
7
  *** 2.1.2 ***
8
 
1
  ## Changelog ##
2
 
3
+ *** 2.2.1 ***
4
+
5
+ * New: cleanup export methods, improvied sanitization
6
+ * New: array and object data is now passed in JSON_ENCODED string object
7
+
8
+ *** 2.2.0 ***
9
+
10
+ * New: Move to cleaner OOP pattern and PHP version bump to 7.0
11
+ * Update: Tested on WP 5.6
12
+
13
  *** 2.1.3 ***
14
 
15
+ * FIX: wrong name for our own plugin :( thanks @kgagne !
16
 
17
  *** 2.1.2 ***
18
 
autoload.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Autoload classes within the namespace `willow`
5
+ */
6
+ spl_autoload_register( function( $class ) {
7
+
8
+ // error_log( 'Autoload Class: '.$class );
9
+
10
+ // project-specific namespace prefix
11
+ $prefix = 'q\\eud\\';
12
+
13
+ /**
14
+ * Does the class being called use the namespace prefix?
15
+ *
16
+ * - Compare the first {$len} characters of the class name against our prefix
17
+ * - If no match, move to the next registered autoloader
18
+ */
19
+
20
+ // character length of our prefix
21
+ $len = strlen( $prefix );
22
+
23
+ // if the first {$len} characters don't match
24
+ if ( strncmp( $prefix, $class, $len ) !== 0 ) {
25
+
26
+ // error_log( 'Autoload Class Rejected, as outside namespace: '.$class );
27
+
28
+ return;
29
+
30
+ }
31
+
32
+ // base directory where our class files and folders live
33
+ $base_dir = __DIR__ . '/library/';
34
+
35
+ /**
36
+ * Perform normalizing operations on the requested class string
37
+ *
38
+ * - Remove the prefix from the class name (so that willow\Plugin looks at src/plugin.php)
39
+ * - Replace namespace separators with directory separators in the class name
40
+ * - Prepend the base directory
41
+ * - Append with .php
42
+ * - Convert to lower case
43
+ */
44
+ $class_name = str_replace( $prefix, '', $class );
45
+
46
+ // error_log( 'Class Name: '.$class_name );
47
+
48
+ $possible_file = strtolower( $base_dir . str_replace('\\', '/', $class_name ) . '.php' );
49
+
50
+ // require the file if it exists
51
+ if( file_exists( $possible_file ) ) {
52
+
53
+ // error_log( 'Willow auto-loading: '.$possible_file );
54
+
55
+ require $possible_file;
56
+
57
+ }
58
+
59
+ });
export-user-data.php CHANGED
@@ -1,200 +1,113 @@
1
  <?php
2
 
3
- /*
 
 
 
 
 
 
 
 
4
  * Plugin Name: Export User Data
 
5
  * Description: Export User data and metadata.
6
- * Version: 2.1.3
7
  * Author: Q Studio
8
- * Author URI: http://qstudio.us/
9
- * License: GPL2
10
- * Class: q_export_user_data
11
- * Text Domain: q-export-user-data
 
 
 
 
12
  * GitHub Plugin URI: qstudio/export-user-data
13
  */
14
 
15
- defined( 'ABSPATH' ) OR exit;
16
-
17
- if ( ! class_exists( 'q_export_user_data' ) ) {
18
-
19
- // instatiate plugin via WP plugins_loaded - init is too late for CPT ##
20
- add_action( 'init', array ( 'q_export_user_data', 'get_instance' ), 1000000 );
21
-
22
- class q_export_user_data {
23
-
24
- // Refers to a single instance of this class. ##
25
- private static $instance = null;
26
-
27
- // Plugin Settings
28
- const version = '2.1.3';
29
- static $debug = false;
30
- const text_domain = 'q-export-user-data'; // for translation ##
31
-
32
- /* properties */
33
- public static $q_eud_exports = ''; // export settings ##
34
- public static $usermeta_saved_fields = array();
35
- public static $bp_fields_saved_fields = array();
36
- public static $bp_fields_update_time_saved_fields = array();
37
- public static $role = '';
38
- public static $roles = '0';
39
- public static $user_fields = '1';
40
- public static $groups = '0';
41
- public static $start_date = '';
42
- public static $end_date = '';
43
- public static $limit_offset = '';
44
- public static $limit_total = '';
45
- public static $updated_since_date = '';
46
- public static $field_updated_since = '';
47
- public static $format = '';
48
- public static $bp_data_available = false;
49
- public static $allowed_tags = '';
50
-
51
- // api ##
52
- public static $api_admin_fields = false;
53
-
54
- /**
55
- * Creates or returns an instance of this class.
56
- *
57
- * @return Foo A single instance of this class.
58
- */
59
- public static function get_instance()
60
- {
61
-
62
- if ( null == self::$instance ) {
63
- self::$instance = new self;
64
- }
65
-
66
- return self::$instance;
67
-
68
- }
69
-
70
-
71
- /**
72
- * Instatiate Class
73
- *
74
- * @since 0.2
75
- * @return void
76
- */
77
- private function __construct()
78
- {
79
-
80
- // activation ##
81
- register_activation_hook( __FILE__, array ( $this, 'register_activation_hook' ) );
82
-
83
- // deactvation ##
84
- register_deactivation_hook( __FILE__, array ( $this, 'register_deactivation_hook' ) );
85
-
86
- // set text domain ##
87
- add_action( 'init', array( $this, 'load_plugin_textdomain' ), 1 );
88
-
89
- // load libraries ##
90
- self::load_libraries();
91
-
92
- }
93
-
94
-
95
- // the form for sites have to be 1-column-layout
96
- public function register_activation_hook() {
97
-
98
- \add_option( 'q_eud_configured' );
99
-
100
- // flush rewrites ##
101
- #global $wp_rewrite;
102
- #$wp_rewrite->flush_rules();
103
-
104
- }
105
-
106
-
107
- public function register_deactivation_hook() {
108
-
109
- \delete_option( 'q_eud_configured' );
110
-
111
- }
112
-
113
-
114
-
115
- /**
116
- * Load Text Domain for translations
117
- *
118
- * @since 1.7.0
119
- *
120
- */
121
- public function load_plugin_textdomain()
122
- {
123
-
124
- // set text-domain ##
125
- $domain = self::text_domain;
126
-
127
- // The "plugin_locale" filter is also used in load_plugin_textdomain()
128
- $locale = apply_filters('plugin_locale', get_locale(), $domain);
129
-
130
- // try from global WP location first ##
131
- load_textdomain( $domain, WP_LANG_DIR.'/plugins/'.$domain.'-'.$locale.'.mo' );
132
-
133
- // try from plugin last ##
134
- load_plugin_textdomain( $domain, FALSE, plugin_dir_path( __FILE__ ).'library/languages/' );
135
-
136
- }
137
-
138
-
139
-
140
- /**
141
- * Get Plugin URL
142
- *
143
- * @since 0.1
144
- * @param string $path Path to plugin directory
145
- * @return string Absoulte URL to plugin directory
146
- */
147
- public static function get_plugin_url( $path = '' )
148
- {
149
-
150
- return plugins_url( $path, __FILE__ );
151
-
152
- }
153
-
154
-
155
- /**
156
- * Get Plugin Path
157
- *
158
- * @since 0.1
159
- * @param string $path Path to plugin directory
160
- * @return string Absoulte URL to plugin directory
161
- */
162
- public static function get_plugin_path( $path = '' )
163
- {
164
-
165
- return plugin_dir_path( __FILE__ ).$path;
166
-
167
- }
168
-
169
-
170
- /**
171
- * Load Libraries
172
- *
173
- * @since 2.0
174
- */
175
- private static function load_libraries()
176
- {
177
-
178
- // vendor ##
179
- require_once self::get_plugin_path( 'vendor/PHP_XLSXWriter/xlsxwriter.class.php' );
180
-
181
- // methods ##
182
- require_once self::get_plugin_path( 'library/core/helper.php' );
183
- require_once self::get_plugin_path( 'library/core/core.php' );
184
- require_once self::get_plugin_path( 'library/core/user.php' );
185
- require_once self::get_plugin_path( 'library/core/buddypress.php' );
186
- // require_once self::get_plugin_path( 'library/core/excel2003.php' );
187
- require_once self::get_plugin_path( 'library/core/export.php' );
188
- require_once self::get_plugin_path( 'library/core/filters.php' );
189
-
190
- // api ##
191
- require_once self::get_plugin_path( 'library/api/admin.php' );
192
-
193
- // backend ##
194
- require_once self::get_plugin_path( 'library/admin/admin.php' );
195
-
196
- }
197
-
198
- }
199
 
200
  }
1
  <?php
2
 
3
+ /**
4
+ * Export User Data
5
+ *
6
+ * @package Export User Data
7
+ * @author Q Studio <social@qstudio.us>
8
+ * @license GPL-2.0+
9
+ * @copyright 2020 Q Studio
10
+ *
11
+ * @wordpress-plugin
12
  * Plugin Name: Export User Data
13
+ * Plugin URI: http://qstudio.us/releases/export-user-data
14
  * Description: Export User data and metadata.
15
+ * Version: 2.2.1
16
  * Author: Q Studio
17
+ * Author URI: https://qstudio.us
18
+ * License: GPL-2.0+
19
+ * Requires PHP: 7.0
20
+ * Copyright: Q Studio
21
+ * Namespace: q\eud
22
+ * API: export_user_data
23
+ * Text Domain: export-user-data
24
+ * Domain Path: /languages
25
  * GitHub Plugin URI: qstudio/export-user-data
26
  */
27
 
28
+ // namespace plugin ##
29
+ namespace q\eud;
30
+
31
+ // import ##
32
+ use q\eud;
33
+ use q\eud\core\helper as h;
34
+
35
+ // If this file is called directly, Bulk!
36
+ if ( ! defined( 'ABSPATH' ) ) {
37
+ return;
38
+ }
39
+
40
+ // plugin activation hook to store current application and plugin state ##
41
+ \register_activation_hook( __FILE__, [ '\\q\\eud\\plugin', 'activation_hook' ] );
42
+
43
+ // plugin deactivation hook - clear stored data ##
44
+ \register_deactivation_hook( __FILE__, [ '\\q\\eud\\plugin', 'deactivation_hook' ] );
45
+
46
+ // required bits to get set-up ##
47
+ require_once __DIR__ . '/library/api/function.php';
48
+ require_once __DIR__ . '/autoload.php';
49
+ require_once __DIR__ . '/plugin.php';
50
+ require_once __DIR__ . '/vendor/PHP_XLSXWriter/xlsxwriter.class.php';
51
+
52
+ // get plugin instance ##
53
+ $plugin = plugin::get_instance();
54
+
55
+ // validate instance ##
56
+ if( ! ( $plugin instanceof \q\eud\plugin ) ) {
57
+
58
+ error_log( 'Error in Export User Data plugin instance' );
59
+
60
+ // nothing else to do here ##
61
+ return;
62
+
63
+ }
64
+
65
+ // fire hooks - build log, helper and config objects and translations ##
66
+ \add_action( 'init', function() use( $plugin ){
67
+
68
+ // set text domain on init hook ##
69
+ \add_action( 'init', [ $plugin, 'load_plugin_textdomain' ], 1 );
70
+
71
+ // check debug settings ##
72
+ \add_action( 'plugins_loaded', [ $plugin, 'debug' ], 11 );
73
+
74
+ }, 0 );
75
+
76
+ // build export object ##
77
+ $export = new eud\core\export( $plugin );
78
+
79
+ // build filters object ##
80
+ $filters = new eud\core\filters( $plugin );
81
+
82
+ // build user object ##
83
+ $user = new eud\core\user( $plugin );
84
+
85
+ // build admin object ##
86
+ $admin = new eud\admin\render( $plugin, $user );
87
+
88
+ // build buddypress object ##
89
+ // $buddypress = new eud\core\buddypress();
90
+
91
+ if ( \is_admin() ){
92
+
93
+ // run export ##
94
+ \add_action( 'admin_init', [ $export, 'render' ], 1000003 );
95
+
96
+ // load BP ##
97
+ // \add_action( 'admin_init', [ $buddypress, 'load' ], 1000001 );
98
+
99
+ // EUD - filter key shown ##
100
+ \add_filter( 'q/eud/admin/display_key', [ $filters, 'display_key' ], 1, 1 );
101
+
102
+ // user option ##
103
+ \add_action( 'admin_init', [ $user, 'load' ], 1000002 );
104
+
105
+ // add export menu inside admin ##
106
+ \add_action( 'admin_menu', [ $admin, 'add_menu' ] );
107
+
108
+ // UI style and functionality ##
109
+ \add_action( 'admin_enqueue_scripts', [ $admin, 'admin_enqueue_scripts' ], 1 );
110
+ \add_action( 'admin_footer', [ $admin, 'jquery' ], 100000 );
111
+ \add_action( 'admin_footer', [ $admin, 'css' ], 100000 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  }
library/admin/{admin.php → render.php} RENAMED
@@ -2,75 +2,57 @@
2
 
3
  namespace q\eud\admin;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
  use q\eud\core\user as user;
8
- use q\eud\core\buddypress as buddypress;
9
  use q\eud\api\admin as api_admin;
10
 
11
- // load it up ##
12
- \q\eud\admin\admin::run();
13
 
14
- class admin extends \q_export_user_data {
15
 
16
- public static function run()
17
- {
18
 
19
- #global $pagenow;
20
-
21
- if ( \is_admin() ) {
22
-
23
- // add export menu inside admin ##
24
- \add_action( 'admin_menu', array( get_class(), 'add_menu' ) );
25
-
26
- // UI style and functionality ##
27
- \add_action( 'admin_enqueue_scripts', array( get_class(), 'admin_enqueue_scripts' ), 1 );
28
- \add_action( 'admin_footer', array( get_class(), 'jquery' ), 100000 );
29
- \add_action( 'admin_footer', array( get_class(), 'css' ), 100000 );
30
-
31
- }
32
-
33
- }
34
 
 
35
 
 
36
 
37
  /**
38
  * Add administration menus
39
  *
40
  * @since 0.1
41
  **/
42
- public static function add_menu()
43
- {
44
 
45
- add_users_page (
46
  __( 'Export User Data', 'q-export-user-data' ),
47
  __( 'Export User Data', 'q-export-user-data' ),
48
  \apply_filters( 'q/eud/admin_capability', 'list_users' ),
49
  'q-export-user-data',
50
- array(
51
- get_class(),
52
- 'admin_page'
53
- )
54
  );
55
 
56
  }
57
 
58
-
59
  /**
60
  * Content of the admin page
61
  *
62
  * @since 0.1
63
  */
64
- public static function admin_page()
65
- {
66
 
67
  // quick security check ##
68
  if ( ! \current_user_can( \apply_filters( 'q/eud/admin_capability', 'list_users' ) ) ) {
69
 
70
  \wp_die( __( 'You do not have sufficient permissions to access this page.', 'q-export-user-data' ) );
71
 
72
- }
73
-
74
  // Save settings button was pressed ##
75
  if (
76
  isset( $_POST['save_export'] )
@@ -97,20 +79,22 @@ class admin extends \q_export_user_data {
97
  // Build array of $options to save and save them ##
98
  if ( isset( $save_export ) ) {
99
 
 
 
100
  // prepare all array values ##
101
  $usermeta =
102
  isset( $_POST['usermeta'] ) ?
103
  array_map( 'sanitize_text_field',
104
  $_POST['usermeta'] ) :
105
  '';
106
- $bp_fields =
107
- isset( $_POST['bp_fields'] ) ?
108
- array_map( 'sanitize_text_field', $_POST['bp_fields'] ) :
109
- '' ;
110
- $bp_fields_update =
111
- isset( $_POST['bp_fields_update_time'] ) ?
112
- array_map( 'sanitize_text_field', $_POST['bp_fields_update_time'] ) :
113
- '' ;
114
  $format =
115
  isset( $_POST['format'] ) ?
116
  \sanitize_text_field( $_POST['format'] ) :
@@ -125,8 +109,8 @@ class admin extends \q_export_user_data {
125
  '' ;
126
  $user_fields =
127
  isset( $_POST['user_fields'] ) ?
128
- array_map( 'sanitize_text_field', $_POST['user_fields'] ) :
129
- '0' ;
130
  $groups =
131
  isset( $_POST['groups'] ) ?
132
  \sanitize_text_field( $_POST['groups'] ) :
@@ -159,8 +143,8 @@ class admin extends \q_export_user_data {
159
  // assign all values to an array ##
160
  $save_array = array (
161
  'usermeta_saved_fields' => $usermeta,
162
- 'bp_fields_saved_fields' => $bp_fields,
163
- 'bp_fields_update_time_saved_fields' => $bp_fields_update,
164
  'role' => $role,
165
  'roles' => $roles,
166
  'user_fields' => $user_fields,
@@ -175,7 +159,7 @@ class admin extends \q_export_user_data {
175
  );
176
 
177
  // store the options, for next load ##
178
- user::set_user_options( $save_export, $save_array );
179
 
180
  // Display the settings the user just saved instead of blanking the form ##
181
  $_POST['load_export'] = 'Load Settings';
@@ -192,7 +176,7 @@ class admin extends \q_export_user_data {
192
  && \check_admin_referer( 'q-eud-admin-page', '_wpnonce-q-eud-admin-page' )
193
  ) {
194
 
195
- user::get_user_options_by_export( \sanitize_text_field( $_POST['export_name'] ) );
196
 
197
  }
198
 
@@ -203,7 +187,7 @@ class admin extends \q_export_user_data {
203
  && \check_admin_referer( 'q-eud-admin-page', '_wpnonce-q-eud-admin-page' )
204
  ) {
205
 
206
- user::delete_user_options( \sanitize_text_field( $_POST['export_name'] ) );
207
 
208
  }
209
 
@@ -215,7 +199,21 @@ class admin extends \q_export_user_data {
215
  // nothing happening? ##
216
  if ( isset( $_GET['error'] ) ) {
217
  echo '<div class="updated"><p><strong>' . \__( 'No users found.', 'q-export-user-data' ) . '</strong></p></div>';
218
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
  ?>
221
  <form method="post" action="" enctype="multipart/form-data">
@@ -297,7 +295,11 @@ class admin extends \q_export_user_data {
297
  }
298
 
299
  // print key ##
300
- echo "<option value='".\esc_attr( $key )."' title='".\esc_attr( $key )."' class='".$usermeta_class."'>$display_key</option>";
 
 
 
 
301
 
302
  }
303
  ?>
@@ -316,6 +318,7 @@ class admin extends \q_export_user_data {
316
  ?>
317
  <?php
318
 
 
319
  // buddypress x profile data ##
320
  if ( $bp_fields = buddypress::get_fields() ) {
321
 
@@ -382,7 +385,7 @@ class admin extends \q_export_user_data {
382
  <tr valign="top" class="toggleable">
383
  <th scope="row"><label for="groups"><?php \_e( 'BP User Groups', 'q-export-user-data' ); ?></label></th>
384
  <td>
385
- <input id='groups' type='checkbox' name='groups' value='1' <?php \checked( isset ( self::$groups ) ? intval ( self::$groups ) : '', 1 ); ?> />
386
  <p class="description"><?php
387
  printf(
388
  \__( 'Include BuddyPress Group Data. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
@@ -395,16 +398,16 @@ class admin extends \q_export_user_data {
395
  <?php
396
 
397
  } // BP installed and active ##
 
398
 
399
  ?>
400
  <tr valign="top" class="toggleable">
401
  <th scope="row"><label for="user_fields"><?php \_e( 'Standard User Fields', 'q-export-user-data' ); ?></label></th>
402
  <td>
403
- <input id='user_fields' type='checkbox' name='user_fields' value='1' <?php \checked( isset ( self::$user_fields ) ? intval ( self::$user_fields ) : '', 1 ); ?> />
404
  <p class="description"><?php
405
 
406
- #self::log( 'user_fields: '.self::$user_fields );
407
- #echo 'user_fields: '. self::$user_fields;
408
 
409
  printf(
410
  \__( 'Include Standard user profile fields, such as user_login. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
@@ -428,7 +431,7 @@ class admin extends \q_export_user_data {
428
 
429
  foreach ( $wp_roles->role_names as $role => $name ) {
430
 
431
- if ( isset ( self::$role ) && ( self::$role == $role ) ) {
432
 
433
  echo "\n\t<option selected value='" . \esc_attr( $role ) . "'>$name</option>";
434
 
@@ -455,7 +458,7 @@ class admin extends \q_export_user_data {
455
  <tr valign="top" class="toggleable">
456
  <th scope="row"><label for="roles"><?php \_e( 'User Roles', 'q-export-user-data' ); ?></label></th>
457
  <td>
458
- <input id='roles' type='checkbox' name='roles' value='1' <?php \checked( isset ( self::$roles ) ? intval ( self::$roles ) : '', 1 ); ?> />
459
  <p class="description"><?php
460
  printf(
461
  \__( 'Include all of the users <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
@@ -469,8 +472,8 @@ class admin extends \q_export_user_data {
469
  <tr valign="top" class="toggleable">
470
  <th scope="row"><label><?php \_e( 'Registered', 'q-export-user-data' ); ?></label></th>
471
  <td>
472
- <input type="text" id="q_eud_users_start_date" name="start_date" value="<?php echo self::$start_date; ?>" class="start-datepicker" />
473
- <input type="text" id="q_eud_users_end_date" name="end_date" value="<?php echo self::$end_date; ?>" class="end-datepicker" />
474
  <p class="description"><?php
475
  printf(
476
  \__( 'Pick a start and end user registration date to limit the results.', 'q-export-user-data' )
@@ -482,8 +485,8 @@ class admin extends \q_export_user_data {
482
  <tr valign="top" class="toggleable">
483
  <th scope="row"><label><?php \_e( 'Limit Range', 'q-export-user-data' ); ?></label></th>
484
  <td>
485
- <input name="limit_offset" type="text" id="q_eud_users_limit_offset" value="<?php echo( self::$limit_offset ); ?>" class="regular-text code numeric" style="width: 136px;" placeholder="<?php _e( 'Offset', 'q-export-user-data' ); ?>">
486
- <input name="limit_total" type="text" id="q_eud_users_limit_total" value="<?php echo ( self::$limit_total ); ?>" class="regular-text code numeric" style="width: 136px;" placeholder="<?php _e( 'Total', 'q-export-user-data' ); ?>">
487
  <p class="description"><?php
488
  printf(
489
  \__( 'Enter an offset start number and a total number of users to export. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
@@ -496,19 +499,20 @@ class admin extends \q_export_user_data {
496
  <?php
497
 
498
  // buddypress x profile data ##
 
499
  if ( $bp_fields = buddypress::get_fields() ) {
500
 
501
  ?>
502
  <tr valign="top" class="toggleable">
503
  <th scope="row"><label><?php \_e( 'Updated Since', 'q-export-user-data' ); ?></label></th>
504
  <td>
505
- <input type="text" id="q_eud_updated_since_date" name="updated_since_date" value="<?php echo self::$updated_since_date; ?>" class="updated-datepicker" />
506
  <select id="bp_field_updated_since" name="bp_field_updated_since">
507
  <?php
508
 
509
  foreach ( $bp_fields as $key ) {
510
 
511
- if ( self::$field_updated_since == $key ) {
512
 
513
  echo "<option value='".\esc_attr( $key )."' title='".\esc_attr( $key )."' selected>$key</option>";
514
 
@@ -533,13 +537,17 @@ class admin extends \q_export_user_data {
533
  <?php
534
 
535
  } // bp date ##
 
536
 
537
  // pull in extra export options from api ##
538
  if ( $api_fields = \apply_filters( 'q/eud/api/admin/fields', [] ) ) {
 
 
 
539
 
540
  foreach( $api_fields as $field ) {
541
 
542
- api_admin::render( $field );
543
 
544
  }
545
 
@@ -551,19 +559,8 @@ class admin extends \q_export_user_data {
551
  <td>
552
  <select name="format" id="q_eud_users_format">
553
  <?php
554
- /*
555
- if ( isset ( self::$format ) && ( self::$format == 'excel2003' ) ) {
556
-
557
- echo '<option selected value="excel2003">' . __( 'Excel 2003 (xls)', 'q-export-user-data' ) . '</option>';
558
-
559
- } else {
560
-
561
- echo '<option value="excel2003">' . __( 'Excel 2003 (xls)', 'q-export-user-data' ) . '</option>';
562
-
563
- }
564
- */
565
 
566
- if ( isset ( self::$format ) && ( self::$format == 'excel2007' ) ) {
567
 
568
  echo '<option selected value="excel2007">' . __( 'Excel 2007 (xlsx)', 'q-export-user-data' ) . '</option>';
569
 
@@ -573,7 +570,7 @@ class admin extends \q_export_user_data {
573
 
574
  }
575
 
576
- if ( isset ( self::$format ) && ( self::$format == 'csv' ) ) {
577
 
578
  echo '<option selected value="csv">' . __( 'CSV', 'q-export-user-data' ) . '</option>';
579
 
@@ -602,8 +599,8 @@ class admin extends \q_export_user_data {
602
  </div>
603
  <?php
604
 
605
- // check if the user has any saved exports ##
606
- if ( user::get_user_options() ) {
607
 
608
  ?>
609
  <div class="row">
@@ -611,7 +608,7 @@ class admin extends \q_export_user_data {
611
  <?php
612
 
613
  // loop over each saved export ##
614
- foreach( user::get_user_options() as $export ) {
615
 
616
  // select Loaded export name, if selected ##
617
  if (
@@ -669,13 +666,10 @@ class admin extends \q_export_user_data {
669
  <?php
670
  }
671
 
672
-
673
-
674
  /**
675
  * style and interaction
676
  */
677
- public static function admin_enqueue_scripts( $hook )
678
- {
679
 
680
  // load the scripts on only the plugin admin page ##
681
  if (
@@ -688,7 +682,7 @@ class admin extends \q_export_user_data {
688
 
689
  }
690
 
691
- \wp_register_style( 'q-eud-css', \plugins_url( 'css/q-eud.css' ,__FILE__ ), '', self::version );
692
  \wp_enqueue_style( 'q-eud-css' );
693
  \wp_enqueue_script( 'q_eud_multi_select_js', \plugins_url( 'javascript/jquery.multi-select.js', __FILE__ ), array('jquery'), '0.9.8', false );
694
 
@@ -697,21 +691,13 @@ class admin extends \q_export_user_data {
697
  \wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
698
  \wp_enqueue_style('jquery-ui');
699
 
700
- // add style ##
701
- // \wp_enqueue_style( 'jquery-ui-datepicker' );
702
- // \wp_enqueue_style('jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
703
-
704
  }
705
-
706
-
707
-
708
 
709
  /**
710
  * Inline jQuery
711
  * @since 0.8.2
712
  */
713
- public static function jquery()
714
- {
715
 
716
  // load the scripts on only the plugin admin page
717
  if (
@@ -721,7 +707,11 @@ class admin extends \q_export_user_data {
721
 
722
  return false;
723
 
724
- }
 
 
 
 
725
 
726
  ?>
727
  <script>
@@ -733,9 +723,9 @@ class admin extends \q_export_user_data {
733
  jQuery('#usermeta, #bp_fields, #bp_fields_update_time').multiSelect();
734
 
735
  // Select any fields from saved settings ##
736
- jQuery('#usermeta').multiSelect('select',([<?php echo( core::quote_array( self::$usermeta_saved_fields ) ); ?>]));
737
- jQuery('#bp_fields').multiSelect('select',([<?php echo( core::quote_array( self::$bp_fields_saved_fields ) ); ?>]));
738
- jQuery('#bp_fields_update_time').multiSelect('select',([<?php echo( core::quote_array( self::$bp_fields_update_time_saved_fields ) ); ?>]));
739
 
740
  // show only common ##
741
  jQuery('.usermeta-common').click(function(e){
@@ -820,7 +810,7 @@ class admin extends \q_export_user_data {
820
  <?php
821
 
822
  // method returns an object with "first" & "last" keys ##
823
- $dates = core::get_user_registered_dates();
824
 
825
  // get date format from WP settings #
826
  $date_format = 'yy-mm-dd' ; // get_option('date_format') ? get_option('date_format') : 'yy-mm-dd' ;
@@ -831,18 +821,18 @@ class admin extends \q_export_user_data {
831
 
832
  // start date picker ##
833
  jQuery('.start-datepicker').datepicker( {
834
- dateFormat : '<?php echo $date_format; ?>',
835
  minDate : '<?php echo substr( $dates["0"]->first, 0, 10 ); ?>',
836
  maxDate : '<?php echo substr( $dates["0"]->last, 0, 10 ); ?>',
837
- firstDay : '<?php echo $start_of_week; ?>'
838
  } );
839
 
840
  // end date picker ##
841
  jQuery('.end-datepicker').datepicker( {
842
- dateFormat : '<?php echo $date_format; ?>',
843
  minDate : '<?php echo substr( $dates["0"]->first, 0, 10 ); ?>',
844
  maxDate : '<?php echo substr( $dates["0"]->last, 0, 10 ); ?>',
845
- firstDay : '<?php echo $start_of_week; ?>'
846
  } );
847
 
848
  // end date picker ##
@@ -861,17 +851,13 @@ class admin extends \q_export_user_data {
861
  <?php
862
 
863
  }
864
-
865
-
866
-
867
 
868
  /**
869
  * Inline CSS
870
  *
871
  * @since 0.8.2
872
  */
873
- public static function css()
874
- {
875
 
876
  // load the scripts on only the plugin admin page
877
  if (
@@ -884,10 +870,10 @@ class admin extends \q_export_user_data {
884
  }
885
 
886
  ?>
887
- <style>
888
- .toggleable { display: none; }
889
- .hidden { display: none; }
890
- </style>
891
  <?php
892
 
893
  }
2
 
3
  namespace q\eud\admin;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin;
8
+ use q\eud\core\helper as h;
9
  use q\eud\core\user as user;
10
+ // use q\eud\core\buddypress as buddypress;
11
  use q\eud\api\admin as api_admin;
12
 
13
+ class render {
 
14
 
15
+ private $plugin, $user;
16
 
17
+ function __construct( \q\eud\plugin $plugin, \q\eud\core\user $user ){
 
18
 
19
+ $this->plugin = $plugin;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ $this->user = $user;
22
 
23
+ }
24
 
25
  /**
26
  * Add administration menus
27
  *
28
  * @since 0.1
29
  **/
30
+ public function add_menu(){
 
31
 
32
+ \add_users_page (
33
  __( 'Export User Data', 'q-export-user-data' ),
34
  __( 'Export User Data', 'q-export-user-data' ),
35
  \apply_filters( 'q/eud/admin_capability', 'list_users' ),
36
  'q-export-user-data',
37
+ [ $this, 'admin_page' ] // callback method ##
 
 
 
38
  );
39
 
40
  }
41
 
 
42
  /**
43
  * Content of the admin page
44
  *
45
  * @since 0.1
46
  */
47
+ public function admin_page(){
 
48
 
49
  // quick security check ##
50
  if ( ! \current_user_can( \apply_filters( 'q/eud/admin_capability', 'list_users' ) ) ) {
51
 
52
  \wp_die( __( 'You do not have sufficient permissions to access this page.', 'q-export-user-data' ) );
53
 
54
+ }
55
+
56
  // Save settings button was pressed ##
57
  if (
58
  isset( $_POST['save_export'] )
79
  // Build array of $options to save and save them ##
80
  if ( isset( $save_export ) ) {
81
 
82
+ // h::log( 'user_fields: '. $_POST['user_fields'] );
83
+
84
  // prepare all array values ##
85
  $usermeta =
86
  isset( $_POST['usermeta'] ) ?
87
  array_map( 'sanitize_text_field',
88
  $_POST['usermeta'] ) :
89
  '';
90
+ // $bp_fields =
91
+ // isset( $_POST['bp_fields'] ) ?
92
+ // array_map( 'sanitize_text_field', $_POST['bp_fields'] ) :
93
+ // '' ;
94
+ // $bp_fields_update =
95
+ // isset( $_POST['bp_fields_update_time'] ) ?
96
+ // array_map( 'sanitize_text_field', $_POST['bp_fields_update_time'] ) :
97
+ // '' ;
98
  $format =
99
  isset( $_POST['format'] ) ?
100
  \sanitize_text_field( $_POST['format'] ) :
109
  '' ;
110
  $user_fields =
111
  isset( $_POST['user_fields'] ) ?
112
+ \sanitize_text_field( $_POST['user_fields'] ) :
113
+ '1' ;
114
  $groups =
115
  isset( $_POST['groups'] ) ?
116
  \sanitize_text_field( $_POST['groups'] ) :
143
  // assign all values to an array ##
144
  $save_array = array (
145
  'usermeta_saved_fields' => $usermeta,
146
+ // 'bp_fields_saved_fields' => $bp_fields,
147
+ // 'bp_fields_update_time_saved_fields' => $bp_fields_update,
148
  'role' => $role,
149
  'roles' => $roles,
150
  'user_fields' => $user_fields,
159
  );
160
 
161
  // store the options, for next load ##
162
+ $this->user->set_user_options( $save_export, $save_array );
163
 
164
  // Display the settings the user just saved instead of blanking the form ##
165
  $_POST['load_export'] = 'Load Settings';
176
  && \check_admin_referer( 'q-eud-admin-page', '_wpnonce-q-eud-admin-page' )
177
  ) {
178
 
179
+ $this->user->get_user_options_by_export( \sanitize_text_field( $_POST['export_name'] ) );
180
 
181
  }
182
 
187
  && \check_admin_referer( 'q-eud-admin-page', '_wpnonce-q-eud-admin-page' )
188
  ) {
189
 
190
+ $this->user->delete_user_options( \sanitize_text_field( $_POST['export_name'] ) );
191
 
192
  }
193
 
199
  // nothing happening? ##
200
  if ( isset( $_GET['error'] ) ) {
201
  echo '<div class="updated"><p><strong>' . \__( 'No users found.', 'q-export-user-data' ) . '</strong></p></div>';
202
+ }
203
+
204
+ // get props
205
+ $_groups = $this->plugin->get( '_groups' );
206
+ $_user_fields = $this->plugin->get( '_user_fields' );
207
+ $_role = $this->plugin->get( '_role' );
208
+ $_roles = $this->plugin->get( '_roles' );
209
+ $_start_date = $this->plugin->get( '_start_date' );
210
+ $_end_date = $this->plugin->get( '_end_date' );
211
+ $_limit_offset = $this->plugin->get( '_limit_offset' );
212
+ $_limit_total = $this->plugin->get( '_limit_total' );
213
+ $_updated_since_date = $this->plugin->get( '_updated_since_date' );
214
+ $_format = $this->plugin->get( '_format' );
215
+ $_field_updated_since = $this->plugin->get( '_field_updated_since' );
216
+ $_updated_since_date = $this->plugin->get( '_updated_since_date' );
217
 
218
  ?>
219
  <form method="post" action="" enctype="multipart/form-data">
295
  }
296
 
297
  // print key ##
298
+ ?>
299
+ <option value="<?php \esc_attr_e( $key ); ?>" title="<?php \esc_attr_e( $key ); ?>" class="<?php \esc_attr_e( $usermeta_class ); ?>">
300
+ <?php \esc_attr_e( $display_key ); ?>
301
+ </option>
302
+ <?php
303
 
304
  }
305
  ?>
318
  ?>
319
  <?php
320
 
321
+ /*
322
  // buddypress x profile data ##
323
  if ( $bp_fields = buddypress::get_fields() ) {
324
 
385
  <tr valign="top" class="toggleable">
386
  <th scope="row"><label for="groups"><?php \_e( 'BP User Groups', 'q-export-user-data' ); ?></label></th>
387
  <td>
388
+ <input id='groups' type='checkbox' name='groups' value='1' <?php \checked( isset ( $_groups ) ? intval ( $_groups ) : '', 1 ); ?> />
389
  <p class="description"><?php
390
  printf(
391
  \__( 'Include BuddyPress Group Data. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
398
  <?php
399
 
400
  } // BP installed and active ##
401
+ */
402
 
403
  ?>
404
  <tr valign="top" class="toggleable">
405
  <th scope="row"><label for="user_fields"><?php \_e( 'Standard User Fields', 'q-export-user-data' ); ?></label></th>
406
  <td>
407
+ <input id='user_fields' type='checkbox' name='user_fields' value='1' <?php \checked( isset ( $_user_fields ) ? intval ( $_user_fields ) : '', 1 ); ?> />
408
  <p class="description"><?php
409
 
410
+ #h::log( 'user_fields: '.$_user_fields );
 
411
 
412
  printf(
413
  \__( 'Include Standard user profile fields, such as user_login. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
431
 
432
  foreach ( $wp_roles->role_names as $role => $name ) {
433
 
434
+ if ( isset ( $_role ) && ( $_role == $role ) ) {
435
 
436
  echo "\n\t<option selected value='" . \esc_attr( $role ) . "'>$name</option>";
437
 
458
  <tr valign="top" class="toggleable">
459
  <th scope="row"><label for="roles"><?php \_e( 'User Roles', 'q-export-user-data' ); ?></label></th>
460
  <td>
461
+ <input id='roles' type='checkbox' name='roles' value='1' <?php \checked( isset ( $_roles ) ? intval ( $_roles ) : '', 1 ); ?> />
462
  <p class="description"><?php
463
  printf(
464
  \__( 'Include all of the users <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
472
  <tr valign="top" class="toggleable">
473
  <th scope="row"><label><?php \_e( 'Registered', 'q-export-user-data' ); ?></label></th>
474
  <td>
475
+ <input type="text" id="q_eud_users_start_date" name="start_date" value="<?php echo $_start_date; ?>" class="start-datepicker" />
476
+ <input type="text" id="q_eud_users_end_date" name="end_date" value="<?php echo $_end_date; ?>" class="end-datepicker" />
477
  <p class="description"><?php
478
  printf(
479
  \__( 'Pick a start and end user registration date to limit the results.', 'q-export-user-data' )
485
  <tr valign="top" class="toggleable">
486
  <th scope="row"><label><?php \_e( 'Limit Range', 'q-export-user-data' ); ?></label></th>
487
  <td>
488
+ <input name="limit_offset" type="text" id="q_eud_users_limit_offset" value="<?php echo( $_limit_offset ); ?>" class="regular-text code numeric" style="width: 136px;" placeholder="<?php _e( 'Offset', 'q-export-user-data' ); ?>">
489
+ <input name="limit_total" type="text" id="q_eud_users_limit_total" value="<?php echo ( $_limit_total ); ?>" class="regular-text code numeric" style="width: 136px;" placeholder="<?php _e( 'Total', 'q-export-user-data' ); ?>">
490
  <p class="description"><?php
491
  printf(
492
  \__( 'Enter an offset start number and a total number of users to export. <a href="%s" target="_blank">%s</a>', 'q-export-user-data' )
499
  <?php
500
 
501
  // buddypress x profile data ##
502
+ /*
503
  if ( $bp_fields = buddypress::get_fields() ) {
504
 
505
  ?>
506
  <tr valign="top" class="toggleable">
507
  <th scope="row"><label><?php \_e( 'Updated Since', 'q-export-user-data' ); ?></label></th>
508
  <td>
509
+ <input type="text" id="q_eud_updated_since_date" name="updated_since_date" value="<?php echo $_updated_since_date; ?>" class="updated-datepicker" />
510
  <select id="bp_field_updated_since" name="bp_field_updated_since">
511
  <?php
512
 
513
  foreach ( $bp_fields as $key ) {
514
 
515
+ if ( $_field_updated_since == $key ) {
516
 
517
  echo "<option value='".\esc_attr( $key )."' title='".\esc_attr( $key )."' selected>$key</option>";
518
 
537
  <?php
538
 
539
  } // bp date ##
540
+ */
541
 
542
  // pull in extra export options from api ##
543
  if ( $api_fields = \apply_filters( 'q/eud/api/admin/fields', [] ) ) {
544
+
545
+ // create api instance #
546
+ $api_admin = new \q\eud\api\admin();
547
 
548
  foreach( $api_fields as $field ) {
549
 
550
+ $api_admin->render( $field );
551
 
552
  }
553
 
559
  <td>
560
  <select name="format" id="q_eud_users_format">
561
  <?php
 
 
 
 
 
 
 
 
 
 
 
562
 
563
+ if ( isset ( $_format ) && ( $_format == 'excel2007' ) ) {
564
 
565
  echo '<option selected value="excel2007">' . __( 'Excel 2007 (xlsx)', 'q-export-user-data' ) . '</option>';
566
 
570
 
571
  }
572
 
573
+ if ( isset ( $_format ) && ( $_format == 'csv' ) ) {
574
 
575
  echo '<option selected value="csv">' . __( 'CSV', 'q-export-user-data' ) . '</option>';
576
 
599
  </div>
600
  <?php
601
 
602
+ // check if the user has any saved exports ##
603
+ if ( $this->user->get_user_options() ) {
604
 
605
  ?>
606
  <div class="row">
608
  <?php
609
 
610
  // loop over each saved export ##
611
+ foreach( $this->user->get_user_options() as $export ) {
612
 
613
  // select Loaded export name, if selected ##
614
  if (
666
  <?php
667
  }
668
 
 
 
669
  /**
670
  * style and interaction
671
  */
672
+ function admin_enqueue_scripts( $hook ){
 
673
 
674
  // load the scripts on only the plugin admin page ##
675
  if (
682
 
683
  }
684
 
685
+ \wp_register_style( 'q-eud-css', \plugins_url( 'css/q-eud.css' ,__FILE__ ), '', $this->plugin->get( '_version' ) );
686
  \wp_enqueue_style( 'q-eud-css' );
687
  \wp_enqueue_script( 'q_eud_multi_select_js', \plugins_url( 'javascript/jquery.multi-select.js', __FILE__ ), array('jquery'), '0.9.8', false );
688
 
691
  \wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
692
  \wp_enqueue_style('jquery-ui');
693
 
 
 
 
 
694
  }
 
 
 
695
 
696
  /**
697
  * Inline jQuery
698
  * @since 0.8.2
699
  */
700
+ function jquery(){
 
701
 
702
  // load the scripts on only the plugin admin page
703
  if (
707
 
708
  return false;
709
 
710
+ }
711
+
712
+ $_usermeta_saved_fields = $this->plugin->get( '_usermeta_saved_fields' );
713
+ $_bp_fields_saved_fields = $this->plugin->get( '_bp_fields_saved_fields' );
714
+ $_bp_fields_update_time_saved_fields = $this->plugin->get( '_bp_fields_update_time_saved_fields' );
715
 
716
  ?>
717
  <script>
723
  jQuery('#usermeta, #bp_fields, #bp_fields_update_time').multiSelect();
724
 
725
  // Select any fields from saved settings ##
726
+ jQuery('#usermeta').multiSelect('select',([<?php echo( \q\eud\core\helper::quote_array( $_usermeta_saved_fields ) ); ?>]));
727
+ jQuery('#bp_fields').multiSelect('select',([<?php echo( \q\eud\core\helper::quote_array( $_bp_fields_saved_fields ) ); ?>]));
728
+ jQuery('#bp_fields_update_time').multiSelect('select',([<?php echo( \q\eud\core\helper::quote_array( $_bp_fields_update_time_saved_fields ) ); ?>]));
729
 
730
  // show only common ##
731
  jQuery('.usermeta-common').click(function(e){
810
  <?php
811
 
812
  // method returns an object with "first" & "last" keys ##
813
+ $dates = \q\eud\core\get::user_registered_dates();
814
 
815
  // get date format from WP settings #
816
  $date_format = 'yy-mm-dd' ; // get_option('date_format') ? get_option('date_format') : 'yy-mm-dd' ;
821
 
822
  // start date picker ##
823
  jQuery('.start-datepicker').datepicker( {
824
+ dateFormat : '<?php \esc_attr_e( $date_format ); ?>',
825
  minDate : '<?php echo substr( $dates["0"]->first, 0, 10 ); ?>',
826
  maxDate : '<?php echo substr( $dates["0"]->last, 0, 10 ); ?>',
827
+ firstDay : '<?php \esc_attr_e( $start_of_week ); ?>'
828
  } );
829
 
830
  // end date picker ##
831
  jQuery('.end-datepicker').datepicker( {
832
+ dateFormat : '<?php \esc_attr_e( $date_format ); ?>',
833
  minDate : '<?php echo substr( $dates["0"]->first, 0, 10 ); ?>',
834
  maxDate : '<?php echo substr( $dates["0"]->last, 0, 10 ); ?>',
835
+ firstDay : '<?php \esc_attr_e( $start_of_week ); ?>'
836
  } );
837
 
838
  // end date picker ##
851
  <?php
852
 
853
  }
 
 
 
854
 
855
  /**
856
  * Inline CSS
857
  *
858
  * @since 0.8.2
859
  */
860
+ function css(){
 
861
 
862
  // load the scripts on only the plugin admin page
863
  if (
870
  }
871
 
872
  ?>
873
+ <style>
874
+ .toggleable { display: none; }
875
+ .hidden { display: none; }
876
+ </style>
877
  <?php
878
 
879
  }
library/api/admin.php CHANGED
@@ -2,27 +2,21 @@
2
 
3
  namespace q\eud\api;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
 
7
 
8
- // load it up ##
9
- #\q\eud\api\admin::run();
10
 
11
- class admin extends \q_export_user_data {
12
 
13
- public static function run()
14
- {
15
-
16
- if ( \is_admin() ) {
17
-
18
- // load standard fields ##
19
- #\add_action( 'admin_init', array( get_class(), 'load' ), 1 );
20
-
21
- }
22
-
23
- }
24
 
 
25
 
 
26
 
27
  /**
28
  * Render admin fields
@@ -30,8 +24,7 @@ class admin extends \q_export_user_data {
30
  * @since 2.0.0.
31
  * @return HTML
32
  */
33
- public static function render( $array = null )
34
- {
35
 
36
  // check if we have any fields to show ##
37
  if (
@@ -39,13 +32,13 @@ class admin extends \q_export_user_data {
39
  || ! is_array( $array )
40
  ) {
41
 
42
- #helper::log( 'No fields found' );
43
 
44
  return false;
45
 
46
  }
47
 
48
- #helper::log( $array );
49
 
50
  // check that we have all required arrays ##
51
  if (
@@ -55,7 +48,7 @@ class admin extends \q_export_user_data {
55
  #|| ! $array['description']
56
  ) {
57
 
58
- #helper::log( 'Missing data' );
59
 
60
  return false;
61
 
@@ -67,12 +60,12 @@ class admin extends \q_export_user_data {
67
  // keep labels formatted nicely ##
68
  $array['label'] = \sanitize_key( $array['label'] );
69
 
70
- #helper::log( $array['options'] );
71
 
72
  // build out options ##
73
  if ( ! self::has_options( $array ) ) {
74
 
75
- #helper::log( 'Missing options for: '.$array['label'] );
76
 
77
  return false;
78
 
@@ -103,9 +96,7 @@ class admin extends \q_export_user_data {
103
 
104
  }
105
 
106
-
107
- public static function has_options( $array = null )
108
- {
109
 
110
  if (
111
  is_null( $array )
@@ -127,10 +118,7 @@ class admin extends \q_export_user_data {
127
 
128
  }
129
 
130
-
131
-
132
- public static function build_options( $array = null )
133
- {
134
 
135
  if (
136
  is_null( $array )
@@ -138,7 +126,7 @@ class admin extends \q_export_user_data {
138
  || ! isset( $array['type'] )
139
  ) {
140
 
141
- #helper::log( 'Error building options for: '.$array['label'] );
142
 
143
  return false;
144
 
@@ -162,10 +150,7 @@ class admin extends \q_export_user_data {
162
 
163
  }
164
 
165
-
166
-
167
- public static function field_select( $array = null )
168
- {
169
 
170
  if (
171
  is_null( $array )
@@ -178,13 +163,13 @@ class admin extends \q_export_user_data {
178
  || ! isset( $array['label_select'] )
179
  ) {
180
 
181
- #helper::log( 'Error building select options for: '.$array['label'] );
182
 
183
  return false;
184
 
185
  }
186
 
187
- #helper::log( 'Building select options for: '.$array['label'] );
188
 
189
  // is this a multiselect ? ##
190
  $multiselect = isset( $array['multiselect'] ) ? ' multiple="multiple"' : '' ;
@@ -227,5 +212,4 @@ class admin extends \q_export_user_data {
227
 
228
  }
229
 
230
-
231
  }
2
 
3
  namespace q\eud\api;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin;
8
+ use q\eud\core\core;
9
+ use q\eud\core\helper as h;
10
 
11
+ class admin {
 
12
 
13
+ private $plugin;
14
 
15
+ function __construct(){
 
 
 
 
 
 
 
 
 
 
16
 
17
+ $this->plugin = plugin::get_instance();
18
 
19
+ }
20
 
21
  /**
22
  * Render admin fields
24
  * @since 2.0.0.
25
  * @return HTML
26
  */
27
+ function render( $array = null ){
 
28
 
29
  // check if we have any fields to show ##
30
  if (
32
  || ! is_array( $array )
33
  ) {
34
 
35
+ #h::log( 'No fields found' );
36
 
37
  return false;
38
 
39
  }
40
 
41
+ #h::log( $array );
42
 
43
  // check that we have all required arrays ##
44
  if (
48
  #|| ! $array['description']
49
  ) {
50
 
51
+ #h::log( 'Missing data' );
52
 
53
  return false;
54
 
60
  // keep labels formatted nicely ##
61
  $array['label'] = \sanitize_key( $array['label'] );
62
 
63
+ #h::log( $array['options'] );
64
 
65
  // build out options ##
66
  if ( ! self::has_options( $array ) ) {
67
 
68
+ #h::log( 'Missing options for: '.$array['label'] );
69
 
70
  return false;
71
 
96
 
97
  }
98
 
99
+ public static function has_options( $array = null ){
 
 
100
 
101
  if (
102
  is_null( $array )
118
 
119
  }
120
 
121
+ public static function build_options( $array = null ){
 
 
 
122
 
123
  if (
124
  is_null( $array )
126
  || ! isset( $array['type'] )
127
  ) {
128
 
129
+ #h::log( 'Error building options for: '.$array['label'] );
130
 
131
  return false;
132
 
150
 
151
  }
152
 
153
+ public static function field_select( $array = null ){
 
 
 
154
 
155
  if (
156
  is_null( $array )
163
  || ! isset( $array['label_select'] )
164
  ) {
165
 
166
+ #h::log( 'Error building select options for: '.$array['label'] );
167
 
168
  return false;
169
 
170
  }
171
 
172
+ #h::log( 'Building select options for: '.$array['label'] );
173
 
174
  // is this a multiselect ? ##
175
  $multiselect = isset( $array['multiselect'] ) ? ' multiple="multiple"' : '' ;
212
 
213
  }
214
 
 
215
  }
library/api/function.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // use export_user_data\core;
4
+ use export_user_data\core;
5
+
6
+ /**
7
+ * export_user_data API
8
+ *
9
+ * @todo
10
+ */
11
+ if ( ! function_exists( 'export_user_data' ) ) {
12
+
13
+ function export_user_data(){
14
+
15
+ // sanity ##
16
+ if(
17
+ ! class_exists( '\export_user_data\plugin' )
18
+ ){
19
+
20
+ error_log( 'e:>Export User Data is not available to '.__FUNCTION__ );
21
+
22
+ return false;
23
+
24
+ }
25
+
26
+ // cache ##
27
+ $export_user_data = \q\eud\plugin::get_instance();
28
+
29
+ // sanity - make sure export_user_data instance returned ##
30
+ if(
31
+ is_null( $export_user_data )
32
+ || ! ( $export_user_data instanceof \q\eud\plugin )
33
+ ) {
34
+
35
+ // get stored export_user_data instance from filter ##
36
+ $export_user_data = \apply_filters( 'q/eud/instance', NULL );
37
+
38
+ // sanity - make sure export_user_data instance returned ##
39
+ if(
40
+ is_null( $export_user_data )
41
+ || ! ( $export_user_data instanceof \q\eud\plugin )
42
+ ) {
43
+
44
+ error_log( 'Error in object instance returned to '.__FUNCTION__ );
45
+
46
+ return false;
47
+
48
+ }
49
+
50
+ }
51
+
52
+ // return export_user_data instance ##
53
+ return $export_user_data;
54
+
55
+ }
56
+
57
+ }
library/core/{excel2003.php → .__excel2003.php} RENAMED
@@ -2,8 +2,10 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
 
8
  /**
9
  * XML template for excel file format
@@ -11,7 +13,7 @@ use q\eud\core\helper as helper;
11
  * @since 0.7.7
12
  **/
13
 
14
- class excel2003 extends \q_export_user_data {
15
 
16
  public static function begin(){
17
 
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\core\core;
8
+ use q\eud\core\helper as h;
9
 
10
  /**
11
  * XML template for excel file format
13
  * @since 0.7.7
14
  **/
15
 
16
+ class excel2003 {
17
 
18
  public static function begin(){
19
 
library/core/.__method.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace q\eud\core;
4
+
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
+
10
+ class method {
11
+
12
+ /**
13
+ * Get the array of standard WP_User fields to return
14
+ */
15
+ public static function get_user_fields(){
16
+
17
+ // standard wp_users fields ##
18
+ if ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) {
19
+
20
+ // debug ##
21
+ #h::log( 'full' );
22
+
23
+ // exportable user data ##
24
+ $user_fields = array(
25
+ 'ID'
26
+ , 'user_login'
27
+ #, 'user_pass'
28
+ , 'user_nicename'
29
+ , 'user_email'
30
+ , 'user_url'
31
+ , 'user_registered'
32
+ #, 'user_activation_key'
33
+ , 'user_status'
34
+ , 'display_name'
35
+ );
36
+
37
+ } else {
38
+
39
+ // debug ##
40
+ #h::log( 'reduced' );
41
+
42
+ // just return the user ID
43
+ $user_fields = array(
44
+ 'ID'
45
+ );
46
+
47
+ }
48
+
49
+ // kick back values via filter ##
50
+ return \apply_filters( 'q/eud/export/user_fields', $user_fields );
51
+
52
+ }
53
+
54
+ /**
55
+ * Get the array of special user fields to return
56
+ */
57
+ public static function get_special_fields(){
58
+
59
+ // exportable user data ##
60
+ $special_fields = array(
61
+ # 'roles' // list of WP Roles
62
+ #, 'groups' // BP Groups
63
+ );
64
+
65
+ // should we allow groups ##
66
+ if ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] ) {
67
+
68
+ $special_fields[] = 'groups'; // add groups ##
69
+
70
+ }
71
+
72
+ // should we allow roles ##
73
+ if ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] ) {
74
+
75
+ $special_fields[] = 'roles'; // add groups ##
76
+
77
+ }
78
+
79
+ // kick back the array via filter ##
80
+ return \apply_filters( 'q/eud/export/special_fields', $special_fields );
81
+
82
+ }
83
+
84
+ /**
85
+ * Data to exclude from export
86
+ */
87
+ public static function get_exclude_fields(){
88
+
89
+ $exclude_fields = array (
90
+ 'user_pass'
91
+ , 'q_eud_exports'
92
+ #, 'user_activation_key'
93
+ );
94
+
95
+ // kick back array via filter ##
96
+ return \apply_filters( 'q/eud/export/exclude_fields', $exclude_fields );
97
+
98
+ }
99
+ }
library/core/buddypress.php CHANGED
@@ -2,34 +2,27 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
 
8
- // load it up ##
9
- \q\eud\core\buddypress::run();
10
 
11
- class buddypress extends \q_export_user_data {
12
 
13
- public static function run()
14
- {
15
 
16
- if ( \is_admin() ) {
17
-
18
- // load BP ##
19
- \add_action( 'admin_init', array( get_class(), 'load' ), 1000001 );
20
-
21
- }
22
-
23
- }
24
 
 
25
 
26
  /**
27
  * Get BP fields from DB, if BuddyPress is installed and active
28
  *
29
  * @since 2.0.0
30
  */
31
- public static function get_fields()
32
- {
33
 
34
  // buddypress support deprecated for now ##
35
  return false;
@@ -60,8 +53,6 @@ class buddypress extends \q_export_user_data {
60
 
61
  }
62
 
63
-
64
-
65
  /**
66
  * Load up saved exports for this user
67
  * Set to public as hooked into action
@@ -69,8 +60,7 @@ class buddypress extends \q_export_user_data {
69
  * @since 0.9.6
70
  * @return Array of saved exports
71
  */
72
- public static function load()
73
- {
74
 
75
  // do we have a bp object in the globals ##
76
  if (
@@ -79,10 +69,10 @@ class buddypress extends \q_export_user_data {
79
  && ! isset( $GLOBALS['bp'] ) // but global unavailble ##
80
  ) {
81
 
82
- helper::log( 'BP not loaded - calling buddypress()' );
83
 
84
  // call BP
85
- buddypress();
86
 
87
  return true;
88
 
@@ -94,6 +84,4 @@ class buddypress extends \q_export_user_data {
94
 
95
  }
96
 
97
-
98
-
99
  }
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
 
10
+ class buddypress {
 
11
 
12
+ private $plugin;
13
 
14
+ function __construct(){
 
15
 
16
+ $this->plugin = plugin::get_instance();
 
 
 
 
 
 
 
17
 
18
+ }
19
 
20
  /**
21
  * Get BP fields from DB, if BuddyPress is installed and active
22
  *
23
  * @since 2.0.0
24
  */
25
+ public static function get_fields(){
 
26
 
27
  // buddypress support deprecated for now ##
28
  return false;
53
 
54
  }
55
 
 
 
56
  /**
57
  * Load up saved exports for this user
58
  * Set to public as hooked into action
60
  * @since 0.9.6
61
  * @return Array of saved exports
62
  */
63
+ public static function load(){
 
64
 
65
  // do we have a bp object in the globals ##
66
  if (
69
  && ! isset( $GLOBALS['bp'] ) // but global unavailble ##
70
  ) {
71
 
72
+ h::log( 'BP not loaded - calling buddypress()' );
73
 
74
  // call BP
75
+ \buddypress();
76
 
77
  return true;
78
 
84
 
85
  }
86
 
 
 
87
  }
library/core/config.php CHANGED
@@ -2,27 +2,20 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
 
8
- // load it up ##
9
- // \q\eud\core\config::run();
10
 
11
- class config extends \q_export_user_data {
12
 
13
- public static function run()
14
- {
15
-
16
- if ( \is_admin() ) {
17
-
18
- // load standard fields ##
19
- \add_action( 'admin_init', array( get_class(), 'load' ), 1 );
20
-
21
- }
22
-
23
- }
24
 
 
25
 
 
26
 
27
  /**
28
  * Load up saved exports for this user
@@ -31,8 +24,7 @@ class config extends \q_export_user_data {
31
  * @since 0.9.6
32
  * @return Array of saved exports
33
  */
34
- public static function load()
35
- {
36
 
37
  // load api admin fields ##
38
  self::get_admin_fields();
@@ -42,8 +34,6 @@ class config extends \q_export_user_data {
42
 
43
  }
44
 
45
-
46
-
47
  /**
48
  * Load up saved exports for this user
49
  * Set to public as hooked into action
@@ -51,38 +41,37 @@ class config extends \q_export_user_data {
51
  * @since 0.9.6
52
  * @return Array of saved exports
53
  */
54
- public static function get_admin_fields()
55
- {
56
 
57
  // build array ##
58
- $array = array(
59
- 'program' => array(
60
  'title' => \_e( 'Programs', 'export-user-data' ),
61
  'label' => 'program',
62
  'description' => \__( 'Select the program that you wish to export.', 'export-user-data' ),
63
  'label_select' => \__( 'All Programs', 'export-user-data' ),
64
- 'options' => \get_posts( array( 'post_type'=> 'program', 'posts_per_page' => -1 ) ),
65
  'options_ID' => 'ID',
66
  'options_title' => 'post_title'
67
- )
68
- );
69
 
70
  // test it ##
71
  #self::log( $array );
72
 
73
- // add to static property ##
74
- self::$api_admin_fields = $array;
75
-
76
  // filter and return ##
77
- apply_filters( 'q/eud/api/admin_fields', self::$api_admin_fields );
78
 
79
  // test it ##
80
- self::log( self::$api_admin_fields );
 
 
 
 
81
 
82
- // kick it back ##
83
  return true;
84
 
85
  }
86
 
87
-
88
  }
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
 
10
+ class config {
 
11
 
12
+ private $plugin;
13
 
14
+ function __construct(){
 
 
 
 
 
 
 
 
 
 
15
 
16
+ $this->plugin = plugin::get_instance();
17
 
18
+ }
19
 
20
  /**
21
  * Load up saved exports for this user
24
  * @since 0.9.6
25
  * @return Array of saved exports
26
  */
27
+ public static function load(){
 
28
 
29
  // load api admin fields ##
30
  self::get_admin_fields();
34
 
35
  }
36
 
 
 
37
  /**
38
  * Load up saved exports for this user
39
  * Set to public as hooked into action
41
  * @since 0.9.6
42
  * @return Array of saved exports
43
  */
44
+ public function get_admin_fields(){
 
45
 
46
  // build array ##
47
+ $array = [
48
+ 'program' => [
49
  'title' => \_e( 'Programs', 'export-user-data' ),
50
  'label' => 'program',
51
  'description' => \__( 'Select the program that you wish to export.', 'export-user-data' ),
52
  'label_select' => \__( 'All Programs', 'export-user-data' ),
53
+ 'options' => \get_posts([ 'post_type'=> 'program', 'posts_per_page' => -1 ]),
54
  'options_ID' => 'ID',
55
  'options_title' => 'post_title'
56
+ ]
57
+ ];
58
 
59
  // test it ##
60
  #self::log( $array );
61
 
 
 
 
62
  // filter and return ##
63
+ apply_filters( 'q/eud/api/admin_fields', $array );
64
 
65
  // test it ##
66
+ // h::log( $array );
67
+
68
+ // add to static property ##
69
+ // self::$api_admin_fields = $array;
70
+ $this->plugin->set( '_api_admin_fields', $array );
71
 
72
+ // kick back true ##
73
  return true;
74
 
75
  }
76
 
 
77
  }
library/core/core.php DELETED
@@ -1,426 +0,0 @@
1
- <?php
2
-
3
- namespace q\eud\core;
4
-
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
7
-
8
- // load it up ##
9
- #\q\eud\core\core::run();
10
-
11
- class core extends \q_export_user_data {
12
-
13
- public static function run()
14
- {
15
-
16
- if ( \is_admin() ) {
17
-
18
- // load user options ##
19
- #\add_action( 'admin_init', array( get_class(), 'load_user_options' ), 1000002 );
20
-
21
- }
22
-
23
- }
24
-
25
-
26
-
27
- /**
28
- * Get the array of standard WP_User fields to return
29
- */
30
- public static function get_user_fields()
31
- {
32
-
33
- // standard wp_users fields ##
34
- if ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) {
35
-
36
- // debug ##
37
- #self::log( 'full' );
38
-
39
- // exportable user data ##
40
- $user_fields = array(
41
- 'ID'
42
- , 'user_login'
43
- #, 'user_pass'
44
- , 'user_nicename'
45
- , 'user_email'
46
- , 'user_url'
47
- , 'user_registered'
48
- #, 'user_activation_key'
49
- , 'user_status'
50
- , 'display_name'
51
- );
52
-
53
- } else {
54
-
55
- // debug ##
56
- #self::log( 'reduced' );
57
-
58
- // just return the user ID
59
- $user_fields = array(
60
- 'ID'
61
- );
62
-
63
- }
64
-
65
- // kick back values via filter ##
66
- return \apply_filters( 'q/eud/export/user_fields', $user_fields );
67
-
68
- }
69
-
70
-
71
-
72
-
73
- /**
74
- * Get the array of special user fields to return
75
- */
76
- public static function get_special_fields()
77
- {
78
-
79
- // exportable user data ##
80
- $special_fields = array(
81
- # 'roles' // list of WP Roles
82
- #, 'groups' // BP Groups
83
- );
84
-
85
- // should we allow groups ##
86
- if ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] ) {
87
-
88
- $special_fields[] = 'groups'; // add groups ##
89
-
90
- }
91
-
92
- // should we allow roles ##
93
- if ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] ) {
94
-
95
- $special_fields[] = 'roles'; // add groups ##
96
-
97
- }
98
-
99
- // kick back the array via filter ##
100
- return \apply_filters( 'q/eud/export/special_fields', $special_fields );
101
-
102
- }
103
-
104
-
105
-
106
- /**
107
- * Data to exclude from export
108
- */
109
- public static function get_exclude_fields()
110
- {
111
-
112
- $exclude_fields = array (
113
- 'user_pass'
114
- , 'q_eud_exports'
115
- #, 'user_activation_key'
116
- );
117
-
118
- // kick back array via filter ##
119
- return \apply_filters( 'q/eud/export/exclude_fields', $exclude_fields );
120
-
121
- }
122
-
123
-
124
-
125
-
126
- /**
127
- * Return Byte count of $val
128
- *
129
- * @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
130
- * @since 0.9.6
131
- */
132
- public static function return_bytes( $val )
133
- {
134
-
135
- $val = trim( $val );
136
- $last = strtolower($val[strlen($val)-1]);
137
- switch( $last ) {
138
-
139
- // The 'G' modifier is available since PHP 5.1.0
140
- case 'g':
141
-
142
- $val *= 1024;
143
-
144
- case 'm':
145
-
146
- $val *= 1024;
147
-
148
- case 'k':
149
-
150
- $val *= 1024;
151
-
152
- }
153
-
154
- return $val;
155
-
156
- }
157
-
158
-
159
- /**
160
- * Recursively implodes an array
161
- *
162
- * @since 1.0.1
163
- * @access public
164
- * @param array $array multi-dimensional array to recursively implode
165
- * @param string $glue value that glues elements together
166
- * @param bool $include_keys include keys before their values
167
- * @param bool $trim_all trim ALL whitespace from string
168
- * @return string imploded array
169
- */
170
- public static function recursive_implode( $array, $return = null, $glue = '|' )
171
- {
172
-
173
- // unserialize ##
174
- $array = self::unserialize( $array );
175
-
176
- // kick it back ##
177
- if ( is_null ( $return ) && ! is_array( $array ) ) {
178
-
179
- return $array;
180
-
181
- }
182
-
183
- // empty return ##
184
- if ( is_null ( $return ) ) {
185
-
186
- $return = '';
187
-
188
- } else {
189
-
190
- if ( "||" == $glue ) {
191
-
192
- $glue = '|||';
193
-
194
- } else if ( "|" == $glue ) {
195
-
196
- $glue = '||';
197
-
198
- }
199
-
200
- }
201
-
202
- // loop ##
203
- foreach( $array as $key => $value ) {
204
-
205
- // unserialize ##
206
- $value = self::unserialize( $value );
207
-
208
- if( is_array( $value ) ) {
209
-
210
- $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
211
-
212
- // add @2.1.0 from issue #4 - https://github.com/qstudio/export-user-data/issues/4
213
- } elseif(is_object($value)) {
214
-
215
- $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
216
-
217
- } else {
218
-
219
- $return .= $glue . $key . $glue . $value;
220
-
221
- }
222
-
223
-
224
- }
225
-
226
- // Removes first $glue from string ##
227
- if ( $glue && $return && $return[0] == '|' ) {
228
-
229
- $return = ltrim( $return, '|' );
230
-
231
- }
232
-
233
- // Trim ALL whitespace ##
234
- if ( $return ) {
235
-
236
- $return = preg_replace( "/(\s)/ixsm", '', $return );
237
-
238
- }
239
-
240
- // kick it back ##
241
- return $return;
242
-
243
- }
244
-
245
-
246
-
247
-
248
- /**
249
- * Save Unserializer
250
- *
251
- * @since 1.1.4
252
- */
253
- public static function unserialize( $value = null )
254
- {
255
-
256
- // the $value is serialized ##
257
- if ( \is_serialized( $value ) ) {
258
-
259
- // unserliaze to new variable ##
260
- $unserialized = @unserialize( $value );
261
-
262
- // test if unserliazing produced errors ##
263
- if ( $unserialized !== false || $value == 'b:0;' ) {
264
-
265
- #$value = 'UNSERIALIZED_'.$unserialized;
266
- $value = $unserialized;
267
-
268
- } else {
269
-
270
- // failed to unserialize - data potentially corrupted in db ##
271
- #$value = 'NOT_SERIALIZED_'.$value;
272
- $value = $value;
273
-
274
- }
275
-
276
- }
277
-
278
- // kick it back ##
279
- return $value;
280
-
281
- }
282
-
283
-
284
-
285
-
286
- /**
287
- * Encode special characters
288
- *
289
- * @param type $string
290
- * @return string Encoding string
291
- * @since 1.2.3
292
- */
293
- public static function format_value( $string = null )
294
- {
295
-
296
- // sanity check ##
297
- if ( is_null( $string ) ) {
298
-
299
- return false;
300
-
301
- }
302
-
303
- // kick it back in a nicer format ##
304
- #return htmlentities( $string, ENT_COMPAT, 'UTF-8' );
305
-
306
- // kick it back via a filter to allow custom formatting ##
307
- return \apply_filters( 'q/eud/export/value', $string );
308
-
309
- }
310
-
311
-
312
-
313
- /**
314
- * Quote array elements and separate with commas
315
- *
316
- * @since 0.9.6
317
- * @return String
318
- */
319
- public static function quote_array( $array )
320
- {
321
-
322
- $prefix = ''; // starts empty ##
323
- $elementlist = '';
324
-
325
- if ( is_array( $array ) ) {
326
-
327
- foreach( $array as $element ) {
328
-
329
- $elementlist .= $prefix . "'" . $element . "'";
330
- $prefix = ','; // prefix all remaining items with a comma ##
331
-
332
- }
333
-
334
- }
335
-
336
- // kick back string to function caller ##
337
- return( $elementlist );
338
-
339
- }
340
-
341
-
342
- /**
343
- * Export Date Options
344
- *
345
- * @since 0.9.6
346
- * @global type $wpdb
347
- * @return Array of objects
348
- */
349
- public static function get_user_registered_dates()
350
- {
351
-
352
- // invite in global objects ##
353
- global $wpdb;
354
-
355
- // query user table for oldest and newest registration ##
356
- $range =
357
- $wpdb->get_results (
358
- #$wpdb->prepare (
359
- "
360
- SELECT
361
- MIN( user_registered ) AS first,
362
- MAX( user_registered ) AS last
363
- FROM
364
- {$wpdb->users}
365
- "
366
- #)
367
- );
368
-
369
- return $range;
370
-
371
- }
372
-
373
-
374
-
375
- /**
376
- * Sanitize data
377
- *
378
- * @since 1.2.8
379
- * @return string
380
- */
381
- public static function sanitize( $value )
382
- {
383
-
384
- // emove line breaks ##
385
- $value = str_replace("\r", '', $value);
386
- $value = str_replace("\n", '', $value);
387
- $value = str_replace("\t", '', $value);
388
-
389
- // with wp_kses ##
390
- $value = \wp_kses( $value, self::get_allowed_tags() );
391
-
392
- // with esc_html
393
- $value = \esc_html( $value );
394
-
395
- // return value ##
396
- return $value;
397
-
398
- }
399
-
400
-
401
- /**
402
- * Get allowed tags for wp_kses
403
- *
404
- * @since 1.2.8
405
- * @return Array
406
- */
407
- public static function get_allowed_tags()
408
- {
409
-
410
- $allowed_tags = array(
411
- 'a' => array(
412
- 'href' => array(),
413
- 'title' => array()
414
- ),
415
- 'br' => array(),
416
- 'em' => array(),
417
- 'strong' => array(),
418
- );
419
-
420
- // kick back via filter ##
421
- return \apply_filters( 'q/eud/export/allowed_tags', $allowed_tags );
422
-
423
- }
424
-
425
-
426
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
library/core/export.php CHANGED
@@ -2,37 +2,30 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
7
- // use q\eud\core\excel2003 as excel2003;
 
 
8
  use XLSXWriter;
9
 
10
- // load it up ##
11
- \q\eud\core\export::run();
12
 
13
- class export extends \q_export_user_data {
14
 
15
- public static function run()
16
- {
17
 
18
- if ( \is_admin() ) {
19
-
20
- // run export ##
21
- \add_action( 'admin_init', array( get_class(), 'render' ), 1000003 );
22
-
23
- }
24
-
25
- }
26
 
 
27
 
28
  /**
29
- * Attempt to generate the export file based on the passed arguements
30
- *
31
- * @since 0.1
32
- * @return Mixes
33
- **/
34
- public static function render()
35
- {
36
 
37
  // Check if the user clicked on the Save, Load, or Delete Settings buttons ##
38
  if (
@@ -57,7 +50,7 @@ class export extends \q_export_user_data {
57
  $args = array(
58
  'fields' => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ?
59
  'all' :
60
- array( 'ID' ), // exclude standard wp_users fields from get_users query ##
61
  'role' => \sanitize_text_field( $_POST['role'] )
62
  );
63
 
@@ -74,7 +67,7 @@ class export extends \q_export_user_data {
74
  $args['number'] = $limit_total; // number - Limit the total number of users returned ##
75
 
76
  // test it ##
77
- helper::log( $args );
78
 
79
  }
80
 
@@ -83,15 +76,15 @@ class export extends \q_export_user_data {
83
  // add custom args via filters ##
84
  $args = \apply_filters( 'q/eud/export/args', $args );
85
 
86
- #helper::log( $args );
87
 
88
  // pre_user query ##
89
- \add_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
90
  $users = \get_users( $args );
91
- \remove_action( 'pre_user_query', array( get_class(), 'pre_user_query' ) );
92
 
93
  // test args ##
94
- #if ( self::$debug ) helper::log ( $users );
95
 
96
  // no users found, so chuck an error into the args array and exit the export ##
97
  if ( ! $users ) {
@@ -201,7 +194,7 @@ class export extends \q_export_user_data {
201
  $breaker = "";
202
  $doc_end = "";
203
 
204
- $writer = new XLSXWriter();
205
 
206
  break;
207
 
@@ -210,8 +203,8 @@ class export extends \q_export_user_data {
210
 
211
  // check for selected usermeta fields ##
212
  $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
213
- #helper::log( $usermeta );
214
- $usermeta_fields = array();
215
 
216
  // loop over each field and sanitize ## @todo - user array_map ##
217
  if ( $usermeta && is_array( $usermeta ) ) {
@@ -220,7 +213,7 @@ class export extends \q_export_user_data {
220
  }
221
  }
222
 
223
- #helper::log( $usermeta_fields );
224
  #exit;
225
 
226
  // check for selected x profile fields ##
@@ -261,34 +254,34 @@ class export extends \q_export_user_data {
261
  global $wpdb;
262
 
263
  // debug ##
264
- #helper::log( 'merging array' );
265
 
266
  // compile final fields list ##
267
  $fields = array_merge(
268
- core::get_user_fields() // standard wp_user fields ##
269
- , core::get_special_fields() // 'special' fields - which are controlled via dedicated checks ##
270
  , $usermeta_fields // wp_user_meta fields ##
271
- , $bp_fields_passed // selected buddypress fields ##
272
- , $bp_fields_update_passed // update date for buddypress fields ##
273
  );
274
 
275
  // test field array ##
276
- #helper::log( $fields );
277
 
278
  // build the document headers ##
279
  $headers = array();
280
 
281
  foreach ( $fields as $key => $field ) {
282
 
283
- #helper::log( 'Field: '. $field );
284
 
285
  // filter field name ##
286
  $field = \apply_filters( 'q/eud/export/field', $field );
287
 
288
  // grab fields to exclude from exports - filterable ##
289
- if ( in_array( $fields[$key], core::get_exclude_fields() ) ) {
290
 
291
- #helper::log( 'Dump Field: '. $fields[$key] );
292
 
293
  // ditch 'em ##
294
  unset( $fields[$key] );
@@ -310,15 +303,15 @@ class export extends \q_export_user_data {
310
  }
311
 
312
  // quick check ##
313
- #helper::log( $fields );
314
- #if ( self::$debug ) #helper::log( $bp_fields_passed );
315
 
316
  // no more buffering while spitting back the export data ##
317
  if( ob_get_level() > 0 ) ob_end_flush();
318
 
319
  // get the value in bytes allocated for Memory via php.ini ##
320
  // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue
321
- $memory_limit = core::return_bytes( ini_get('memory_limit') ) * .75;
322
 
323
  // we need to disable caching while exporting because we export so much data that it could blow the memory cache
324
  // if we can't override the cache here, we'll have to clear it later...
@@ -338,30 +331,30 @@ class export extends \q_export_user_data {
338
 
339
  }
340
 
341
-
342
- if ($export_method !== "excel2007") {
343
  // open doc wrapper.. ##
344
  echo $doc_begin;
345
 
346
  // echo headers ##
347
  echo $pre . implode( $seperator, $headers ) . $breaker;
348
 
349
- #helper::log( $users );
350
  } else {
351
 
352
- $xlsx_header = array_flip($headers);
353
 
354
  foreach($xlsx_header as $k => $v) {
355
  $xlsx_header[$k] = "string";
356
  }
357
 
358
- $writer->writeSheetHeader('Sheet1', $xlsx_header);
 
359
  }
360
 
361
  // build row values for each user ##
362
  foreach ( $users as $user ) {
363
 
364
- #helper::log( $user );
365
 
366
  // check if we're hitting any Memory limits, if so flush them out ##
367
  // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
@@ -374,7 +367,7 @@ class export extends \q_export_user_data {
374
 
375
  // BP loaded ? ##
376
  if (
377
- ! self::$bp_data_available
378
  && function_exists ( 'bp_is_active' )
379
  && \bp_is_active( 'xprofile' )
380
  && class_exists( 'BP_XProfile_ProfileData' )
@@ -382,27 +375,27 @@ class export extends \q_export_user_data {
382
  && is_callable ( array( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
383
  ) {
384
 
385
- helper::log( 'XProfile Accessible' );
386
- self::$bp_data_available = true; // we only need to check for BP once ##
387
 
388
  }
389
 
390
  // grab all user data ##
391
  if (
392
- self::$bp_data_available
393
  && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID )
394
  ) {
395
 
396
  // null the data to be sure ##
397
  $bp_data = false;
398
 
399
- helper::log( 'XProfile returned no data ID#: '.$user->ID );
400
 
401
  }
402
 
403
  // single query method - get all user_meta data ##
404
  $get_user_meta = (array)\get_user_meta( $user->ID );
405
- #helper::log( $get_user_meta );
406
 
407
  // loop over each field ##
408
  foreach ( $fields as $field ) {
@@ -442,9 +435,7 @@ class export extends \q_export_user_data {
442
  #$value = $this->sanitize($value);
443
 
444
  // check if this is a BP field we want the updated date for ##
445
- }
446
- elseif ( in_array( $field, $bp_fields_update_passed ) )
447
- {
448
 
449
  global $bp;
450
 
@@ -463,9 +454,7 @@ class export extends \q_export_user_data {
463
  );
464
 
465
  // include the user's role in the export ##
466
- }
467
- elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' )
468
- {
469
 
470
  // empty array ##
471
  $user_roles = [];
@@ -481,23 +470,23 @@ class export extends \q_export_user_data {
481
  }
482
 
483
  // test ##
484
- // helper::log( $user_roles );
485
 
486
- // empty value if no role found - or flat array of user roles ##
487
- $value = ! empty( $user_roles ) ? implode( $user_roles, '|' ) : '';
 
 
 
488
 
489
  // include the user's BP group in the export ##
490
- }
491
- elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' )
492
- {
493
 
494
  if ( function_exists( 'groups_get_user_groups' ) ) {
495
 
496
  // check if user is a member of any groups ##
497
  $group_ids = \groups_get_user_groups( $user->ID );
498
 
499
- #$this->pr( $group_ids );
500
- #wp_die( pr( 'loaded group data.' ));
501
 
502
  if ( ! $group_ids || $group_ids == '' ) {
503
 
@@ -516,7 +505,8 @@ class export extends \q_export_user_data {
516
  }
517
 
518
  // implode it ##
519
- $value = implode( $groups, '|' );
 
520
 
521
  }
522
 
@@ -526,20 +516,24 @@ class export extends \q_export_user_data {
526
 
527
  }
528
 
529
- }
530
- elseif ( $field == 'bp_latest_update' || $field == 'last_activity' )
531
- {
 
 
532
 
533
  // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ##
534
  $value = \bp_get_user_last_activity( $user->ID );
 
535
 
536
  // user or usermeta field ##
537
- }
538
- else
539
- {
540
 
541
  // the user_meta key isset ##
542
- if ( isset( $get_user_meta[$field] ) ) {
 
 
 
543
 
544
  // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ##
545
  $value = $get_user_meta[$field][0];
@@ -552,76 +546,118 @@ class export extends \q_export_user_data {
552
 
553
  }
554
 
 
555
 
556
- // the $value might be serialized ##
557
- $value = core::unserialize( $value );
558
 
559
- // the value is an array ##
560
- if ( is_array ( $value ) ) {
561
 
562
- // recursive implode it ##
563
- $value = core::recursive_implode( $value );
 
 
 
564
 
565
- }
 
566
 
567
- // sanitize ##
568
- #$value = $this->sanitize($value);
569
 
570
- }
 
 
 
 
 
 
 
 
 
 
571
 
572
  // filter $value ##
573
- $value = \apply_filters( 'q/eud/export/value', $value, $field );
574
 
575
  // sanitize ##
576
- $value = core::sanitize( $value );
 
 
 
 
 
 
 
 
 
 
 
 
 
577
 
578
  // wrap values in quotes and add to array ##
579
  if ( $is_csv ) {
580
 
581
- $data[] = '"' . str_replace( '"', '""', core::format_value( $value ) ) . '"';
 
 
 
 
 
 
 
 
 
 
 
 
 
582
 
583
  // just add to array ##
584
  } else {
585
 
586
- $data[] = core::format_value( $value );
 
587
  }
588
 
589
  }
590
 
591
- if ($export_method !== "excel2007") {
592
- // echo row data ##
593
- echo $pre . implode( $seperator, $data ) . $breaker;
 
 
594
  } else {
595
- $writer->writeSheetRow('Sheet1', $data);
 
 
596
  }
597
 
598
  }
599
 
600
- if ($export_method !== "excel2007") {
 
601
  // close doc wrapper..
602
- echo $doc_end;
 
603
  } else {
604
- //$writer->writeSheet($rows,'Sheet1', $header); //or write the whole sheet in 1 call
605
- //$writer->writeToFile('xlsx-simple.xlsx');
606
- //$writer->writeToStdOut();
607
- echo $writer->writeToString();
608
  }
609
 
610
  // stop PHP, so file can export correctly ##
611
  exit;
612
 
613
  }
614
-
615
-
616
-
617
 
618
  /**
619
  * Pre User Query
620
  *
621
  * @since 2.0.0
622
  */
623
- public static function pre_user_query( $user_search = null )
624
- {
625
 
626
  global $wpdb;
627
 
@@ -651,12 +687,19 @@ class export extends \q_export_user_data {
651
  && (isset ($_POST['bp_field_updated_since'] ) && $_POST['bp_field_updated_since'] != '' )
652
  ) {
653
 
654
- $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
655
- self::$updated_since_date = $last_updated_date->format( 'Y-m-d H:i:s' );
656
- self::$field_updated_since = \sanitize_text_field ( $_POST['bp_field_updated_since'] );
657
- $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( self::$field_updated_since );
658
- $user_search->query_from .= " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
659
- $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, self::$updated_since_date );
 
 
 
 
 
 
 
660
 
661
  }
662
 
@@ -666,11 +709,9 @@ class export extends \q_export_user_data {
666
 
667
  }
668
 
669
- #wp_die( self::$pr( $user_search ) );
670
  return $user_search;
671
 
672
  }
673
 
674
-
675
-
676
  }
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
+ use q\eud\core\method;
10
  use XLSXWriter;
11
 
12
+ class export {
 
13
 
14
+ private $plugin;
15
 
16
+ function __construct( \q\eud\plugin $plugin ){
 
17
 
18
+ $this->plugin = $plugin;
 
 
 
 
 
 
 
19
 
20
+ }
21
 
22
  /**
23
+ * Attempt to generate the export file based on the passed arguements
24
+ *
25
+ * @since 0.1
26
+ * @return mixed
27
+ */
28
+ public function render(){
 
29
 
30
  // Check if the user clicked on the Save, Load, or Delete Settings buttons ##
31
  if (
50
  $args = array(
51
  'fields' => ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) ?
52
  'all' :
53
+ [ 'ID' ], // exclude standard wp_users fields from get_users query ##
54
  'role' => \sanitize_text_field( $_POST['role'] )
55
  );
56
 
67
  $args['number'] = $limit_total; // number - Limit the total number of users returned ##
68
 
69
  // test it ##
70
+ // h::log( $args );
71
 
72
  }
73
 
76
  // add custom args via filters ##
77
  $args = \apply_filters( 'q/eud/export/args', $args );
78
 
79
+ #h::log( $args );
80
 
81
  // pre_user query ##
82
+ \add_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
83
  $users = \get_users( $args );
84
+ \remove_action( 'pre_user_query', [ $this, 'pre_user_query' ] );
85
 
86
  // test args ##
87
+ #h::log ( $users );
88
 
89
  // no users found, so chuck an error into the args array and exit the export ##
90
  if ( ! $users ) {
194
  $breaker = "";
195
  $doc_end = "";
196
 
197
+ $writer = new \XLSXWriter();
198
 
199
  break;
200
 
203
 
204
  // check for selected usermeta fields ##
205
  $usermeta = isset( $_POST['usermeta'] ) ? $_POST['usermeta']: '';
206
+ #h::log( $usermeta );
207
+ $usermeta_fields = [];
208
 
209
  // loop over each field and sanitize ## @todo - user array_map ##
210
  if ( $usermeta && is_array( $usermeta ) ) {
213
  }
214
  }
215
 
216
+ #h::log( $usermeta_fields );
217
  #exit;
218
 
219
  // check for selected x profile fields ##
254
  global $wpdb;
255
 
256
  // debug ##
257
+ #h::log( 'merging array' );
258
 
259
  // compile final fields list ##
260
  $fields = array_merge(
261
+ get::user_fields() // standard wp_user fields ##
262
+ , get::special_fields() // 'special' fields - which are controlled via dedicated checks ##
263
  , $usermeta_fields // wp_user_meta fields ##
264
+ // , $bp_fields_passed // selected buddypress fields ##
265
+ // , $bp_fields_update_passed // update date for buddypress fields ##
266
  );
267
 
268
  // test field array ##
269
+ #h::log( $fields );
270
 
271
  // build the document headers ##
272
  $headers = array();
273
 
274
  foreach ( $fields as $key => $field ) {
275
 
276
+ #h::log( 'Field: '. $field );
277
 
278
  // filter field name ##
279
  $field = \apply_filters( 'q/eud/export/field', $field );
280
 
281
  // grab fields to exclude from exports - filterable ##
282
+ if ( in_array( $fields[$key], get::exclude_fields() ) ) {
283
 
284
+ #h::log( 'Dump Field: '. $fields[$key] );
285
 
286
  // ditch 'em ##
287
  unset( $fields[$key] );
303
  }
304
 
305
  // quick check ##
306
+ #h::log( $fields );
307
+ #h::log( $bp_fields_passed );
308
 
309
  // no more buffering while spitting back the export data ##
310
  if( ob_get_level() > 0 ) ob_end_flush();
311
 
312
  // get the value in bytes allocated for Memory via php.ini ##
313
  // @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue
314
+ $memory_limit = helper::return_bytes( ini_get('memory_limit') ) * .75;
315
 
316
  // we need to disable caching while exporting because we export so much data that it could blow the memory cache
317
  // if we can't override the cache here, we'll have to clear it later...
331
 
332
  }
333
 
334
+ if ( $export_method !== "excel2007" ) {
 
335
  // open doc wrapper.. ##
336
  echo $doc_begin;
337
 
338
  // echo headers ##
339
  echo $pre . implode( $seperator, $headers ) . $breaker;
340
 
341
+ #h::log( $users );
342
  } else {
343
 
344
+ $xlsx_header = array_flip( $headers );
345
 
346
  foreach($xlsx_header as $k => $v) {
347
  $xlsx_header[$k] = "string";
348
  }
349
 
350
+ $writer->writeSheetHeader('Sheet1', $xlsx_header);
351
+
352
  }
353
 
354
  // build row values for each user ##
355
  foreach ( $users as $user ) {
356
 
357
+ #h::log( $user );
358
 
359
  // check if we're hitting any Memory limits, if so flush them out ##
360
  // per http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
367
 
368
  // BP loaded ? ##
369
  if (
370
+ ! $this->plugin->get( '_bp_data_available' )
371
  && function_exists ( 'bp_is_active' )
372
  && \bp_is_active( 'xprofile' )
373
  && class_exists( 'BP_XProfile_ProfileData' )
375
  && is_callable ( array( 'BP_XProfile_ProfileData', 'get_all_for_user' ) )
376
  ) {
377
 
378
+ // h::log( 'XProfile Accessible' );
379
+ $this->plugin->set( '_bp_data_available', true ); // we only need to check for BP once ##
380
 
381
  }
382
 
383
  // grab all user data ##
384
  if (
385
+ $this->plugin->get( '_bp_data_available' )
386
  && ! $bp_data = \BP_XProfile_ProfileData::get_all_for_user( $user->ID )
387
  ) {
388
 
389
  // null the data to be sure ##
390
  $bp_data = false;
391
 
392
+ // h::log( 'XProfile returned no data ID#: '.$user->ID );
393
 
394
  }
395
 
396
  // single query method - get all user_meta data ##
397
  $get_user_meta = (array)\get_user_meta( $user->ID );
398
+ #h::log( $get_user_meta );
399
 
400
  // loop over each field ##
401
  foreach ( $fields as $field ) {
435
  #$value = $this->sanitize($value);
436
 
437
  // check if this is a BP field we want the updated date for ##
438
+ } elseif ( in_array( $field, $bp_fields_update_passed ) ) {
 
 
439
 
440
  global $bp;
441
 
454
  );
455
 
456
  // include the user's role in the export ##
457
+ } elseif ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] && $field == 'roles' ) {
 
 
458
 
459
  // empty array ##
460
  $user_roles = [];
470
  }
471
 
472
  // test ##
473
+ // h::log( $user_roles );
474
 
475
+ // empty value if no role found - or flat array of user roles ##
476
+ $value =
477
+ ! empty( $user_roles ) ?
478
+ helper::json_encode( $user_roles ) /*implode( '|', $user_roles )*/ :
479
+ '';
480
 
481
  // include the user's BP group in the export ##
482
+ } elseif ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] && $field == 'groups' ) {
 
 
483
 
484
  if ( function_exists( 'groups_get_user_groups' ) ) {
485
 
486
  // check if user is a member of any groups ##
487
  $group_ids = \groups_get_user_groups( $user->ID );
488
 
489
+ #h::log( $group_ids );
 
490
 
491
  if ( ! $group_ids || $group_ids == '' ) {
492
 
505
  }
506
 
507
  // implode it ##
508
+ // $value = implode( $groups, '|' );
509
+ $value = helper::json_encode( $groups );
510
 
511
  }
512
 
516
 
517
  }
518
 
519
+ /*
520
+ } elseif (
521
+ ( $field == 'bp_latest_update' && function_exists( 'bp_get_user_last_activity' ) )
522
+ || $field == 'last_activity'
523
+ ){
524
 
525
  // https://bpdevel.wordpress.com/2014/02/21/user-last_activity-data-and-buddypress-2-0/ ##
526
  $value = \bp_get_user_last_activity( $user->ID );
527
+ */
528
 
529
  // user or usermeta field ##
530
+ } else {
 
 
531
 
532
  // the user_meta key isset ##
533
+ if (
534
+ isset( $get_user_meta[$field] )
535
+ && is_array( $get_user_meta[$field] )
536
+ ){
537
 
538
  // take from the bulk get_user_meta call - this returns an array in all cases, so we take the first key ##
539
  $value = $get_user_meta[$field][0];
546
 
547
  }
548
 
549
+ }
550
 
551
+ // ---------- cleanup and format the value, before exporting ##
 
552
 
553
+ // the $value might be serialized, so try to unserialize ##
554
+ $value = helper::unserialize( $value );
555
 
556
+ // the value is an array ##
557
+ if (
558
+ is_array ( $value )
559
+ || is_object ( $value )
560
+ ){
561
 
562
+ helper::log( 'is_array || is_object' );
563
+ helper::log( $value );
564
 
565
+ // recursive implode it ##
566
+ // $value = helper::recursive_implode( $value );
567
 
568
+ // json_encode value to object
569
+ $value = helper::json_encode( $value );
570
+
571
+ // } else {
572
+
573
+ }
574
+
575
+ // sanitize string value ##
576
+ $value = helper::sanitize( $value );
577
+
578
+ // }
579
 
580
  // filter $value ##
581
+ // $value = \apply_filters( 'q/eud/export/value', $value, $field );
582
 
583
  // sanitize ##
584
+ // $value = helper::sanitize( $value );
585
+
586
+ // if no filter is added, apply default sanitiziation ##
587
+ // if( has_filter( 'q/eud/export/value' ) ){
588
+
589
+ // $value = \apply_filters( 'q/eud/export/value', $value );
590
+
591
+ // } else {
592
+
593
+ // $value = helper::format_value( $value );
594
+
595
+ // }
596
+
597
+ // helper::log( $value );
598
 
599
  // wrap values in quotes and add to array ##
600
  if ( $is_csv ) {
601
 
602
+ // replace single-double quotes with double-double quotes, if not dealing with a JSON string ###
603
+ // if( ! helper::is_json( $value ) ) {
604
+
605
+ // $value = str_replace( '"', '\"', $value );
606
+
607
+ // }
608
+
609
+ // wrap value in double quotes ##
610
+ $value = '"' . $value . '"';
611
+
612
+ // helper::log( $value );
613
+
614
+ // add value to $data array ##
615
+ $data[] = $value;
616
 
617
  // just add to array ##
618
  } else {
619
 
620
+ $data[] = $value;
621
+
622
  }
623
 
624
  }
625
 
626
+ if ( $export_method !== "excel2007" ) {
627
+
628
+ // echo row data ##
629
+ echo $pre . implode( $seperator, $data ) . $breaker;
630
+
631
  } else {
632
+
633
+ $writer->writeSheetRow( 'Sheet1', $data );
634
+
635
  }
636
 
637
  }
638
 
639
+ if ( $export_method !== "excel2007" ) {
640
+
641
  // close doc wrapper..
642
+ echo $doc_end;
643
+
644
  } else {
645
+
646
+ echo $writer->writeToString();
647
+
 
648
  }
649
 
650
  // stop PHP, so file can export correctly ##
651
  exit;
652
 
653
  }
 
 
 
654
 
655
  /**
656
  * Pre User Query
657
  *
658
  * @since 2.0.0
659
  */
660
+ function pre_user_query( $user_search = null ){
 
661
 
662
  global $wpdb;
663
 
687
  && (isset ($_POST['bp_field_updated_since'] ) && $_POST['bp_field_updated_since'] != '' )
688
  ) {
689
 
690
+ // get last update string ##
691
+ $last_updated_date = new \DateTime( \sanitize_text_field ( $_POST['updated_since_date'] ) . ' 00:00:00' );
692
+
693
+ // set date ##
694
+ $this->plugin->set( '_updated_since_date', $last_updated_date->format( 'Y-m-d H:i:s' ) );
695
+
696
+ // set field ##
697
+ $this->plugin->set( '_field_updated_since', \sanitize_text_field ( $_POST['bp_field_updated_since'] ) );
698
+ $field_updated_since_id = \BP_Xprofile_Field::get_id_from_name( $this->plugin->get( '_field_updated_since' ) );
699
+ $user_search->query_from .= " JOIN `wp_bp_xprofile_data` XP ON XP.user_id = wp_users.ID ";
700
+
701
+ // set where string ##
702
+ $where .= $wpdb->prepare( " AND XP.field_id = %s AND XP.last_updated >= %s", $field_updated_since_id, $this->plugin->get( '_updated_since_date' ) );
703
 
704
  }
705
 
709
 
710
  }
711
 
712
+ #h::log( $user_search ) );
713
  return $user_search;
714
 
715
  }
716
 
 
 
717
  }
library/core/filters.php CHANGED
@@ -2,34 +2,27 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
 
8
- // load it up ##
9
- \q\eud\core\filters::run();
10
 
11
- class filters extends \q_export_user_data {
12
 
13
- public static function run()
14
- {
15
 
16
- if ( \is_admin() ) {
17
-
18
- // EUD - filter key shown ##
19
- \add_filter( 'q/eud/admin/display_key', [ get_class(), 'display_key' ], 1, 1 );
20
-
21
- }
22
-
23
- }
24
 
 
25
 
26
  /**
27
  * Filter keys in EUD plugin
28
  *
29
  * @since 2.0.0
30
  */
31
- public static function display_key( $string = null )
32
- {
33
 
34
  #helper::log( 'string from filter: '.$string );
35
 
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
 
10
+ class filters {
 
11
 
12
+ private $plugin;
13
 
14
+ function __construct( \q\eud\plugin $plugin ){
 
15
 
16
+ $this->plugin = $plugin;
 
 
 
 
 
 
 
17
 
18
+ }
19
 
20
  /**
21
  * Filter keys in EUD plugin
22
  *
23
  * @since 2.0.0
24
  */
25
+ public static function display_key( $string = null ){
 
26
 
27
  #helper::log( 'string from filter: '.$string );
28
 
library/core/get.php ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace q\eud\core;
4
+
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
+
10
+ class get {
11
+
12
+ /**
13
+ * Get the array of standard WP_User fields to return
14
+ */
15
+ public static function user_fields(){
16
+
17
+ // standard wp_users fields ##
18
+ if ( isset( $_POST['user_fields'] ) && '1' == $_POST['user_fields'] ) {
19
+
20
+ // debug ##
21
+ #h::log( 'full' );
22
+
23
+ // exportable user data ##
24
+ $user_fields = array(
25
+ 'ID'
26
+ , 'user_login'
27
+ #, 'user_pass'
28
+ , 'user_nicename'
29
+ , 'user_email'
30
+ , 'user_url'
31
+ , 'user_registered'
32
+ #, 'user_activation_key'
33
+ , 'user_status'
34
+ , 'display_name'
35
+ );
36
+
37
+ } else {
38
+
39
+ // debug ##
40
+ #h::log( 'reduced' );
41
+
42
+ // just return the user ID
43
+ $user_fields = array(
44
+ 'ID'
45
+ );
46
+
47
+ }
48
+
49
+ // kick back values via filter ##
50
+ return \apply_filters( 'q/eud/export/user_fields', $user_fields );
51
+
52
+ }
53
+
54
+ /**
55
+ * Get the array of special user fields to return
56
+ */
57
+ public static function special_fields(){
58
+
59
+ // exportable user data ##
60
+ $special_fields = array(
61
+ # 'roles' // list of WP Roles
62
+ #, 'groups' // BP Groups
63
+ );
64
+
65
+ // should we allow groups ##
66
+ if ( isset( $_POST['groups'] ) && '1' == $_POST['groups'] ) {
67
+
68
+ $special_fields[] = 'groups'; // add groups ##
69
+
70
+ }
71
+
72
+ // should we allow roles ##
73
+ if ( isset( $_POST['roles'] ) && '1' == $_POST['roles'] ) {
74
+
75
+ $special_fields[] = 'roles'; // add groups ##
76
+
77
+ }
78
+
79
+ // kick back the array via filter ##
80
+ return \apply_filters( 'q/eud/export/special_fields', $special_fields );
81
+
82
+ }
83
+
84
+ /**
85
+ * Data to exclude from export
86
+ */
87
+ public static function exclude_fields(){
88
+
89
+ $exclude_fields = array (
90
+ 'user_pass'
91
+ , 'q_eud_exports'
92
+ #, 'user_activation_key'
93
+ );
94
+
95
+ // kick back array via filter ##
96
+ return \apply_filters( 'q/eud/export/exclude_fields', $exclude_fields );
97
+
98
+ }
99
+
100
+ /**
101
+ * Export Date Options
102
+ *
103
+ * @since 0.9.6
104
+ * @global type $wpdb
105
+ * @return Array of objects
106
+ * @todo Remove max date, as this makes little sense for exports not based on user reg dates.. ??
107
+ */
108
+ public static function user_registered_dates(){
109
+
110
+ // invite in global objects ##
111
+ global $wpdb;
112
+
113
+ // query user table for oldest and newest registration ##
114
+ $range =
115
+ $wpdb->get_results (
116
+ #$wpdb->prepare (
117
+ "
118
+ SELECT
119
+ MIN( user_registered ) AS first,
120
+ MAX( user_registered ) AS last
121
+ FROM
122
+ {$wpdb->users}
123
+ "
124
+ #)
125
+ );
126
+
127
+ return $range;
128
+
129
+ }
130
+
131
+ }
library/core/helper.php CHANGED
@@ -7,22 +7,20 @@ namespace q\eud\core;
7
  * helper Class
8
  * @package q_eud\core
9
  */
10
- class helper extends \q_export_user_data {
11
 
12
-
13
  /**
14
  * Write to WP Error Log
15
  *
16
  * @since 1.5.0
17
  * @return void
18
  */
19
- public static function log( $log )
20
- {
21
 
22
- if ( true === WP_DEBUG ) {
23
 
24
  $trace = debug_backtrace();
25
- $caller = $trace[1];
26
 
27
  $suffix = sprintf(
28
  __( ' - %s%s() %s:%d', 'Q' )
@@ -42,5 +40,406 @@ class helper extends \q_export_user_data {
42
 
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  }
7
  * helper Class
8
  * @package q_eud\core
9
  */
10
+ class helper {
11
 
 
12
  /**
13
  * Write to WP Error Log
14
  *
15
  * @since 1.5.0
16
  * @return void
17
  */
18
+ public static function log( $log ){
 
19
 
20
+ if ( true === \WP_DEBUG ) {
21
 
22
  $trace = debug_backtrace();
23
+ $caller = $trace[0];
24
 
25
  $suffix = sprintf(
26
  __( ' - %s%s() %s:%d', 'Q' )
40
 
41
  }
42
 
43
+
44
+ /**
45
+ * Return Byte count of $val
46
+ *
47
+ * @link http://wordpress.org/support/topic/how-to-exporting-a-lot-of-data-out-of-memory-issue?replies=2
48
+ * @since 0.9.6
49
+ */
50
+ public static function return_bytes( $val ){
51
+
52
+ $val = trim( $val );
53
+ $last = strtolower($val[strlen($val)-1]);
54
+ switch( $last ) {
55
+
56
+ // The 'G' modifier is available since PHP 5.1.0
57
+ case 'g':
58
+
59
+ $val *= 1024;
60
+
61
+ case 'm':
62
+
63
+ $val *= 1024;
64
+
65
+ case 'k':
66
+
67
+ $val *= 1024;
68
+
69
+ }
70
+
71
+ return $val;
72
+
73
+ }
74
+
75
+ /**
76
+ * Recursively implodes an array
77
+ *
78
+ * @since 1.0.1
79
+ * @access public
80
+ * @param array $array multi-dimensional array to recursively implode
81
+ * @param string $glue value that glues elements together
82
+ * @param bool $include_keys include keys before their values
83
+ * @param bool $trim_all trim ALL whitespace from string
84
+ * @return string imploded array
85
+ */
86
+ public static function recursive_implode( $array, $return = null, $glue = '|' ){
87
+
88
+ // unserialize ##
89
+ $array = self::unserialize( $array );
90
+
91
+ // kick it back ##
92
+ if ( is_null ( $return ) && ! is_array( $array ) ) {
93
+
94
+ return $array;
95
+
96
+ }
97
+
98
+ // empty return ##
99
+ if ( is_null ( $return ) ) {
100
+
101
+ $return = '';
102
+
103
+ } else {
104
+
105
+ if ( "||" == $glue ) {
106
+
107
+ $glue = '|||';
108
+
109
+ } else if ( "|" == $glue ) {
110
+
111
+ $glue = '||';
112
+
113
+ }
114
+
115
+ }
116
+
117
+ // loop ##
118
+ foreach( $array as $key => $value ) {
119
+
120
+ // unserialize ##
121
+ $value = self::unserialize( $value );
122
+
123
+ if( is_array( $value ) ) {
124
+
125
+ $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
126
+
127
+ // add @2.1.0 from issue #4 - https://github.com/qstudio/export-user-data/issues/4
128
+ } elseif(is_object($value)) {
129
+
130
+ $return .= $glue . $key . $glue . self::recursive_implode( $value, $return, $glue );
131
+
132
+ } else {
133
+
134
+ $return .= $glue . $key . $glue . $value;
135
+
136
+ }
137
+
138
+
139
+ }
140
+
141
+ // Removes first $glue from string ##
142
+ if ( $glue && $return && $return[0] == '|' ) {
143
+
144
+ $return = ltrim( $return, '|' );
145
+
146
+ }
147
+
148
+ // Trim ALL whitespace ##
149
+ if ( $return ) {
150
+
151
+ $return = preg_replace( "/(\s)/ixsm", '', $return );
152
+
153
+ }
154
+
155
+ // kick it back ##
156
+ return $return;
157
+
158
+ }
159
+
160
+ /**
161
+ * Save Unserializer
162
+ *
163
+ * @since 1.1.4
164
+ */
165
+ public static function unserialize( $value = null ){
166
+
167
+ // the $value is serialized ##
168
+ if ( \is_serialized( $value ) ) {
169
+
170
+ // unserliaze to new variable ##
171
+ $unserialized = @unserialize( $value );
172
+
173
+ // test if unserliazing produced errors ##
174
+ if (
175
+ $unserialized !== false
176
+ && $value !== 'b:0;'
177
+ ){
178
+
179
+ h::log( $unserialized );
180
+
181
+ #$value = 'UNSERIALIZED_'.$unserialized;
182
+ $value = $unserialized;
183
+
184
+ } else {
185
+
186
+ // failed to unserialize - data potentially corrupted in db ##
187
+ #$value = 'NOT_SERIALIZED_'.$value;
188
+ $value = $value;
189
+
190
+ }
191
+
192
+ }
193
+
194
+ // kick it back ##
195
+ return $value;
196
+
197
+ }
198
+
199
+ /**
200
+ * Encode special characters
201
+ *
202
+ * @param type $string
203
+ * @return string Encoding string
204
+ * @since 1.2.3
205
+ */
206
+ public static function format_value( string $value = null )
207
+ {
208
+
209
+ // sanity check ##
210
+ if ( is_null( $value ) ) {
211
+
212
+ return false;
213
+
214
+ }
215
+
216
+ if( has_filter( 'q/eud/export/value' ) ){
217
+
218
+ $value = \apply_filters( 'q/eud/export/value', $value );
219
+
220
+ } else {
221
+
222
+ $value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
223
+
224
+ }
225
+
226
+ // if value is a JSON_ENCODE'd string, then do not sanitize ##
227
+ // if( self::is_json( $value ) ){
228
+
229
+ // do we need to apply some escpaping ?? ##
230
+
231
+ // return $value;
232
+
233
+ // }
234
+
235
+ // sanitize ##
236
+ // $value = self::sanitize( $value );
237
+
238
+ // if no filter is added, apply default sanitiziation ##
239
+ // if( ! has_filter( 'q/eud/export/value' ) ){
240
+
241
+
242
+
243
+ // }
244
+
245
+ // self::log( $value );
246
+
247
+ // kick it back via a filter to allow custom formatting ##
248
+ return $value;
249
+
250
+ }
251
+
252
+ /**
253
+ * Encode array values to JSON string
254
+ *
255
+ * @since 2.2.1
256
+ * @param mixed
257
+ * @return mixed string|null
258
+ */
259
+ public static function json_encode( array $value ):?string
260
+ {
261
+
262
+ if ( ! is_array( $value ) ){
263
+
264
+ return $value;
265
+
266
+ }
267
+
268
+ // cleanup array ##
269
+ $value = array_values( $value );
270
+
271
+ // encode and escape ##
272
+ $value = htmlspecialchars( json_encode( $value, JSON_FORCE_OBJECT ) );
273
+
274
+ // self::log( $value );
275
+
276
+ // kick back JSON encoded string ##
277
+ return $value;
278
+
279
+ }
280
+
281
+ /**
282
+ * Quote array elements and separate with commas
283
+ *
284
+ * @since 0.9.6
285
+ * @return String
286
+ */
287
+ public static function quote_array( $array ){
288
+
289
+ $prefix = ''; // starts empty ##
290
+ $string = '';
291
+
292
+ if ( is_array( $array ) ) {
293
+
294
+ foreach( $array as $element ) {
295
+
296
+ $string .= $prefix . "'" . $element . "'";
297
+ $prefix = ','; // prefix all remaining items with a comma ##
298
+
299
+ }
300
+
301
+ }
302
+
303
+ // kick back string to function caller ##
304
+ return( $string );
305
+
306
+ }
307
+
308
+ /**
309
+ * Export Date Options
310
+ *
311
+ * @since 0.9.6
312
+ * @global type $wpdb
313
+ * @return Array of objects
314
+ * @todo Remove max date, as this makes little sense for exports not based on user reg dates.. ??
315
+ */
316
+ public static function get_user_registered_dates(){
317
+
318
+ // invite in global objects ##
319
+ global $wpdb;
320
+
321
+ // query user table for oldest and newest registration ##
322
+ $range =
323
+ $wpdb->get_results (
324
+ #$wpdb->prepare (
325
+ "
326
+ SELECT
327
+ MIN( user_registered ) AS first,
328
+ MAX( user_registered ) AS last
329
+ FROM
330
+ {$wpdb->users}
331
+ "
332
+ #)
333
+ );
334
+
335
+ return $range;
336
+
337
+ }
338
+
339
+ /**
340
+ * Sanitize data
341
+ *
342
+ * @since 1.2.8
343
+ * @return string
344
+ */
345
+ public static function sanitize_value( $value ){
346
+
347
+ // if value is a JSON_ENCODE'd string, then do not sanitize ##
348
+ // if( self::is_json( $value ) ){
349
+
350
+ // // do we need to apply some escpaping ?? ##
351
+
352
+ // return $value;
353
+
354
+ // }
355
+
356
+ // self::log( 'sanitize: '.$value );
357
+
358
+ if( has_filter( 'q/eud/export/value' ) ){
359
+
360
+ $value = \apply_filters( 'q/eud/export/value', $value );
361
+
362
+ } else {
363
+
364
+ $value = htmlentities( $value, ENT_COMPAT|ENT_COMPAT, 'UTF-8' );
365
+ // $value = \esc_attr( $value );
366
+
367
+ }
368
+
369
+ // remove line breaks ##
370
+ // $value = str_replace("\r", '', $value);
371
+ // $value = str_replace("\n", '', $value);
372
+ // $value = str_replace("\t", '', $value);
373
+
374
+ // with wp_kses ##
375
+ // $value = \wp_kses( $value, self::get_allowed_tags() );
376
+
377
+ // return value ##
378
+ return $value;
379
+
380
+ }
381
+
382
+ public static function sanitize( $value ) {
383
+
384
+ if ( is_array( $value ) ) {
385
+
386
+ array_walk_recursive( $value, [ __CLASS__, 'sanitize_value' ] );
387
+
388
+ } else {
389
+
390
+ self::sanitize_value( $value );
391
+
392
+ }
393
+
394
+ return $value;
395
+
396
+ }
397
+
398
+ /**
399
+ * Check if a string is JSON
400
+ *
401
+ * @since 2.0.2
402
+ */
403
+ public static function is_json( $string )
404
+ {
405
+
406
+ json_decode( $string );
407
+
408
+ if ( json_last_error() === JSON_ERROR_NONE ){
409
+
410
+ // self::log( 'is_json: '.$string );
411
+
412
+ return true;
413
+
414
+ }
415
+
416
+ // self::log( 'is not json: '.$string );
417
+
418
+ return false;
419
+
420
+ }
421
+
422
+ /**
423
+ * Get allowed tags for wp_kses
424
+ *
425
+ * @since 1.2.8
426
+ * @return Array
427
+ */
428
+ public static function get_allowed_tags(){
429
+
430
+ $allowed_tags = [
431
+ 'a' => [
432
+ 'href' => [],
433
+ 'title' => []
434
+ ],
435
+ 'br' => [],
436
+ 'em' => [],
437
+ 'strong' => [],
438
+ ];
439
+
440
+ // kick back via filter ##
441
+ return \apply_filters( 'q/eud/export/allowed_tags', $allowed_tags );
442
+
443
+ }
444
 
445
  }
library/core/user.php CHANGED
@@ -2,26 +2,20 @@
2
 
3
  namespace q\eud\core;
4
 
5
- use q\eud\core\core as core;
6
- use q\eud\core\helper as helper;
 
 
7
 
8
- // load it up ##
9
- \q\eud\core\user::run();
10
 
11
- class user extends \q_export_user_data {
12
 
13
- public static function run()
14
- {
15
 
16
- if ( \is_admin() ) {
17
-
18
- // load user options ##
19
- \add_action( 'admin_init', array( get_class(), 'load' ), 1000002 );
20
-
21
- }
22
-
23
- }
24
 
 
25
 
26
  /**
27
  * Load up saved exports for this user
@@ -30,8 +24,7 @@ class user extends \q_export_user_data {
30
  * @since 0.9.6
31
  * @return Array of saved exports
32
  */
33
- public static function load()
34
- {
35
 
36
  // convert outdated stored meta from q_report to q_eud_exports ##
37
  if(
@@ -51,17 +44,21 @@ class user extends \q_export_user_data {
51
  }
52
 
53
  // test #
54
- // helper::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
55
-
56
- return self::$q_eud_exports =
57
- \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
58
- \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
59
- array() ;
60
-
61
- }
62
 
 
 
 
 
 
63
 
 
 
64
 
 
 
 
 
65
 
66
  /**
67
  * Get list of saved exports for this user
@@ -69,27 +66,29 @@ class user extends \q_export_user_data {
69
  * @since 0.9.4
70
  * @return Array of saved exports
71
  */
72
- public static function get_user_options()
73
- {
 
 
74
 
75
  // get the stored options - filter empty array items ##
76
- $q_eud_exports = array_filter( self::$q_eud_exports );
77
 
78
  // quick check if the array is empty ##
79
- if ( empty ( $q_eud_exports ) ) {
80
 
81
  return false;
82
 
83
  }
84
 
85
  // test the array of saved exports ##
86
- #$this->pr( $q_eud_exports );
87
 
88
  // start with an empty array ##
89
- $exports = array();
90
 
91
  // loop over each saved export and grab each key ##
92
- foreach ( $q_eud_exports as $key => $value ) {
93
 
94
  $exports[] = $key;
95
 
@@ -100,58 +99,74 @@ class user extends \q_export_user_data {
100
 
101
  }
102
 
103
-
104
  /**
105
  * Check for and load stored user options
106
  *
107
  * @since 0.9.3
108
  * @return void
109
  */
110
- public static function get_user_options_by_export( $export = null )
111
- {
112
 
113
  // sanity check ##
114
- if ( is_null ( $export ) ) { return false; }
115
-
116
- if ( isset( self::$q_eud_exports[$export] ) ) {
117
-
118
- self::$usermeta_saved_fields = self::$q_eud_exports[$export]['usermeta_saved_fields'];
119
- self::$bp_fields_saved_fields = self::$q_eud_exports[$export]['bp_fields_saved_fields'];
120
- self::$bp_fields_update_time_saved_fields = self::$q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
121
- self::$updated_since_date = isset( self::$q_eud_exports[$export]['updated_since_date'] ) ? self::$q_eud_exports[$export]['updated_since_date'] : null ;
122
- self::$field_updated_since = isset( self::$q_eud_exports[$export]['field_updated_since'] ) ? self::$q_eud_exports[$export]['field_updated_since'] : null ;
123
- self::$role = self::$q_eud_exports[$export]['role'];
124
- self::$roles = self::$q_eud_exports[$export]['roles'];
125
- self::$groups = self::$q_eud_exports[$export]['groups'];
126
- self::$user_fields = isset( self::$q_eud_exports[$export]['user_fields'] ) ? self::$q_eud_exports[$export]['user_fields'] : null ;
127
- self::$start_date = self::$q_eud_exports[$export]['start_date'];
128
- self::$end_date = self::$q_eud_exports[$export]['end_date'];
129
- self::$limit_offset = self::$q_eud_exports[$export]['limit_offset'];
130
- self::$limit_total = self::$q_eud_exports[$export]['limit_total'];
131
- self::$format = self::$q_eud_exports[$export]['format'];
 
 
 
132
 
133
  } else {
134
 
135
- self::$usermeta_saved_fields = array();
136
- self::$bp_fields_saved_fields = array();
137
- self::$bp_fields_update_time_saved_fields = array();
138
- self::$updated_since_date = '';
139
- self::$field_updated_since = '';
140
- self::$role = '';
141
- self::$user_fields = '1';
142
- self::$roles = '1';
143
- self::$groups = '1';
144
- self::$start_date = '';
145
- self::$end_date = '';
146
- self::$limit_offset = '';
147
- self::$limit_total = '';
148
- self::$format = '';
149
 
150
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
  }
153
 
154
-
155
  /**
156
  * Method to store user options
157
  *
@@ -160,24 +175,26 @@ class user extends \q_export_user_data {
160
  * @since 0.9.3
161
  * @return void
162
  */
163
- public static function set_user_options( $key = null, $options = null )
164
- {
165
 
166
  // sanity check ##
167
  if ( is_null ( $key ) || is_null ( $options ) ) {
168
 
169
- #$this->pr( 'missing save values' );
170
  return false;
171
 
172
  }
173
 
174
- #$this->pr( $key );
175
- #$this->pr( $options );
 
 
 
176
 
177
  // for now, I'm simply allowing keys to be resaved - but this is not so logical ##
178
- if ( array_key_exists( $key, self::$q_eud_exports ) ) {
179
 
180
- #$this->pr( 'key exists, skipping save' );
181
  #return false;
182
 
183
  }
@@ -205,19 +222,20 @@ class user extends \q_export_user_data {
205
  }
206
 
207
  // assign the sanitized array of values to the class property $q_eud_exports as a new array with key $key ##
208
- self::$q_eud_exports[$key] = $options;
 
 
 
209
 
210
  // update stored user_meta values, if previous key found ##
211
- if ( \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) !== false ) {
212
 
213
- #update_option( 'q_eud_exports', $this->q_eud_exports );
214
- \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
215
 
216
  // create new user meta key ##
217
  } else {
218
 
219
- #add_option( 'q_eud_exports', $this->q_eud_exports, $deprecated, $autoload );
220
- \add_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
221
 
222
  }
223
 
@@ -225,7 +243,6 @@ class user extends \q_export_user_data {
225
 
226
  }
227
 
228
-
229
  /**
230
  * method to delete user options
231
  *
@@ -233,26 +250,32 @@ class user extends \q_export_user_data {
233
  * @since 0.9.3
234
  * @return void
235
  */
236
- public static function delete_user_options( $key = null )
237
- {
 
 
238
 
239
  // sanity check ##
240
- if ( is_null ( $key ) || ! array_key_exists( $key, self::$q_eud_exports ) ) { return false; }
241
 
242
  // clean it up ##
243
  $key = \sanitize_text_field( $key );
244
 
245
  // check it out ##
246
- #$this->pr( $key );
247
 
248
  // drop the array by it's key name from the class property ##
249
- unset( self::$q_eud_exports[$key] );
250
 
251
  // update the saved data ##
252
- \update_user_meta( \get_current_user_id(), 'q_eud_exports', self::$q_eud_exports );
253
-
254
- }
 
255
 
 
 
256
 
 
257
 
258
  }
2
 
3
  namespace q\eud\core;
4
 
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
 
10
+ class user {
 
11
 
12
+ private $plugin;
13
 
14
+ public function __construct( \q\eud\plugin $plugin ){
 
15
 
16
+ $this->plugin = $plugin;
 
 
 
 
 
 
 
17
 
18
+ }
19
 
20
  /**
21
  * Load up saved exports for this user
24
  * @since 0.9.6
25
  * @return Array of saved exports
26
  */
27
+ public function load(){
 
28
 
29
  // convert outdated stored meta from q_report to q_eud_exports ##
30
  if(
44
  }
45
 
46
  // test #
47
+ // h::log( \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) );
 
 
 
 
 
 
 
48
 
49
+ // get array ##
50
+ $array =
51
+ \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ?
52
+ \get_user_meta( \get_current_user_id(), 'q_eud_exports', true ) :
53
+ [] ;
54
 
55
+ // set prop ##
56
+ $this->plugin->set( '_q_eud_exports', $array );
57
 
58
+ // return bool ##
59
+ return true;
60
+
61
+ }
62
 
63
  /**
64
  * Get list of saved exports for this user
66
  * @since 0.9.4
67
  * @return Array of saved exports
68
  */
69
+ function get_user_options(){
70
+
71
+ // get props ##
72
+ $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
73
 
74
  // get the stored options - filter empty array items ##
75
+ $_q_eud_exports = array_filter( $_q_eud_exports );
76
 
77
  // quick check if the array is empty ##
78
+ if ( empty ( $_q_eud_exports ) ) {
79
 
80
  return false;
81
 
82
  }
83
 
84
  // test the array of saved exports ##
85
+ #h::log( $_q_eud_exports );
86
 
87
  // start with an empty array ##
88
+ $exports = [];
89
 
90
  // loop over each saved export and grab each key ##
91
+ foreach ( $_q_eud_exports as $key => $value ) {
92
 
93
  $exports[] = $key;
94
 
99
 
100
  }
101
 
 
102
  /**
103
  * Check for and load stored user options
104
  *
105
  * @since 0.9.3
106
  * @return void
107
  */
108
+ function get_user_options_by_export( $export = null ){
 
109
 
110
  // sanity check ##
111
+ if ( is_null ( $export ) ) { return false; }
112
+
113
+ // get props ##
114
+ $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
115
+
116
+ if ( isset( $_q_eud_exports[$export] ) ) {
117
+
118
+ $_usermeta_saved_fields = $_q_eud_exports[$export]['usermeta_saved_fields'];
119
+ // $_bp_fields_saved_fields = $_q_eud_exports[$export]['bp_fields_saved_fields'];
120
+ // $_bp_fields_update_time_saved_fields = $_q_eud_exports[$export]['bp_fields_update_time_saved_fields'];
121
+ $_updated_since_date = $_q_eud_exports[$export]['updated_since_date'] ?? null ;
122
+ $_field_updated_since = $_q_eud_exports[$export]['field_updated_since'] ?? null ;
123
+ $_role = $_q_eud_exports[$export]['role'];
124
+ $_roles = $_q_eud_exports[$export]['roles'];
125
+ $_groups = $_q_eud_exports[$export]['groups'];
126
+ $_user_fields = $_q_eud_exports[$export]['user_fields'] ?? null ;
127
+ $_start_date = $_q_eud_exports[$export]['start_date'];
128
+ $_end_date = $_q_eud_exports[$export]['end_date'];
129
+ $_limit_offset = $_q_eud_exports[$export]['limit_offset'];
130
+ $_limit_total = $_q_eud_exports[$export]['limit_total'];
131
+ $_format = $_q_eud_exports[$export]['format'];
132
 
133
  } else {
134
 
135
+ $_usermeta_saved_fields = [];
136
+ // $_bp_fields_saved_fields = [];
137
+ // $_bp_fields_update_time_saved_fields = [];
138
+ $_updated_since_date = '';
139
+ $_field_updated_since = '';
140
+ $_role = '';
141
+ $_user_fields = '1';
142
+ $_roles = '1';
143
+ $_groups = '1';
144
+ $_start_date = '';
145
+ $_end_date = '';
146
+ $_limit_offset = '';
147
+ $_limit_total = '';
148
+ $_format = '';
149
 
150
+ }
151
+
152
+ // set props ##
153
+ $this->plugin->set( '_usermeta_saved_fields', $_usermeta_saved_fields );
154
+ // $this->plugin->set( '_bp_fields_saved_fields', $_bp_fields_saved_fields );
155
+ // $this->plugin->set( '_bp_fields_update_time_saved_fields', $_bp_fields_update_time_saved_fields );
156
+ $this->plugin->set( '_updated_since_date', $_updated_since_date );
157
+ $this->plugin->set( '_field_updated_since', $_field_updated_since );
158
+ $this->plugin->set( '_role', $_role );
159
+ $this->plugin->set( '_user_fields', $_user_fields );
160
+ $this->plugin->set( '_roles', $_roles );
161
+ $this->plugin->set( '_groups', $_groups );
162
+ $this->plugin->set( '_start_date', $_start_date );
163
+ $this->plugin->set( '_end_date', $_end_date );
164
+ $this->plugin->set( '_limit_offset', $_limit_offset );
165
+ $this->plugin->set( '_limit_total', $_limit_total );
166
+ $this->plugin->set( '_format', $_format );
167
 
168
  }
169
 
 
170
  /**
171
  * Method to store user options
172
  *
175
  * @since 0.9.3
176
  * @return void
177
  */
178
+ function set_user_options( $key = null, $options = null ){
 
179
 
180
  // sanity check ##
181
  if ( is_null ( $key ) || is_null ( $options ) ) {
182
 
183
+ #h::log( 'missing save values' );
184
  return false;
185
 
186
  }
187
 
188
+ #h::log( $key );
189
+ #h::log( $options );
190
+
191
+ // get prop ##
192
+ $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
193
 
194
  // for now, I'm simply allowing keys to be resaved - but this is not so logical ##
195
+ if ( array_key_exists( $key, $_q_eud_exports ) ) {
196
 
197
+ #h::log( 'key exists, skipping save' );
198
  #return false;
199
 
200
  }
222
  }
223
 
224
  // assign the sanitized array of values to the class property $q_eud_exports as a new array with key $key ##
225
+ $_q_eud_exports[$key] = $options;
226
+
227
+ // set prop ##
228
+ $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
229
 
230
  // update stored user_meta values, if previous key found ##
231
+ if ( false !== \get_user_meta( \get_current_user_id(), 'q_eud_exports' ) ) {
232
 
233
+ \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
 
234
 
235
  // create new user meta key ##
236
  } else {
237
 
238
+ \add_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
 
239
 
240
  }
241
 
243
 
244
  }
245
 
 
246
  /**
247
  * method to delete user options
248
  *
250
  * @since 0.9.3
251
  * @return void
252
  */
253
+ function delete_user_options( $key = null ){
254
+
255
+ // get prop ##
256
+ $_q_eud_exports = $this->plugin->get( '_q_eud_exports' );
257
 
258
  // sanity check ##
259
+ if ( is_null ( $key ) || ! array_key_exists( $key, $_q_eud_exports ) ) { return false; }
260
 
261
  // clean it up ##
262
  $key = \sanitize_text_field( $key );
263
 
264
  // check it out ##
265
+ #h::log( $key );
266
 
267
  // drop the array by it's key name from the class property ##
268
+ unset( $_q_eud_exports[$key] );
269
 
270
  // update the saved data ##
271
+ \update_user_meta( \get_current_user_id(), 'q_eud_exports', $_q_eud_exports );
272
+
273
+ // set prop ##
274
+ $this->plugin->set( '_q_eud_exports', $_q_eud_exports );
275
 
276
+ // done ##
277
+ return true;
278
 
279
+ }
280
 
281
  }
package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "export-user-data",
3
- "version": "2.1.3",
4
  "description": "Q Plugins ~ Export User data and metadata",
5
  "author": "Q Studio",
6
  "homepage": "https://qstudio.us",
1
  {
2
  "name": "export-user-data",
3
+ "version": "2.2.1",
4
  "description": "Q Plugins ~ Export User data and metadata",
5
  "author": "Q Studio",
6
  "homepage": "https://qstudio.us",
plugin.php ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace q\eud;
4
+
5
+ // import classes ##
6
+ use q\eud;
7
+ use q\eud\plugin as plugin;
8
+ use q\eud\core\helper as h;
9
+
10
+ // If this file is called directly, Bulk!
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ return;
13
+ }
14
+
15
+ /*
16
+ * Main Plugin Class
17
+ */
18
+ final class plugin {
19
+
20
+ /**
21
+ * Instance
22
+ *
23
+ * @var Object $instance
24
+ */
25
+ private static $instance;
26
+
27
+ public static
28
+
29
+ // current tag ##
30
+ $_version = '2.2.1',
31
+
32
+ // debugging control ##
33
+ $_debug = \WP_DEBUG
34
+
35
+ ;
36
+
37
+ /**
38
+ * Props
39
+ *
40
+ * @var $props
41
+ */
42
+ private
43
+
44
+ $_q_eud_exports = '', // export settings ##
45
+ $_usermeta_saved_fields = [],
46
+ $_bp_fields_saved_fields = [],
47
+ $_bp_fields_update_time_saved_fields = [],
48
+ $_role = '',
49
+ $_roles = '0',
50
+ $_user_fields = '1',
51
+ $_groups = '0',
52
+ $_start_date = '',
53
+ $_end_date = '',
54
+ $_limit_offset = '',
55
+ $_limit_total = '',
56
+ $_updated_since_date = '',
57
+ $_field_updated_since = '',
58
+ $_format = '',
59
+ $_bp_data_available = false,
60
+ $_allowed_tags = '',
61
+
62
+ // api ##
63
+ $_api_admin_fields = false
64
+
65
+ ;
66
+
67
+ /**
68
+ * Initiator
69
+ *
70
+ * @since 0.0.2
71
+ * @return Object
72
+ */
73
+ public static function get_instance() {
74
+
75
+ // object defined once --> singleton ##
76
+ if (
77
+ isset( self::$instance )
78
+ && NULL !== self::$instance
79
+ ){
80
+
81
+ return self::$instance;
82
+
83
+ }
84
+
85
+ // create an object, if null ##
86
+ self::$instance = new self;
87
+
88
+ // store instance in filter, for potential external access ##
89
+ \add_filter( __NAMESPACE__.'/instance', function() {
90
+
91
+ return self::$instance;
92
+
93
+ });
94
+
95
+ // return the object ##
96
+ return self::$instance;
97
+
98
+ }
99
+
100
+ /**
101
+ * Class constructor to define object props --> empty
102
+ *
103
+ * @since 0.0.1
104
+ * @return void
105
+ */
106
+ private function __construct() {
107
+
108
+ // empty ...
109
+
110
+ }
111
+
112
+ /**
113
+ * Get stored object property
114
+ *
115
+ * @todo Make this work with single props, not from an array
116
+ * @param $key string
117
+ * @since 0.0.2
118
+ * @return Mixed
119
+ */
120
+ public function get( string $key = null )
121
+ {
122
+
123
+ // check if key set ##
124
+ if( is_null( $key ) ){
125
+
126
+ // return instance ##
127
+ return self::get_instance();
128
+
129
+ }
130
+
131
+ // return if isset ##
132
+ return $this->{$key} ?? false ;
133
+
134
+ }
135
+
136
+ /**
137
+ * Set stored object properties
138
+ *
139
+ * @todo Make this work with single props, not from an array
140
+ * @param $key string
141
+ * @param $value Mixed
142
+ * @since 0.0.2
143
+ * @return Mixed
144
+ */
145
+ public function set( string $key = null, $value = null )
146
+ {
147
+
148
+ // sanity ##
149
+ if(
150
+ is_null( $key )
151
+ ){
152
+
153
+ return false;
154
+
155
+ }
156
+
157
+ // w__log( 'prop->set: '.$key.' -> '.$value );
158
+
159
+ // set new value ##
160
+ return $this->{$key} = $value;
161
+
162
+ }
163
+
164
+ /**
165
+ * Load Text Domain for translations
166
+ *
167
+ * @since 0.0.1
168
+ * @return Void
169
+ */
170
+ public function load_plugin_textdomain(){
171
+
172
+ // The "plugin_locale" filter is also used in load_plugin_textdomain()
173
+ $locale = apply_filters( 'plugin_locale', \get_locale(), 'export-user-data' );
174
+
175
+ // try from global WP location first ##
176
+ \load_textdomain( 'export-user-data', WP_LANG_DIR.'/plugins/export-user-data-'.$locale.'.mo' );
177
+
178
+ // try from plugin last ##
179
+ \load_plugin_textdomain( 'export-user-data', FALSE, \plugin_dir_path( __FILE__ ).'library/languages/' );
180
+
181
+ }
182
+
183
+ /**
184
+ * Plugin activation
185
+ *
186
+ * @since 0.0.1
187
+ * @return void
188
+ */
189
+ public static function activation_hook(){
190
+
191
+ // check user caps ##
192
+ if ( ! \current_user_can( 'activate_plugins' ) ) {
193
+
194
+ return;
195
+
196
+ }
197
+
198
+ $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
199
+ \check_admin_referer( "activate-plugin_{$plugin}" );
200
+
201
+ // store data about the current plugin state at activation point ##
202
+ $config = [
203
+ 'configured' => true ,
204
+ 'version' => self::$_version ,
205
+ 'wp' => \get_bloginfo( 'version' ) ?? null ,
206
+ 'timestamp' => time(),
207
+ ];
208
+
209
+ // activation running, so update configuration flag ##
210
+ \update_option( 'plugin_export_user_data', $config, true );
211
+
212
+ }
213
+
214
+ /**
215
+ * Plugin deactivation
216
+ *
217
+ * @since 0.0.1
218
+ * @return void
219
+ */
220
+ public static function deactivation_hook(){
221
+
222
+ // Log::write( 'Plugin De-activated..' );
223
+
224
+ // check user caps ##
225
+ if ( ! \current_user_can( 'activate_plugins' ) ) {
226
+
227
+ return;
228
+
229
+ }
230
+
231
+ $plugin = isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : '';
232
+ \check_admin_referer( "deactivate-plugin_{$plugin}" );
233
+
234
+ // de-configure plugin ##
235
+ \delete_option('plugin_export_user_data');
236
+
237
+ // clear rewrite rules ##
238
+ // \flush_rewrite_rules();
239
+
240
+ }
241
+
242
+ /**
243
+ * We want the debugging to be controlled in global and local steps
244
+ * If Q debug is true -- all debugging is true
245
+ * else follow settings in Q, or this plugin $debug variable
246
+ */
247
+ public function debug(){
248
+
249
+ // define debug ##
250
+ $this->_debug =
251
+ (
252
+ class_exists( 'Q' )
253
+ && true === \Q::$debug
254
+ ) ?
255
+ true :
256
+ $this->_debug;
257
+
258
+ // test ##
259
+ // w__log( 'Q exists: '.json_encode( class_exists( 'Q' ) ) );
260
+ // w__log( 'Q debug: '.json_encode( \Q::$debug ) );
261
+ // w__log( json_encode( self::$debug ) );
262
+
263
+ return $this->_debug;
264
+
265
+ }
266
+
267
+ /**
268
+ * Get Plugin URL
269
+ *
270
+ * @since 0.1
271
+ * @param string $path Path to plugin directory
272
+ * @return string Absoulte URL to plugin directory
273
+ */
274
+ public static function get_plugin_url( $path = '' ){
275
+
276
+ return \plugins_url( $path, __FILE__ );
277
+
278
+ }
279
+
280
+ /**
281
+ * Get Plugin Path
282
+ *
283
+ * @since 0.1
284
+ * @param string $path Path to plugin directory
285
+ * @return string Absoulte URL to plugin directory
286
+ */
287
+ public static function get_plugin_path( $path = '' ){
288
+
289
+ return \plugin_dir_path( __FILE__ ).$path;
290
+
291
+ }
292
+
293
+ }
readme.md CHANGED
@@ -4,8 +4,8 @@
4
  **Tags:** users, export, usermeta, excel
5
  **Requires PHP:** 6.0
6
  **Requires at least:** 5.0
7
- **Tested up to:** 5.5
8
- **Stable tag:** 2.1.3
9
  **License:** GPLv2
10
 
11
  Export users data and metadata to a csv or Excel file
4
  **Tags:** users, export, usermeta, excel
5
  **Requires PHP:** 6.0
6
  **Requires at least:** 5.0
7
+ **Tested up to:** 5.6
8
+ **Stable tag:** 2.2.1
9
  **License:** GPLv2
10
 
11
  Export users data and metadata to a csv or Excel file
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Export User Data ===
2
  Contributors: qlstudio
3
  Tags: users, export, usermeta, excel
4
- Requires PHP: 6.0
5
  Requires at least: 4.8
6
- Tested up to: 5.5
7
- Stable tag: 2.1.3
8
  License: GPLv2
9
 
10
  Export users data and metadata to a csv or Excel file
1
  === Export User Data ===
2
  Contributors: qlstudio
3
  Tags: users, export, usermeta, excel
4
+ Requires PHP: 7.0
5
  Requires at least: 4.8
6
+ Tested up to: 5.6
7
+ Stable tag: 2.2.0
8
  License: GPLv2
9
 
10
  Export users data and metadata to a csv or Excel file