Created
May 14, 2021 23:30
-
-
Save BrianHenryIE/6aaa505fff0b7e999621238750532d18 to your computer and use it in GitHub Desktop.
Find on which WordPress hook something has happened
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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