Here is something that WordPress developers might find very useful. Recently when working with symfony i figured out it would awesome to have debug bar in WordPress, similar like symfony has since version 1.0. After Googling WordPress debug plugin it turned out there was no such solution so i decided to developed one myself.
Here is why you will find it helpful:
- instantly inspect global variables (GET, POST, COOKIE, SERVER)
- debug both frontend and admin area
- executed MySQL queries and time it took to execute each query (useful for finding slow queries)
- profiler for measuring performance of your plugins and themes
- errors occurred when loading WordPress page
If you will decide to use the plugin please remember it’s not a perfect solution, it uses some workarounds, but it’s gets the job done, is lightweight and unobstrusive which i think is most important. Here is how it looks:
Basically the debug bar is attached to the top of the browser window. Using “Close Toolbar” you can close it if the plugin is bothering you, however on the next page refresh it will “popup” again until you disable the plugin. Other than “Close Toolbar” there are four other sections. Click on any of them to expand, second click hides expanded information.
As the name says, Globals contains information about global variables. I find it one of the most useful features since i do not have to add print_r($_POST) everytime i want see if variables from the form were sent correctly or at all.
BTW. Syntax highlighting is done using highlight.js library, it highlights 35+ languages and comes with a lot of color schemes i really recommend it if you are looking for syntax highlighting library.
Profiler is the one that is using a dirty work around, but let me say in my defence that i have a reason for this. Either way, first, let’s look at how to add new points to profiler to benchmark your code.
Another point is added with the following single line of code:
apply_filters("debug", "My new checkpoint");
Obviously, the second argument should be a name of function to execute, but it’s not. It’s simply a name/title that will be added to the profiler section.The reason i solved it this way is because i wanted to make something plugin-independent. If you disable BlackBox the code will still work so you do not have to worry about removing all the checkpoints from the code.
You probably noticed that by default there are three entries in the profiler. “Profiler Initiated” and “Profiler Stopped” are self explenationary, however “Profiler Noise” is not. “Profiler Noise” is the time that WordPress needs to execute hook, in other words if you measure the time between two checkpoints you need to keep in mind that you need to subs tract “noise” from it.
As for information you will find in profiler, these are: time passed since profiler was started and total memory WordPress was using when checkpoint was reached.
Well actually, not all queries are listed. If the query was not executed using WP_Query object you won’t find it in the list, also if it was executed before BlackBox plugin index.php file was loaded it won’t be on the list as well. Keep this limitations in mind, however it’s very uncommon to to happen and probably might happen only if you are using a plugin created by beginner WordPress developer.
By default WordPress hides all strict errors, notices and warnings (or even fatal errors), it’s great for production but not really helpful when developing a website or plugin. Therefore in Error tab all errors are listed, if the error is a warning then it’s listed on red, so you can easily notice more important problems.
Notice that each error is listed only once, if the same code is executed twice or more and it raises some kind of problem, then on the list of errors, next to the error type there will be listed number of times error occurred.
Few final words
Currently there is no configuration for the plugin you must use it as is, or modify source code to fit your needs. If you need will find it useful or horrible please let me know in comments what you think and how can i improve the plugin.