In the previous two articles we looked at using the
$wp_actions to list the filters and actions that were fired on a page.
Having looked at how this can be done in code I wanted to finish off the series by taking look at a plugin that does the same job.
The Query Monitor Plugin
The Query Monitor Plugin is an excellent plugin that I would highly recommend installing if you want to do any sort of debugging on your site. In this article we’re only going to look at the functionality that lists the hooks on a page, but it does a lot of other things including
- Monitor database queries
- Providing debug information about URL rewriting
- Listing any PHP errors found on a site
- Providing information on what templates have been used to render the current page
- Monitoring API calls
- Keeping track of script and CSS files
How to View the Hooks Using the Plugin
Once you have installed the plugin and activated it, it will add a set of diagnostic information to the right hand of the admin toolbar, this information doubles up as a menu button, and clicking it reveals a drop-down menu, as shown below
Once the menu has appeared, click the “Hooks & Actions” option. The hooks will then be listed in the panel at the bottom of the screen.
As you can see from the screenshot below, the plugin lists the names of the hook’s tag, it’s priority and the function(s) linked to it. It is possible to expand the plugin description to show the line of code where the hooked function is defined.
The plugin also allows you filter the hooks it finds this, this can be done by keyword
or by component
I find this functionality useful for finding hooks linked to plugins, as you can see from the screenshot above the plugin gives you the option to only list filters that are linked to WooCommerce.
What Hooks Does the Plugin List?
By default the plugin only list actions that are fired during the current request, this means it does not show any actions that are registered but not fired, and it doesn’t show any filter hocks.
The plugin does provide an option to list these filters though, here’s a screen grab of the option being described in the plugins settings section
From the image above you can see that you’d need to add the following code to your site’s wp-config.php file in order to list the filters and non-fired actions
define( 'QM_SHOW_ALL_HOOKS', true );
Using the Query Monitor Plugin to Discover Hooks Linked to Functionality
Before we wrap things up I just wanted mention one other feature that was recently added to Query Monitor, which is the ability to list hooks linked to a particular area of functionality.
Situated on the plugin’s left hand side menu there are a number of “Hooks in Use” menu options, in the example image above you can see the plugin listing the hooks fired when processing the request. This functionality can be invaluable when you’re trying to work out why something happened, and it saves you having to search for the hook names used in the area you are investigating.
Hopefully this post will help you to add the Query Monitor plugin to your debugging toolkit
If you’d like to know more about how to track hooks without a plugin and the code that WordPress uses internally to store hook details, you could take a look at the first two articles in this series
As always, if you have any questions or queries about this post then please don’t hesitate to let me know in the comments.