Skip to content

Instantly share code, notes, and snippets.

@BrianHenryIE
Created May 14, 2021 23:30
Show Gist options
  • Save BrianHenryIE/6aaa505fff0b7e999621238750532d18 to your computer and use it in GitHub Desktop.
Save BrianHenryIE/6aaa505fff0b7e999621238750532d18 to your computer and use it in GitHub Desktop.
Find on which WordPress hook something has happened
<?php
/**
* In this example, we will test has WooCommerce populated the global $product variable.
*
* Basically, we add an action to the WordPress `all` hook, then `error_log` when the criteria is true, and unhook.
*/
global $has_product_global_been_set;
$has_product_global_been_set = function() {
global $product;
if( !empty( $product ) ) {
$was_set = current_action();
error_log( "global \$product first set on action {$was_set}" );
global $has_product_global_been_set;
remove_action( 'all', $has_product_global_been_set, 999 );
}
};
add_action( 'all', $has_product_global_been_set, 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment