Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active November 26, 2018 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/5cef7b7b004b83f527360494f55a162c to your computer and use it in GitHub Desktop.
Save Pebblo/5cef7b7b004b83f527360494f55a162c to your computer and use it in GitHub Desktop.
Example of how to log all of the EE hooks 'fired' on a request. You need to enable WP_DEBUG and WP_DEBUG_LOG for this to write the hooks to /wp-content/debug.log
<?php
//Debug function to easily write various vars to the log.
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
//Add all of the EE hooks into arrays used for logging later.
add_action('all', function(){
global $AHEE, $FHEE, $EEHooks;
$cf = current_filter();
$AHEE = is_array( $AHEE ) ? $AHEE : array();
$FHEE = is_array( $FHEE ) ? $FHEE : array();
$EEHooks = is_array( $EEHooks ) ? $EEHooks : array();
if ( strpos($cf, 'AHEE__') === 0 ) {
if(! in_array($cf, $AHEE) ) {
//Split out AHEE's
$AHEE[] = $cf;
//Add every hook to an array.
$EEHooks[] = $cf;
}
} elseif ( strpos($cf, 'FHEE__') === 0 ) {
if(! in_array($cf, $FHEE) ) {
//Split out AHEE's
$FHEE[] = $cf;
//Add every hook to an array.
$EEHooks[] = $cf;
}
}
});
//Log all of the EE hooks fired on this request.
add_action('shutdown', function(){
global $AHEE, $FHEE, $EEHooks;
if( !empty($AHEE) || !empty($FHEE) ) {
write_log(
array(
'AHEE (Actions Hooks)' => $AHEE,
'FHEE (Filter Hooks)' => $FHEE,
'All EE hooks' => $EEHooks
)
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment