WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#37985 closed enhancement (duplicate)

Allow all arguments to be passed to an action or filter callback

Reported by: aaemnnosttv Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Plugins Keywords:
Focuses: Cc:

Description

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
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.

Attachments (1)

37985.1.diff (2.4 KB) - added by aaemnnosttv 5 years ago.
Initial patch

Download all attachments as: .zip

Change History (2)

@aaemnnosttv
5 years ago

Initial patch

#1 @swissspidy
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Type changed from feature request to enhancement
  • Version 4.7 deleted

Hey there,

Thanks for opening this ticket! This has been discussed at length at #14671. Would you mind chiming in there and uploading your patch on that ticket?

Cheers.

Note: See TracTickets for help on using tickets.