Hooktrail

Description

When something on a WordPress site behaves strangely, the question is usually “which plugin is doing this?”. Hooktrail answers it for any page you open.

Switch it on for yourself, open a page, and choose Hooktrail in the admin bar. A panel opens at the bottom of the page.

Timeline

Every action and filter that fired, in order, grouped under WordPress’s loading stages. Each row shows when the hook first fired, how many times it ran, how long its first run took, and coloured tags for every plugin or theme with a callback on it. Click a row to see each callback, its priority and the exact file and line where it is defined.

Flame

A chart of hook run times: each bar is a hook’s first run, hooks fired inside it sit below it, and the slowest hooks are listed at the top. Click any bar to jump to that hook.

By plugin and Shared hooks

Every plugin, theme and WordPress core with the hooks it used on this page, and the hooks where more than one plugin or theme attaches a callback, listed in the order they run.

Trace

Pick a filter such as the_content or document_title_parts, reload, and see its value before and after every single callback, with the changed text highlighted. You see exactly which plugin changed what.

Queries

Every database query, with the hook that was running and the plugin or theme file, line and function that made it. Queries are totalled per plugin and repeated queries are grouped.

Assets

The theme template used for the page, the theme files loaded, and every script and stylesheet printed, with its size and the plugin, theme or external host that added it.

Issues

A short list of things worth a closer look: PHP warnings and notices with the plugin and hook that caused them, plugins on the same filter at the same priority, callbacks at extreme priorities, callbacks removed while the page loaded, repeated queries and slow hooks.

Not fired

Callbacks registered on hooks that did not run on this page, grouped by plugin.

Background

AJAX and REST API requests you made while recording (for example saves in the block editor), which never show a page of their own. Open any of them to see its full map.

Compare

Load two saved maps (for example before and after activating or updating a plugin) and see hooks, callbacks, priorities and assets that changed.

Also

  • Search across hooks, callbacks, files and queries.
  • Copy a plain-text summary of the page for a support ticket, or export the full map as JSON.
  • Translation, escaping, option, URL and query hooks, which fire hundreds of times per page, are hidden until you ask for them.
  • Plugin hook reference under Tools > Hooktrail: lists the actions and filters any installed plugin offers to other developers, read from its code (nothing is run), with a Markdown download.

WP-CLI

  • wp hooktrail record <url> [--output=<file>] records a page on this site as a logged-out visitor sees it.
  • wp hooktrail compare <a.json> <b.json> [--fail-on-change] compares two maps; with --fail-on-change it exits with status 1 when they differ, for deploy checks.
  • wp hooktrail hooks <plugin-folder> [--format=table|json|csv|markdown] lists the hooks a plugin offers.

Safe to leave installed

  • Recording only runs for administrators who switch it on for themselves, and only in their own browser. Visitors are never recorded and see nothing.
  • WP-CLI recording works only with a single-use token that can only be created from the command line, and records the page as a logged-out visitor.
  • Page maps live only in the page you are viewing. Background-request maps are kept for 30 minutes for your account only. Nothing else is stored.
  • No external services, no tracking.

Installation

  1. Install and activate the plugin.
  2. Go to Tools > Hooktrail and click Turn recording on, or click Hooktrail: off in the admin bar.
  3. Open any page and click Hooktrail in the admin bar (or the Hooktrail button in the bottom corner).
  4. Turn recording off again when you are finished.

FAQ

Does it slow my site down?

Only for you, and only while recording is on. Hooktrail listens to every hook, query and PHP warning during your page views, which adds some time to each of your requests. Visitors and other users are not affected.

Why are some early hooks missing?

Recording starts when Hooktrail itself loads. Hooks, queries and warnings from before that, such as while must-use plugins and earlier plugins load, are not included. Callbacks those plugins add to later hooks are still shown. Filters that run before init cannot be traced.

How does it know which plugin a callback, query or warning belongs to?

Callbacks: PHP Reflection gives the file and line where each callback is defined. Queries and warnings: the call stack shows the plugin or theme file that made the call. Files are matched against the plugins folder, the must-use plugins folder, the active theme and WordPress core.

How are hook durations measured?

When a hook first runs, Hooktrail adds a callback at the very last priority, so it runs after every other callback on that hook and records the elapsed time. The time includes everything that ran inside the hook. The extra callback removes itself straight away.

Does tracing a filter change my site?

No. While tracing, each callback on that filter is wrapped so its input and output can be recorded; the wrapped callback receives the same arguments and its result is passed on unchanged. Only filters you choose are traced, only for your account, and only while recording is on.

Is it safe to share an exported map?

Exports can contain database queries, which may include data such as email addresses or user names. Check an export before sharing it outside your team.

Reviews

There are no reviews for this plugin.

Contributors & Developers

“Hooktrail” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Hooktrail” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.0.0

  • First release.