[wp-trac] [WordPress Trac] #37985: Allow all arguments to be passed to an action or filter callback
WordPress Trac
noreply at wordpress.org
Thu Sep 8 08:36:05 UTC 2016
#37985: Allow all arguments to be passed to an action or filter callback
-----------------------------+-----------------------------
Reporter: aaemnnosttv | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version: trunk
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
Related #17817, #14671
With the recent addition of WP_Hook for 4.7, I have a small request to
make regarding the way callback arguments are handled.
As it is, it is still not possible to pass all arguments to the filter or
action callback. While #14671 would be the ideal solution IMO, it seems
as if that is a no-go at least for now.
However, I would like to propose a next-best option which I don't believe
has been suggested yet to allow all arguments to be passed which should be
fully backwards compatible and no less performant than it is now.
The basic idea is that there should be a way to pass all arguments without
just using some arbitrarily large number to fake it.
My patch simply changes the way the callback args are manipulated at call
time, so that they are only sliced if the accepted args is a number
greater than zero.
To explicitly pass all arguments to the callback, you could add_action or
add filter like this:
{{{#!php
<?php
add_action( 'some_tag', 'some_callback', 10, -1 );
// or
add_filter( 'some_tag', 'some_callback', 10, -1 );
}}}
You can also draw a bit of a parallel with WP_Query conceptually with a -1
for posts_per_page returning unlimited results.
All the current tests still pass and I added one to test this
specifically.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/37985>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list