#33886 closed enhancement (duplicate)
Need ability to determine the priority at which an action hook or filter is being run
| Reported by: | bobbingwide | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Plugins | Version: | 4.4 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
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.
Change History (10)
#1
@
11 years ago
- Summary Need ability to determine the priority which an action hook or filter is being run at → Need ability to determine the priority at which an action hook or filter is being run
#3
in reply to: ↑ 2
@
11 years ago
Replying to SergeyBiryukov:
has_filter( current_filter(), __FUNCTION__ )returns the priority.
This returns the priority of the first invocation, not the current one.
My routine can be attached to the same hook with multiple priorities.
e.g. the_content:11,the_content:10
So for priority 10, with verbose tracing I could see the results after these filters have been applied
wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(333:64) bw_trace_inspect_current(1) 339 2015-09-25T09:10:13+00:00 1.695575 0.024268 cf=genesis_loop,genesis_entry_content,the_content 27 17898 31566984/32127896 F=293 current Array
(
[convert_smilies] => Array
(
[function] => convert_smilies
[accepted_args] => 1
)
[convert_chars] => Array
(
[function] => convert_chars
[accepted_args] => 1
)
[prepend_attachment] => Array
(
[function] => prepend_attachment
[accepted_args] => 1
)
[bw_trace_results] => Array
(
[function] => bw_trace_results
[accepted_args] => 9.10
)
)
#4
@
10 years ago
I think this might get what you need.
<?php function current_filter_priority() { global $wp_filter; return key( $wp_filter[current_filter()] ); }
#5
@
10 years ago
- Resolution → invalid
- Status new → closed
@lgedeon Thanks Luke. I'll do a bit more testing and then either mark this as 'wontfix' or convert your snippet into a patch.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In this example the priority is
11.