-
Notifications
You must be signed in to change notification settings - Fork 11
/
plugin.php
277 lines (208 loc) · 5.64 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
namespace q\eud;
// import classes ##
use q\eud;
use q\eud\plugin as plugin;
use q\eud\core\helper as h;
// If this file is called directly, Bulk!
if ( ! defined( 'ABSPATH' ) ) {
return;
}
/*
* Main Plugin Class
*/
final class plugin {
/**
* Instance
*
* @var Object $_instance
*/
private static $_instance;
public static
// current tag ##
$_version = '2.3.0',
// debugging control ##
$_debug = \WP_DEBUG
;
/**
* Props
*
* @var $props
*/
private
$_q_eud_exports = '', // export settings ##
$_usermeta_saved_fields = [],
$_role = '',
$_roles = '0',
$_user_fields = '1',
$_groups = '0',
$_start_date = '',
$_end_date = '',
$_limit_offset = '',
$_limit_total = '',
$_updated_since_date = '',
$_format = '',
$_allowed_tags = '',
// api ##
$_api_admin_fields = false
;
/**
* Initiator
*
* @since 0.0.2
* @return Object
*/
public static function get_instance() {
// object defined once --> singleton ##
if (
isset( self::$_instance )
&& NULL !== self::$_instance
){
return self::$_instance;
}
// create an object, if null ##
self::$_instance = new self;
// store instance in filter, for potential external access ##
\add_filter( __NAMESPACE__.'/instance', function() {
return self::$_instance;
});
// return the object ##
return self::$_instance;
}
/**
* Class constructor to define object props --> empty
*
* @since 0.0.1
* @return void
*/
private function __construct() {
// empty ...
}
/**
* Get stored object property
*
* @todo Make this work with single props, not from an array
* @param $key string
* @since 0.0.2
* @return Mixed
*/
public function get( string $key = null )
{
// check if key set ##
if( is_null( $key ) ){
// return instance ##
return self::get_instance();
}
// return if isset ##
return $this->{$key} ?? false ;
}
/**
* Set stored object properties
*
* @todo Make this work with single props, not from an array
* @param $key string
* @param $value Mixed
* @since 0.0.2
* @return Mixed
*/
public function set( string $key = null, $value = null )
{
// sanity ##
if(
is_null( $key )
){
return false;
}
// set new value ##
return $this->{$key} = $value;
}
/**
* Load Text Domain for translations
*
* @since 0.0.1
* @return Void
*/
public function load_plugin_textdomain(){
// The "plugin_locale" filter is also used in load_plugin_textdomain()
$locale = apply_filters( 'plugin_locale', \get_locale(), 'export-user-data' );
// try from global WP location first ##
\load_textdomain( 'export-user-data', WP_LANG_DIR.'/plugins/export-user-data-'.$locale.'.mo' );
// try from plugin last ##
\load_plugin_textdomain( 'export-user-data', FALSE, \plugin_dir_path( __FILE__ ).'library/languages/' );
}
/**
* Plugin activation
*
* @since 0.0.1
* @return void
*/
public static function activation_hook(){
// check user caps ##
if ( ! \current_user_can( 'activate_plugins' ) ) {
return;
}
$_plugin = isset( $_REQUEST['plugin'] ) ? \sanitize_text_field( $_REQUEST['plugin'] ) : '';
\check_admin_referer( "activate-plugin_{$_plugin}" );
// store data about the current plugin state at activation point ##
$_config = [
'configured' => true ,
'version' => self::$_version ,
'wp' => \get_bloginfo( 'version' ) ?? null ,
'timestamp' => time(),
];
// activation running, so update configuration flag ##
\update_option( 'plugin_export_user_data', $_config, true );
}
/**
* Plugin deactivation
*
* @since 0.0.1
* @return void
*/
public static function deactivation_hook(){
// check user caps ##
if ( ! \current_user_can( 'activate_plugins' ) ) {
return;
}
$_plugin = isset( $_REQUEST['plugin'] ) ? \sanitize_text_field($_REQUEST['plugin'] ) : '';
\check_admin_referer( "deactivate-plugin_{$_plugin}" );
// de-configure plugin ##
\delete_option('plugin_export_user_data');
}
/**
* We want the debugging to be controlled in global and local steps
* If Q debug is true -- all debugging is true
* else follow settings in Q, or this plugin $debug variable
*/
public function debug(){
// define debug ##
$this->_debug =
(
class_exists( 'Q' )
&& true === \Q::$debug
) ?
true :
$this->_debug;
return $this->_debug;
}
/**
* Get Plugin URL
*
* @since 0.1
* @param string $path Path to plugin directory
* @return string Absoulte URL to plugin directory
*/
public static function get_plugin_url( $path = '' ){
return \plugins_url( $path, __FILE__ );
}
/**
* Get Plugin Path
*
* @since 0.1
* @param string $path Path to plugin directory
* @return string Absoulte URL to plugin directory
*/
public static function get_plugin_path( $path = '' ){
return \plugin_dir_path( __FILE__ ).$path;
}
}