WordPress: can’t add a plugins_loaded hook from functions.php?

My functions.php includes this code:

add_action('plugins_loaded', 'plugin_overrides');
function plugin_overrides() {
   error_log("B", 0);
}

And I’ve modified wp-settings.php to put debug calls around the hook stuff:

Read More
error_log("A", 0);
do_action( 'plugins_loaded' );
error_log("C", 0);

The idea is to replace a couple of woocommerce hook actions with my own, so my plugin_overrides calls remove_hook, and so on.

However, plugin_overrides doesn’t seem to be called. When I reload any page on my site the error log only shows the A and C messages, and never B. And, in fact, wp-settings.php is actually run twice, for some reason – I get 2 sets of A/C messages. Except when I load a woocommerce-specific page, when it’s run 3 times, with my woocommerce-specific add_action debug messages appearing after the first call.

Any idea what’s going on? How do I hook into plugins_loaded to call remove_action for plugins?

Related posts

Leave a Reply