In order to do a few clever things, Query Monitor loads earlier than you ever thought humanly possible (almost). It does this by symlinking a custom
WP_CONTENT_DIR. This file (when present) gets included before the database driver is loaded, meaning this portion of Query Monitor loads before WordPress even engages its brain.
In this file is Query Monitor’s extension to the
- Allows us to log all database queries (including ones that happen before plugins are loaded)
- Logs the full stack trace for each query, which allows us to determine the component that’s responsible for the query
- Logs the query result, which allows us to display the affected rows or error message if applicable
- Logs various PHP configurations before anything has loaded, which allows us to display a message if these get altered at runtime by a plugin or theme
This is totally fucking clever and very well done considering that it’s not even using a profiler. Bravo, sir!