-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdebug-hooks.php
More file actions
51 lines (46 loc) · 1.38 KB
/
debug-hooks.php
File metadata and controls
51 lines (46 loc) · 1.38 KB
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
<?php
/*
* Plugin Name: Log all triggered hooks (DBG)
* Plugin URI: https://github.com/szepeviktor/wordpress-website-lifecycle
*/
add_action(
'all',
static function () {
$skip_hooks = [
'gettext',
'gettext_default',
'gettext_with_context',
'gettext_with_context_default'
];
$log_path = WP_CONTENT_DIR.'/debug-hooks.log';
$args = func_get_args();
$hook_name = $args[0];
$value = isset($args[1]) ? $args[1] : null;
if (in_array($hook_name, $skip_hooks, true)) {
return;
}
file_put_contents(
$log_path,
sprintf(
'%.2f %s@%.4f %s %s %s =%s%c',
microtime(true),
php_sapi_name() === 'cli' ? 'CLI' : $_SERVER['REMOTE_ADDR'],
$_SERVER['REQUEST_TIME_FLOAT'],
$_SERVER['REQUEST_METHOD'],
$_SERVER['REQUEST_URI'],
$hook_name,
is_string($value)
? $value
: '<'.(is_object($value)
? get_class($value)
: (is_bool($value)
? ($value ? 'TRUE' : 'FALSE')
: gettype($value))).'>',
10
),
FILE_APPEND | LOCK_EX
);
},
10,
0
);