This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kint-debugger.php
152 lines (138 loc) · 3.65 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
150
151
152
<?php
/**
* Plugin Name: Kint Debugger
* Plugin URI: https://strongplugins.com/
* Description: Dump variables and traces in an organized and interactive display. Works with Debug Bar.
* Version: 1.2
* Author: Brian Fegter, Chris Dillon
* Author URI: https://strongplugins.com
* Requires: 2.5 or higher
* License: Dual license GPL-2.0+ & MIT (Kint is licensed MIT)
*
* Copyright 2012-2019 Brian Fegter (brian@fegter.com), Chris Wallace (chris@liftux.com), Chris Dillon (chris@strongwp.com)
*
* 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
*/
/**
* Load Kint after this plugin to ensure our modified d() function override.
*
* @since 1.1
*/
function kint_debug_load_kint() {
require 'vendor/kint/Kint.class.php';
}
add_action( 'plugins_loaded', 'kint_debug_load_kint' );
/**
* 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 ) {
$_ = array( $var );
echo call_user_func_array( 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 ( ! Kint::enabled() ) {
return '';
}
$_ = func_get_args();
if ( class_exists( 'Debug_Bar' ) ) {
ob_start( 'kint_debug_ob' );
echo call_user_func_array( array( 'Kint', 'dump' ), $_ );
ob_end_flush();
} else {
return call_user_func_array( 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
*/
function kint_debug_bar_panel( $panels ) {
if ( ! class_exists( 'Kint_Debug_Bar_Panel' ) ) {
require_once 'includes/class-kint-debug-bar-panel.php';
}
$panels[] = new Kint_Debug_Bar_Panel;
return $panels;
}
add_filter( 'debug_bar_panels', 'kint_debug_bar_panel' );