[wp-trac] [WordPress Trac] #43592: Variadic hook callbacks

WordPress Trac noreply at wordpress.org
Wed Mar 21 07:12:58 UTC 2018


#43592: Variadic hook callbacks
--------------------------+-----------------------------
 Reporter:  soulseekah    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Plugins       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Is it not possible to have variadic callbacks for `add_action` and
 `add_filter`

 Both `apply_filters` and `do_action` accept a variable number of
 arguments. So theoretically the same action can be called with a different
 set of arguments depending on the context.

 However, the callbacks have a limitation on `$accepted_args`. By default
 this is set to `1`, it can't be open-ended either, you have to set it to
 something. I, for one, would love to use `func_get_args()` and `...$args`
 in my callbacks.

 Would it not be a good idea to make `$accepted_args` open-ended by
 default? i.e. pass ALL the arguments from `do_action/filter` into the
 callback. Something like setting `$accepted_args` to `-1` for variadic
 callbacks.

 This is a proposal to:

 1. Introduce support for `-1` as a valid open-ended value for
 `$accepted_args` (which ignores the slice here
 https://core.trac.wordpress.org/browser/tags/4.9/src/wp-includes/class-wp-
 hook.php#L288)
 2. Make -1 the default. Because it's safe to do so, since all functions in
 PHP are variadic.

 Or am I blatantly missing something?

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


More information about the wp-trac mailing list