[wp-trac] [WordPress Trac] #11212: Add filter to wp_parse_args()
WordPress Trac
wp-trac at lists.automattic.com
Sun Nov 22 01:17:58 UTC 2009
#11212: Add filter to wp_parse_args()
--------------------------+-------------------------------------------------
Reporter: Viper007Bond | Owner:
Type: enhancement | Status: new
Priority: lowest | Milestone: Future Release
Component: General | Version: 2.9
Severity: normal | Keywords: has-patch
--------------------------+-------------------------------------------------
Comment(by Viper007Bond):
Replying to [comment:8 filosofo]:
> Because otherwise you're going to influence performance geometrically.
Let's say I want to change the max_depth argument. With a
wp_list_comments-specific filter, my attached callback gets called once.
With the wp_parse_args filter, it's called 80-some times.
I can't edit the ticket and post the revised idea. You'll have to read the
comments above. ;)
The current concept is adding a third optional parameter to
`wp_parse_args()` that says where it's being called from (i.e.
`__FUNCTION__`). '''If that parameter is set''', then `wp_parse_args()`
fires a filter called `wp_parse_args_the_function_name`.
So if I wanted to modify `wp_list_comments()`, I'd hook into
`wp_parse_args_wp_list_comments`. My callback would only be run when
`wp_list_comments()` is used rather than every time `wp_parse_args()` is
used.
As for performance, there's no difference between adding a filter inside
each function or just one dynamic filter inside of `wp_parse_args()` --
it's the same number of `apply_filters()`. Plus `apply_filters()` is
incredibly fast, especially if nothing is hooked to the hook it's calling
as all it's doing is looking at the hooks array and then aborting when it
finds nothing for that hook. About a 100 calls to it '''with a callback'''
only adds a couple milliseconds.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11212#comment:9>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list