Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#61882 closed enhancement (duplicate)

Assigning same callback to multiple Actions and Filters via a single function call

Reported by: namith.jawahar Owned by:
Priority: normal Milestone:
Component: Plugins Version:
Severity: normal Keywords:
Cc: Focuses:

Description

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.

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

Change History (1)

#1 @SergeyBiryukov
2 years ago

  • Component GeneralPlugins
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

Hi there, welcome to WordPress Trac!

Thanks for the ticket, we're already tracking this enhancement in #34309.

Version 0, edited 2 years ago by SergeyBiryukov (next)
Note: See TracTickets for help on using tickets.