[wp-trac] [WordPress Trac] #17019: context arg for WP_Query filter application

WordPress Trac wp-trac at lists.automattic.com
Thu Apr 7 07:59:01 UTC 2011


#17019: context arg for WP_Query filter application
-------------------------+------------------------------
 Reporter:  kevinB       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------

Comment (by kevinB):

 Replying to [comment:14 kevinB]:
 > Replying to [comment:13 nacin]:
 > >
 > > Adding a context filter to all hooks is going to be way worse
 performance wise than adding a filter only exactly when you want it.
 > >
 >
 > I didn't propose adding an additional filter to all hooks. Where do you
 see that?
 >
 I think I see where you misunderstood me.  My point was that with multiple
 WP_Query use by core code, this:

 {{{
 add_filter( 'posts_where', 'my_function', 10, 2 );
 }}}

 causes my_function to be executed every time Query_Posts applies filters
 for any query; I have no choice.  Same for my_function2 and my_function3
 which also want to filter posts_where, but for a different use case.  All
 3 of them, when hooked directly to posts_where, will each be executed
 every N times post_where filters are applied.  Is there not some overhead
 in needless call_user_func_array() calls?

 So as it stands, my plugin code will instead hook '''one''' function to
 posts_where and let it route the traffic.  But most plugin / theme authors
 won't bother to do that, so I thought it would be better to just skip the
 call_user_func_array() when a context mismatch is known.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17019#comment:18>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list