PluginProbe
My WP Customize Admin/Frontend / trunk
My WP Customize Admin/Frontend vtrunk
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / developer / class.developer.php

class.developer.php in My WP Customize Admin/Frontend trunk, at developer/class.developer.php

412 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( ! class_exists( 'MywpDeveloper' ) ) :
8
9 final class MywpDeveloper {
10
11 public static function is_debug() {
12
13 $is_debug = false;
14
15 return apply_filters( 'mywp_is_debug' , $is_debug );
16
17 }
18
19 public static function is_debug_item( $debug_item = false ) {
20
21 if( empty( $debug_item ) ) {
22
23 return false;
24
25 }
26
27 if( ! is_string( $debug_item ) ) {
28
29 return false;
30
31 }
32
33 if( ! class_exists( 'MywpControllerModuleDebugGeneral' ) ) {
34
35 return true;
36
37 }
38
39 $setting_data = MywpControllerModuleDebugGeneral::get_setting_data();
40
41 $debug_items = array(
42 'mywp_cache',
43 'debug_request',
44 'debug_time',
45 'debug_action',
46 'debug_debugtrace',
47 );
48
49 if( ! in_array( $debug_item , $debug_items , true ) ) {
50
51 return false;
52
53 }
54
55 $is_debug_item = false;
56
57 if( isset( $setting_data[ $debug_item ] ) ) {
58
59 $is_debug_item = $setting_data[ $debug_item ];
60
61 }
62
63 $is_debug_item = apply_filters( "mywp_is_debug_item_{$debug_item}" , $is_debug_item );
64 $is_debug_item = apply_filters( 'mywp_is_debug_item' , $is_debug_item , $debug_item );
65
66 if( ! $is_debug_item ) {
67
68 return false;
69
70 }
71
72 return true;
73
74 }
75
76 public static function get_debug_types() {
77
78 $debug_types = array();
79
80 return apply_filters( 'mywp_debug_types' , $debug_types );
81
82 }
83
84 public static function get_debug_renders() {
85
86 $pre_debug_renders = apply_filters( 'mywp_debug_renders' , array() );
87
88 if( empty( $pre_debug_renders ) ) {
89
90 return false;
91
92 }
93
94 $default = array(
95 'debug_type' => 'custom',
96 'title' => '',
97 );
98
99 $debug_renders = array();
100
101 foreach( $pre_debug_renders as $render_id => $render ) {
102
103 $debug_renders[ $render_id ] = wp_parse_args( $render , $default );
104
105 }
106
107 return $debug_renders;
108
109 }
110
111 public static function debug( $include_debug_modules = array() ) {
112
113 do_action( 'mywp_developer_debug' , $include_debug_modules );
114
115 echo "\n\n ----- mywp_developer_debug ----- \n\n";
116
117 }
118
119 public static function debug_die( $include_debug_modules = array() ) {
120
121 self::debug( $include_debug_modules );
122
123 die();
124
125 }
126
127 public static function debug_action( $action = false ) {
128
129 if( $action === false ) {
130
131 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$action' );
132
133 MywpHelper::error_not_found_message( '$action' , $called_text );
134
135 return false;
136
137 }
138
139 $action = strip_tags( $action );
140
141 echo esc_html( sprintf( 'debug_action = %s' , $action ) );
142 echo "\n";
143
144 echo esc_html( sprintf( 'has_action = %s' , has_action( $action ) ) );
145 echo "\n";
146
147 echo esc_html( sprintf( 'did_action = %s' , did_action( $action ) ) );
148 echo "\n";
149
150 echo 'actions = ' . "\n";
151
152 $filter_to_func = self::get_filter_to_func( $action );
153
154 if( ! empty( $filter_to_func ) ) {
155
156 foreach( $filter_to_func as $func ) {
157
158 echo esc_html( sprintf( ' (%d) %s' , $func['priority'] , $func['print_format'] ) );
159 echo "\n";
160
161 }
162
163 }
164
165 echo "\n\n";
166
167 }
168
169 public static function debug_filter( $filter = false ) {
170
171 if( $filter === false ) {
172
173 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$filter' );
174
175 MywpHelper::error_not_found_message( '$filter' , $called_text );
176
177 return false;
178
179 }
180
181 $filter = strip_tags( $filter );
182
183 echo esc_html( sprintf( 'debug_filter = %s' , $filter ) );
184 echo "\n";
185
186 echo esc_html( sprintf( 'has_filter = %s' , has_filter( $filter ) ) );
187 echo "\n";
188
189 echo 'filters = ' . "\n";
190
191 $filter_to_func = self::get_filter_to_func( $filter );
192
193 if( ! empty( $filter_to_func ) ) {
194
195 foreach( $filter_to_func as $func ) {
196
197 echo esc_html( sprintf( ' (%d) %s' , $func['priority'] , $func['print_format'] ) );
198 echo "\n";
199
200 }
201
202 }
203
204 echo "\n\n";
205
206 }
207
208 public static function get_filter_to_func( $filter_name = false ) {
209
210 global $wp_filter;
211
212 if( empty( $filter_name ) ) {
213
214 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$filter_name' );
215
216 MywpHelper::error_not_found_message( '$filter_name' , $called_text );
217
218 return false;
219
220 }
221
222 $wp_filters = $wp_filter;
223
224 if( empty( $wp_filters[ $filter_name ] ) ) {
225
226 return false;
227
228 }
229
230 $filter_to_func = array();
231
232 $defaults = array(
233 'priority' => false,
234 'function' => false,
235 'class' => false,
236 'static' => false,
237 'print_format' => false,
238 );
239
240 foreach( $wp_filters[ $filter_name ] as $priority => $filters ) {
241
242 foreach( $filters as $filter_func_name => $filter_array ) {
243
244 if( is_null( $filter_array['function'] ) ) {
245
246 continue;
247
248 }
249
250 $filter_function = $defaults;
251
252 $filter_function['priority'] = $priority;
253
254 $print_format = '';
255
256 if( is_array( $filter_array['function'] ) ) {
257
258 $filter_function['function'] = $filter_array['function'][1];
259
260 if( is_object( $filter_array['function'][0] ) ) {
261
262 $filter_function['class'] = get_class( $filter_array['function'][0] );
263 $print_format = sprintf( '[Class / Object] %s -> %s()' , $filter_function['class'] , $filter_function['function'] );
264
265 } else {
266
267 $filter_function['class'] = $filter_array['function'][0];
268 $filter_function['static'] = 1;
269 $print_format = sprintf( '[Class / Object] %s :: %s()' , $filter_function['class'] , $filter_function['function'] );
270
271 }
272
273 } elseif( is_object( $filter_array['function'] ) ) {
274
275 $filter_function['class'] = get_class( $filter_array['function'] );
276 $print_format = sprintf( '[Class / Object] %s' , print_r( $filter_array['function'] , true ) );
277
278 } else {
279
280 $filter_function['function'] = $filter_array['function'];
281 $print_format = sprintf( '%s()' , $filter_function['function'] );
282
283 }
284
285 $filter_function['print_format'] = $print_format;
286
287 $filter_to_func[] = $filter_function;
288
289 }
290
291 }
292
293 return $filter_to_func;
294
295 }
296
297 public static function get_current_filter() {
298
299 $filter = current_filter();
300
301 if( empty( $filter ) ) {
302
303 $called_text = sprintf( '%s::%s()' , __CLASS__ );
304
305 MywpHelper::error_not_found_message( 'filter' , $called_text );
306
307 return false;
308
309 }
310
311 return $filter;
312
313 }
314
315 public static function exists_function( $functions = false ) {
316
317 if( empty( $functions ) ) {
318
319 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$functions' );
320
321 MywpHelper::error_not_found_message( '$functions' , $called_text );
322
323 return false;
324
325 }
326
327 if( is_array( $functions ) ) {
328
329 foreach( $functions as $function_name ) {
330
331 self::exists_function( $function_name );
332
333 }
334
335 } else {
336
337 $exists = false;
338
339 if( function_exists( $functions ) ) {
340
341 $exists = true;
342
343 }
344
345 echo esc_html( sprintf( '%s: %s' , $functions , $exists ) );
346 echo "\n";
347
348 }
349
350 }
351
352 public static function exists_define( $defines = false ) {
353
354 if( empty( $defines ) ) {
355
356 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$defines' );
357
358 MywpHelper::error_not_found_message( '$defines' , $called_text );
359
360 return false;
361
362 }
363
364 if( is_array( $defines ) ) {
365
366 foreach( $defines as $define_name ) {
367
368 self::exists_define( $define_name );
369
370 }
371
372 } else {
373
374 $exists = false;
375
376 if( defined( $defines ) ) {
377
378 $exists = true;
379
380 }
381
382 echo esc_html( sprintf( '%s: %s' , $defines , $exists ) );
383 echo "\n";
384
385 }
386
387 }
388
389 public static function get_process() {
390
391 $load_avg = false;
392
393 if( function_exists( 'sys_getloadavg' ) ) {
394
395 $sys_getloadavg = sys_getloadavg();
396
397 if( isset( $sys_getloadavg[0] ) ) {
398
399 $load_avg = $sys_getloadavg[0];
400
401 }
402
403 }
404
405 return array( 'microtime' => microtime( true ) , 'memory_get_usage' => memory_get_usage() , 'load_avg' => $load_avg );
406
407 }
408
409 }
410
411 endif;
412