Skip to content

WordPress hook debugging: which action fired, when, and what was attached

Debugging WordPress hooks means knowing the firing order, the priority of every callback, and what each filter returned. Here are the WordPress techniques that show all three.

When a WordPress filter or action doesn’t behave the way you expect — “my callback isn’t running”, “the value gets overwritten”, “the order is wrong” — the diagnostic isn’t a guess. There are tools that show the full hook execution timeline. The trick is knowing which one fits which question.

What’s happening

WordPress hooks are stored in the global $wp_filter array. Each entry is a hook name pointing to an array indexed by priority (default 10), each priority pointing to an array of callbacks. When do_action('save_post') runs, WordPress walks that array in priority order, calling each callback. A do_action returns nothing; an apply_filters returns whatever the last callback returned.

The places things go wrong: a callback registered too late (after the hook already fired), a callback registered with the wrong number of arguments, a filter that returns null instead of the value it received (so the next callback gets null), two callbacks at the same priority and the second overwrites the first, or a callback that’s silently never reached because an earlier one short-circuited via return false.

How to verify

# Print all callbacks attached to a hook:
wp eval 'global $wp_filter; print_r($wp_filter["save_post"] ?? "no callbacks");'

# Use Query Monitor's Hooks panel — shows every fired hook in execution order

# Add temporary logging:
add_action('all', function($hook) {
    error_log("HOOK FIRED: $hook");
}, 1);

For a single hook, use the did_action debug pattern:

add_action('init', function() {
    error_log('init fired at priority ' . current_filter() . ' - count: ' . did_action('init'));
}, 1);

Query Monitor’s Hooks panel is the fastest read for “which callbacks ran for this hook” — it shows callback, priority, source file, and execution time.

The fix

  1. Use Query Monitor first. Hooks panel, find the hook in question, expand to see every callback in firing order with priority and source. If your callback isn’t there, registration failed.
  2. Confirm registration timing. A callback registered in plugins_loaded won’t catch hooks that fired earlier (during muplugins_loaded or initial config). Register on the earliest hook you can.
  3. Check argument count. add_filter('my_filter', 'my_callback', 10, 3) — the 3 is critical. If your callback declares three parameters but add_filter says 1, the extras come through as null.
  4. Check the return value. Filters must return what they received (modified or not). A filter that does return; returns null and the next callback sees null. Use var_dump or error_log on the return.
  5. Use all hook for full trace. Attach a callback to the all hook to log every fired hook. Useful for “which hook should I be using” questions. Remove it before production.
  6. Use Hookr or Debug Bar for deep dives. These plugins show even more detail than Query Monitor, including hooks that fired but had no callbacks attached.

For plugin and theme development across distributed teams, Stack Harbor enforces hook discipline as part of managed enterprise WordPress hosting code review. To get a hook conflict diagnosed, book a consult.