[wp-trac] [WordPress Trac] #33886: Need ability to determine the priority which an action hook or filter is being run at
WordPress Trac
noreply at wordpress.org
Tue Sep 15 18:34:53 UTC 2015
#33886: Need ability to determine the priority which an action hook or filter is
being run at
-------------------------+-----------------------------
Reporter: bobbingwide | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
I have a trace routine which can be invoked for any hook.
It can also be registered to run at multiple priorities.
I'm trying to use it to see what's happening during 'the_content'
processing.
It would be nice if the output was able to show the priority of the actual
invocation.
=== Current solution ===
In this first iteration my trace function calls the following.
{{{
/**
* Find the current priority
* @return string priority
*/
function bw_trace_inspect_current() {
global $wp_filter;
$tag = current_filter();
$current = current( $wp_filter[ $tag ] );
bw_trace2( $current, "current", false, BW_TRACE_VERBOSE );
$priority = $current[ 'bw_trace_results']['accepted_args'];
$priority = substr( $priority, 2 );
return( $priority );
}
}}}
This super hack relies on the fact that you can define accepted args as a
decimal value
So I append the priority to the `$accepted_args` parameter.
I'm using a base value of `9 `, since I want to trace all the passed
parameter values.
It seems to be high enough.
Note: I can't guarantee I can find what it should be for the given action
hook or filter.
{{{
wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(338:64)
bw_trace_inspect_current(2) 338 2015-09-15T17:53:33+00:00 1.801802
0.001625 cf=genesis_loop,genesis_entry_content,the_content 27 1463
32065360/32341352 F=300 current Array
(
[capital_P_dangit] => Array
(
[function] => capital_P_dangit
[accepted_args] => 1
)
[do_shortcode] => Array
(
[function] => do_shortcode_earlier
[accepted_args] => 1
[replaced] => do_shortcode
)
[bw_trace_results] => Array
(
[function] => bw_trace_results
[accepted_args] => 9.11
)
)
}}}
Aside: As you can see the trace output is also fairly useful.
It tells me that if I wanted to inspect the result between
capital_P_dangit and
do_shortcode I'd have to fiddle even more than I've already done with my
bw_replace_filter() function... which has added the [replaced] entry.
=== Preferred solution ===
WordPress to provide an API that I can call to return the current hook
priority without me having to mess with internal structures.
I don't need the whole stack, just the priority of the end on in
$wp_current_filter.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33886>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list