-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathair.php
336 lines (262 loc) · 8.12 KB
/
air.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
/*------------------------------------
* Theme: Air by studio.bio
* File: Template dev functions file
* Author: Joshua Michaels
* URI: https://studio.bio/themes/air
*------------------------------------
*/
/*
******************************
* GET CURRENT TEMPLATE *
******************************
*
* Pretty self-explanatory.
*
* To use, add this in your header:
* <?php echo '<!-- ' . get_current_template() . ' -->' ?>;
*
*
*/
add_filter( 'air_include', 'var_air_include', 1000 );
function var_air_include( $t ){
$GLOBALS['current_theme_template'] = basename($t);
return $t;
}
function get_current_template( $echo = false ) {
if( !isset( $GLOBALS['current_theme_template'] ) )
return false;
if( $echo )
echo $GLOBALS['current_theme_template'];
else
return $GLOBALS['current_theme_template'];
}
/**
* Debug Stuffs
*
* To see all of the hooks being called in your theme and where,
* I highly recommend checking out the Query Monitor plugin. It's
* great for tracking down issues in your code or errant plugins:
* https://wordpress.org/plugins/query-monitor/
*/
/*
*****************
* R-DEBUG *
*****************
*
* Debugger class for checking out hooks, filters, queries
* post info and more.
*
* You could install as a plugin as well.
* Grab the raw file here: https://gist.github.com/Rarst/1739714
*
* Uncomment the include for this file in functions.php, then call
* one of the helper functions below in your theme:
*
* R_Debug::list_live_hooks();
*
* Make sure to disable for live sites or you will have a lot of
* essplainin' to do.
*
*/
/**
* Class with static dump methods
*/
class R_Debug {
/**
* List basic performance stats
*
* @param bool $visible display or only include in source
*/
static function list_performance( $visible = false ) {
if ( defined( 'DOING_AJAX' ) ) {
return;
}
$stat = sprintf(
'%d queries in %s seconds, using %.2fMB memory',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo $visible ? $stat : "<!-- {$stat} -->";
}
/**
* List defined constants
*
* @param bool|string $filter limit to matching names or values
*/
static function list_constants( $filter = false ) {
$constants = get_defined_constants();
if ( false !== $filter ) {
$temp = array();
foreach ( $constants as $key => $constant ) {
if ( false !== stripos( $key, $filter ) || false !== stripos( $constant, $filter ) ) {
$temp[ $key ] = $constant;
}
}
$constants = $temp;
}
ksort( $constants );
self::dump( $constants );
}
/**
* Concatenate print_r of all input and echo in pre tags.
*/
static function dump() {
$output = '';
foreach ( func_get_args() as $arg ) {
$output .= print_r( $arg, true );
}
echo '<pre>' . $output . '</pre>';
}
/**
* List cron entries with time remaining till next run
*/
static function list_cron() {
$cron = _get_cron_array();
echo '<pre>';
$offset = get_option( 'gmt_offset' ) * 3600;
foreach ( $cron as $time => $entry ) {
$when = '<strong>In ' . human_time_diff( $time ) . '</strong> (' . $time . ' ' . date_i18n( DATE_RSS, $time + $offset ) . ')';
echo "<br />>>>>>\t{$when}<br />";
foreach ( array_keys( $entry ) as $function ) {
echo "\t{$function}<br />";
self::list_hooks( $function );
}
}
echo '</pre>';
}
/**
* List hooks as currently defined
*
* @param bool|string $filter limit to matching names
*/
static function list_hooks( $filter = false ) {
global $wp_filter;
$skip_filter = empty( $filter );
$hooks = $wp_filter;
ksort( $hooks );
foreach ( $hooks as $tag => $hook ) {
if ( $skip_filter || false !== strpos( $tag, $filter ) ) {
self::dump_hook( $tag, $hook );
}
}
}
/**
* Output hook info
*
* @param string $tag hook name
* @param array $hook hook data
*/
static function dump_hook( $tag, $hook ) {
// ksort( $hook ); // PHP 7.X freaks out with this so commented out (JM)
echo "<pre>>>>>>\t<strong>{$tag}</strong><br />";
foreach ( $hook as $priority => $functions ) {
echo $priority;
foreach ( $functions as $function ) {
echo "\t";
$callback = $function['function'];
if ( is_string( $callback ) ) {
echo $callback;
} elseif ( is_a( $callback, 'Closure' ) ) {
$closure = new ReflectionFunction( $callback );
echo 'closure from ' . $closure->getFileName() . '::' . $closure->getStartLine();
} elseif ( is_string( $callback[0] ) ) { // static method call
echo $callback[0] . '::' . $callback[1];
} elseif ( is_object( $callback[0] ) ) {
echo get_class( $callback[0] ) . '->' . $callback[1];
}
echo ( 1 == $function['accepted_args'] ) ? '<br />' : " ({$function['accepted_args']}) <br />";
}
}
echo '</pre>';
}
/**
* Enable live listing of hooks as they run
*
* @param bool|string $hook limit to matching names
*/
static function list_live_hooks( $hook = false ) {
if ( false === $hook ) {
$hook = 'all';
}
add_action( $hook, array( __CLASS__, 'list_hook_details' ), - 1 );
}
/**
* Handler for live hooks output
*
* @param mixed $input
*
* @return mixed
*/
static function list_hook_details( $input = null ) {
global $wp_filter;
$tag = current_filter();
if ( isset( $wp_filter[ $tag ] ) ) {
self::dump_hook( $tag, $wp_filter[ $tag ] );
}
return $input;
}
/**
* List active plugins
*/
static function list_plugins() {
self::dump( get_option( 'active_plugins' ) );
}
/**
* List post's fields, custom fields, and terms
*
* @param int $post_id
*/
static function list_post( $post_id = null ) {
if ( empty( $post_id ) ) {
$post_id = get_the_ID();
}
self::dump(
get_post( $post_id ),
get_post_custom( $post_id ),
wp_get_post_terms( $post_id, get_post_taxonomies( $post_id ) )
);
}
/**
* List performed MySQL queries
*/
static function list_queries() {
global $wpdb;
if ( ! defined( 'SAVEQUERIES' ) || ! SAVEQUERIES ) {
trigger_error( 'SAVEQUERIES needs to be defined', E_USER_NOTICE );
return;
}
echo '<pre>';
foreach ( $wpdb->queries as $query ) {
list( $request, $duration, $backtrace ) = $query;
$duration = sprintf( '%f', $duration );
$backtrace = explode( ',', $backtrace );
$backtrace = trim( array_pop( $backtrace ) );
if ( 'get_option' == $backtrace ) {
preg_match_all( '/\option_name.*?=.*?\'(.+?)\'/', $request, $matches );
$backtrace .= "({$matches[1][0]})";
}
echo "<br /><code>{$request}</code><br />{$backtrace} in {$duration}s<br />";
}
echo '<br /></pre>';
}
/**
* Run EXPLAIN on provided MySQL query or last query performed.
*
* @param string $query
*/
static function explain_query( $query = '' ) {
/** @var wpdb $wpdb */
global $wpdb;
if ( empty( $query ) ) {
$query = $wpdb->last_query;
}
self::dump(
$query,
$wpdb->get_results( 'EXPLAIN EXTENDED ' . $query ),
$wpdb->get_results( 'SHOW WARNINGS' )
);
}
}
?>