You appear to be a bot. Output may be restricted
Description
Count every action and filter hookWordPress itself counts the number of times an action is performed in order to be able to report true on did_action(). We want to know about filters as well. This new logic ( Aug 2014 ) is significantly faster than the orignal action tracing, which wrote each action to the action log. The additional logic ( May/June 2015 ) helps us determine the nesting. Sep 2015 – added ability to record the number of parameters passed. We subtract 1 from the number of args passed to this function; it gives the value needed when registering an action hook or filter.
Usage
bw_trace_count_all( $tag, $args2 );
Parameters
- $tag
- ( string ) required – the action or filter hook
- $args2
- ( array ) optional – doesn't matter – we use func_num_args()
Returns
voidSource
File name: oik-bwtrace/includes/oik-action-counts.phpLines:
1 to 28 of 28
function bw_trace_count_all( $tag, $args2=null ) { global $bw_action_counts; global $bw_action_parms; global $bw_action_time; if ( !isset( $bw_action_counts[ $tag ] ) ) { $bw_action_counts[ $tag ] = 1; $bw_action_parms[ $tag ] = func_num_args() - 1; $bw_action_time[ $tag ] = microtime( true ); } else { $bw_action_counts[ $tag ] += 1; } /* * We also want to record the actions showing the hierarchy of hooks * Assuming no one uses semi-colons in hook names! * */ global $wp_current_filter; global $bw_action_counts_tree; $filters = implode( ";", $wp_current_filter ); if ( !isset( $bw_action_counts_tree[ $filters ] ) ) { $bw_action_counts_tree[ $filters ] = 1; } else { $bw_action_counts_tree[ $filters ] += 1; } }View on GitHub View on Trac