[wp-trac] [WordPress Trac] #26704: Multiple actions when using add_action

WordPress Trac noreply at wordpress.org
Sun Dec 22 10:48:34 UTC 2013


#26704: Multiple actions when using add_action
-----------------------------+------------------------
 Reporter:  sigurdbergsvela  |       Owner:
     Type:  feature request  |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Plugins          |     Version:  trunk
 Severity:  normal           |  Resolution:  duplicate
 Keywords:                   |
-----------------------------+------------------------
Changes (by dd32):

 * status:  new => closed
 * resolution:   => duplicate
 * milestone:  Awaiting Review =>


Comment:

 Two main issues:
 1. We currently allow actions to have spaces in them, although we don't
 generally advise it, an action can be made up of any valid PHP string.
 1. The add_action/add_filter set of functions are called hundreds of times
 per page load, adding an explode() to that function will make running the
 function more expensive without any gained benefit for almost every
 existing use of the functions.

 A few general suggestions:
 *. Closures in hooks is kind of bad, you're completely unable to remove
 the function from the hook, and in the event that all functions are
 removed from the hook by a plugin, it can't re-add the function. Leads to
 a harder life for those performing deep customizations of existing plugins
 * If you use a PHP class (or namespace if you're into that kind of thing),
 you get around the need to have long function names,
 `filter_{$filter_name}()` is a common method name in a lot of plugin
 classes.
 * A similar proposal to pass an array of actions has also been suggested:
 #14280  - this also fits the expensive with little benefits case mentioned
 above.

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


More information about the wp-trac mailing list