1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flynt\Features\ComponentLogServer; |
4
|
|
|
|
5
|
|
|
use Flynt; |
6
|
|
|
|
7
|
|
|
define(__NAMESPACE__ . '\NS', __NAMESPACE__ . '\\'); |
8
|
|
|
|
9
|
|
|
add_action('Flynt/afterRegisterFeatures', function () { |
10
|
|
|
$componentManager = Flynt\ComponentManager::getInstance(); |
11
|
|
|
$componentWhitelist = []; |
12
|
|
|
if (isset($_GET['component']) && !empty($_GET['component'])) { |
13
|
|
|
$componentWhitelist = explode(',', $_GET['component']); |
14
|
|
|
} |
15
|
|
|
if (count($componentWhitelist) === 0) { |
16
|
|
|
foreach ($componentManager->getAll() as $name => $path) { |
17
|
|
|
add_filter("Flynt/addComponentData?name={$name}", NS . 'addDebugInfo', 12, 3); |
18
|
|
|
} |
19
|
|
|
} else { |
20
|
|
|
foreach ($componentManager->getAll() as $name => $path) { |
21
|
|
|
if (in_array($name, $componentWhitelist)) { |
22
|
|
|
add_filter("Flynt/addComponentData?name={$name}", NS . 'addDebugInfo', 12, 3); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
}, 11); |
27
|
|
|
|
28
|
|
|
function addDebugInfo($data, $parentData, $config) |
29
|
|
|
{ |
30
|
|
|
if ((WP_ENV === 'development' || current_user_can('editor') || current_user_can('administrator')) && isset($_GET['log'])) { |
31
|
|
|
consoleDebug([ |
32
|
|
|
'component' => $config['name'], |
33
|
|
|
'config' => $config, |
34
|
|
|
'data' => $data, |
35
|
|
|
'parentData' => $parentData, |
36
|
|
|
]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $data; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function consoleDebug($data, $postpone = true) |
43
|
|
|
{ |
44
|
|
|
$type = gettype($data); |
|
|
|
|
45
|
|
|
$output = json_encode($data); |
46
|
|
|
$result = "<script>console.log({$output});</script>\n"; |
47
|
|
|
echoDebug($result, $postpone); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
function echoDebug($data, $postpone) |
51
|
|
|
{ |
52
|
|
|
if ($postpone) { |
53
|
|
|
add_action('wp_footer', function () use ($data) { |
54
|
|
|
echo $data; |
55
|
|
|
}, 30); |
56
|
|
|
} else { |
57
|
|
|
echo $data; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.