This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kint-debugger.php
149 lines (136 loc) · 3.53 KB
/
kint-debugger.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
<?php
/**
* Plugin Name: Kint Debugger
* Plugin URI:
* Description: Simpe php dump ui/debugger
* Version: 1.0.0
* Author:
* Author URI:
* GitHub Plugin URI:
* Requires: 5.0
* License: Dual license GPL-2.0+ & MIT (Kint is licensed MIT)
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
add_action('plugins_loaded', function () {
require_once (__DIR__ . '/vendor/autoload.php');
});
/**
* Generic data dump.
*
* @since 1.1
*/
if (!function_exists('dump_this')) {
function dump_this($var, $inline = false)
{
/**
* Some hooks send WP objects which then get passed as $inline
* so check type too.
*/
if (true === $inline) {
$_ = [$var];
echo call_user_func_array(['Kint', 'dump'], $_);
} else {
d($var);
}
}
}
/**
* Helper functions.
*/
if (!function_exists('dump_wp_query')) {
function dump_wp_query($inline = false)
{
global $wp_query;
dump_this($wp_query, $inline);
}
}
if (!function_exists('dump_wp')) {
function dump_wp($inline = false)
{
global $wp;
dump_this($wp, $inline);
}
}
if (!function_exists('dump_post')) {
function dump_post($inline = false)
{
global $post;
dump_this($post, $inline);
}
}
/* Override can be prevented using config constant. */
if (!defined('KINT_TO_DEBUG_BAR') || KINT_TO_DEBUG_BAR) {
/* An mu-plugin can still override the function. */
if (!function_exists('d')) {
/**
* Alias of Kint::dump()
*
* This sends Kint output to Debug Bar if active.
*
* Can be prevented by declaring the function first in an mu-plugin
* (but not a theme due to WordPress load sequence).
*
* @return string
*/
function d()
{
/** @noinspection PhpUndefinedClassInspection */
if (!class_exists('Kint')) {
return;
}
$_ = func_get_args();
if (class_exists('Debug_Bar')) {
ob_start('kint_debug_ob');
echo call_user_func_array(['Kint', 'dump'], $_);
ob_end_flush();
} else {
return call_user_func_array(['Kint', 'dump'], $_);
}
return '';
}
}
}
/**
* Output buffer callback.
*
* @param $buffer
*
* @return string
*/
function kint_debug_ob($buffer)
{
global $kint_debug;
$kint_debug[] = $buffer;
if (class_exists('Debug_Bar')) {
return '';
}
return $buffer;
}
/**
* Add our Debug Bar panel.
*
* @param $panels
*
* @return array
*/
add_filter('debug_bar_panels', function($panels) {
if (!class_exists('Kint_Debug_Bar_Panel')) {
require_once __DIR__ . '/includes/class-kint-debug-bar-panel.php';
}
$panels[] = new Kint_Debug_Bar_Panel;
return $panels;
});