[wp-trac] [WordPress Trac] #14280: add_filter should accept an array of tags
WordPress Trac
wp-trac at lists.automattic.com
Wed Aug 15 16:36:01 UTC 2012
#14280: add_filter should accept an array of tags
-------------------------------------------------+-------------------------
Reporter: sivel | Owner:
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: Plugins | Version:
Severity: normal | Resolution: wontfix
Keywords: has-patch early needs-testing dev- |
feedback |
-------------------------------------------------+-------------------------
Comment (by joehoyle):
If you are using closures, this isn't just syntactic sugar.
{{{
foreach ( array( 'sanitize_post', 'sanitize_user' ) as $hook ) {
add_action( $hook, function() { return $foo; } );
}
}}}
This will create 2 closure objects, whereas `add_action` supporting an
array would only require 2 references to the same closure. (less memory
usage, shared scope etc)
You could always do
{{{
$func = function() { return $foo };
foreach ( array( 'sanitize_post', 'sanitize_user' ) as $hook ) {
add_action( $hook, $func );
}
}}}
But that feels like it starts to get messy. I would rather create my own
`add_actions` function than do the above, so I don't think it's a stretch
to just add the functionality to `add_action`
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14280#comment:5>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list