-
-
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
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 | |
//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