[wp-trac] Re: [WordPress Trac] #5445: Add function to count number of functions hooked to an action

WordPress Trac wp-trac at lists.automattic.com
Mon Dec 10 14:05:55 GMT 2007


#5445: Add function to count number of functions hooked to an action
------------------------------------------+---------------------------------
 Reporter:  pishmishy                     |        Owner:  pishmishy
     Type:  defect                        |       Status:  closed   
 Priority:  normal                        |    Milestone:  2.5      
Component:  General                       |      Version:  2.3.1    
 Severity:  normal                        |   Resolution:  invalid  
 Keywords:  has-patch plugin action hook  |  
------------------------------------------+---------------------------------
Comment (by darkdragon):

 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?"

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5445#comment:4>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list