This is a second (and i promise the last) article i wanted to move from my old blog which i will be no longer using.
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 to Symfony has since version 1.0. After Googling WordPress debug plugin it turned out there was no such solution so i decided to develop 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 the 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 got the job done, is lightweight and unobtrusive 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, the second click hides expanded information.
Globals
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) every time i want to see if variables from the form were sent correctly or at all.
BTW. Syntax highlighting is done using the 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
Profiler is the one that is using a dirty workaround, but let me say in my defense 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 to the following single line of code:
apply_filters("debug", "My new checkpoint"); |
Obviously, the second argument should be a name of the 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 that 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 explenetionary, 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 the information you will find in profiler, these are: time passed since profiler was started and total memory WordPress was using when the checkpoint was reached.
SQL
This is probably the most useful feature of all. In SQL tab are listed all executed queries along with time (in milliseconds) it took to execute each of them.
Well actually, not all queries are listed. If the query was not executed using the 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 limitation in mind, however, it’s very uncommon to happen and probably might happen only if you are using a plugin created by beginner WordPress developer.
Errors
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 in 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 a number of times an error occurred.
Few final words
Currently, there is no configuration for the plugin you must use it as is or modify the 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.
Comments (1)
Keep up the great work.