[wp-trac] [WordPress Trac] #61882: Assigning same callback to multiple Actions and Filters via a single function call

WordPress Trac noreply at wordpress.org
Thu Aug 15 17:17:55 UTC 2024


#61882: Assigning same callback to multiple Actions and Filters via a single
function call
----------------------------+-----------------------------
 Reporter:  namith.jawahar  |      Owner:  (none)
     Type:  enhancement     |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 This is an enhancement everyone decided to leave out for lack of
 performance improvement more than a decade back but now we have extensive
 use of anonymous functions and the syntactic sugar does make sense now.

 Something like this will allow not having to define a function with a name
 or assign a function to a variable and run it through foreach every time
 the same callback needs to be applied to different hooks

 Something like the add_actions and add_filters function wont create an
 impact on existing hook while allowing cleaner and easier to read code
 without having to litter everywhere with foreach loops.

 {{{#!php
 function add_actions($hooks, $callback, $priority = 10, $accepted_args =
 1) {
     foreach ($hooks as $hook) {
         add_action($hook, $callback, $priority, $accepted_args);
     }
 }
 }}}

 Hoping to restart the discussion around this

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61882>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list