#5445 closed defect (bug) (invalid)
Add function to count number of functions hooked to an action
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.3.1 |
Component: | General | Keywords: | has-patch plugin action hook |
Focuses: | Cc: |
Description
Add a function to count the number of functions hooked to a particular action. Useful to test if an action exists at all.
Attachments (1)
Change History (7)
#2
@
17 years ago
There is already has_filter()
and has_action()
for testing whether or not a action or filter exists.
#4
@
17 years ago
There are some issues with the patch
function count_filter($filter) { global $wp_filter; $i = 0; if( isset($wp_filter[$filter]) } { foreach($wp_filter[$filter] as $priority) $i += count($priority); } return $i; } function count_action($action) { return count_filter($action); }
- The global $wp_actions stores how many times an action was called.
And that is all. Really, for optimization, if it is not set, then it is better to return 0, like your patch. Not have an else condition. Then have the loop afterwards.
It would also be better to have some sort of caching once the number has been found.
You misunderstand. It would be useful to have this function, but just not for your second point. A guy (one guy) thought it would be useful. However, I'm not quite sure it would be useful for everyone else.
One practical application would be for debugging, "Did my hook actually add itself?"
Adds count_action()