WordPress Hook Order

I’ve made a site that shows actions and filters executed during different WordPress requests.

Screenshot of hookorder.com

Why?

When I’m writing a plugin, I sometimes need to know not just what a hook does, but also when it runs in relation to other hooks. The official WordPress documentation has a list of common actions, but it’s out of date and far from complete. There have been other attempts to document the hook execution order, but those are also a few years old now and not comprehensive.

This is not entirely surprising. WordPress comes with hundreds of unique actions and filters, and some of them are called dozens of times per page. Manually collating and maintaining an ordered list of all hooks would require a huge amount of work. Fortunately, it’s possible to automate some of that work, which is what I’ve done for this project.

What is it?

HookOrder.com is a documentation/reference site that shows the execution order of all unique WordPress hooks that are fired on common pages. Notable features include:

  • Up to date with WordPress 6.1 (as of this writing).
  • Shows both actions and filters. You can hide filters if you’re only interested in actions.
  • Hook documentation in the sidebar.
  • Shows active callbacks, if any.
  • Shows hook arguments. The actual values will be different on each site, of course, but it can be handy to see some practical examples.

How does it work?

The hook lists are generated by setting up a basic WordPress site and logging every do_action(), apply_filters(), etc call that happens during a request.  A bunch of post-processing is necessary to normalize and format the results and make the database fast enough to be usable.

For anyone curious, here are some of the tools I used:

  • The all hook makes it possible to catch every action and filter. The hook itself appears to be undocumented, but see _wp_call_all_hook.
  • Puppeteer – to control headless Chrome.
  • WP-CLI – to install and configure WordPress, activate plugins, create or import sample data, and so on.
  • Theme Test Data – to fill out the site and hopefully make the results more realistic.
  • SQLite – for temporary log storage.
  • Hook documentation parser – to extract hook documentation from WordPress source code.
  • Miscellaneous Symfony Components.

 

Related posts :

One Response to “WordPress Hook Order”

  1. Mark Quigg says:

    Hi Janis,

    Wow, this a great! Thanks for creating this.

    Mark

Leave a Reply