How to debug WordPress database queries, developers special

When you are a developer you have to take care of many details so that everything works correctly. It is common for a developer to need to debug WordPress database queries, php errors, hooks and actions, API calls, etc. etc.

For this they must have tools to help them in these complex tasks and we are in luck because there is already a plugin tool that covers these needs and much more and that is available to everyone, whether they are developers or not.

Query Monitor para WordPress

Query Monitor

Query Monitor is a free plugin available in the official WordPress repository created by John Blackbourn that is designed and created as a fundamental tool for developers and non-developers because its visual interface as a plugin helps us see what is wrong and what can be improved in our WordPress, for example debugging database queries, block editing blocks, queued scripts and style sheets, HTTP API calls and more.

It includes some advanced features such as debugging Ajax calls, REST API calls, and user capability checks.

It allows you to quickly detect which plugins, themes or low-performance functions are those that affect your WordPress and this is honestly fantastic when we see and notice that our WordPress is not performing as it should, overcrowding of plugins is very common, but we can also have Few plugins and our WordPress is not performing as it should, because if a plugin is poorly developed it can take all the resource consumption of our server and with Query Monitor we can find out.

Query Monitor focuses heavily on presenting your information in a useful way, for example by displaying queries added to the database grouped by the plugins, themes, or functions that are responsible for them. Adds an admin toolbar menu that shows an overview of the current page, with full debugging information displayed in panels once a menu item is selected.

These are some of the Query Monitor functions:

  • Queries to the database, including notifications of slow, duplicate or erroneous queries. It allows filtering by query type (SELECT, UPDATE, DELETE, etc), responsible component (plugin, theme, WordPress core), and calling function, and provides separate aggregated views for each.
  • The file name of the template, the full hierarchy of the template, and the names of all parts of the template that were uploaded or not.
  • PHP errors are presented together with their responsible component and call stack, and a visible warning in the administrator toolbar.
  • Blocks and associated properties in post content when using WordPress 5.0+ or ​​the Gutenberg plugin.
  • Matching rewrite rules, associated query strings, and query vars.
  • Queued scripts and stylesheets, along with their dependencies and broken dependency alerts.
  • Language settings and loaded translation files (MO files) for each text.
  • HTTP API requests, with response code, responsible component and time spent, with alerts of failed or erroneous requests.
  • Environment information, including detailed information about PHP, the database, WordPress, and the web server.

By default, the Query Monitor out put is only shown to Administrators in single-site installations, and to Super Administrators in multi-site installations.

It does not persistently store any of the data it collects. It does not send data to any third party, nor does it include third party resources.