Using “Debug Bar”, “Debug Bar Action Hooks”, and “Kint Debugger” together

I needed to trace the execution of a WordPress plugin, so I installed several developer tools: "Developer", "Debug Bar", "Debug Bar Transients", "Debug Bar Action Hooks", and "Kint Debugger". I then tried to display a variable with Kint Debugger, but the attempt failed. The variable was used before Kint Debugger had loaded, so its d() function was not yet available.

Debug Bar Action Hooks, however, showed the hooks that ran before and after the code I wanted to inspect. I therefore created a new hook and placed the information I needed directly in its name:

do_action("KC level: $level", get_defined_vars());

The hook fired even though no callback was registered for it. Debug Bar Action Hooks still recorded the hook, allowing me to see the required information in the hook list. Spaces in the hook name did not cause a problem. The same technique also worked when I needed to display an entire array or object:

do_action("KC field: <pre>".print_r($field, true)."</pre>", get_defined_vars());

It was a useful debugging trick, so I am sharing it here.

Share this

This entry was posted in Blog, Hacks. Bookmark the permalink.

Leave a Reply