WordPress.org

Make WordPress Core

Opened 6 weeks ago

Closed 6 weeks ago

#49219 closed defect (bug) (invalid)

feed.php calls apply_filters with too many arguments

Reported by: bret.miller Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.3.2
Component: Feeds Keywords:
Focuses: Cc:

Description

feed.php calls apply filters like this:

return apply_filters( 'get_bloginfo_rss', convert_chars( $info ), $show );

But in class-wp-hook, apply_filters only accepts 2 parameters. So when filters are called for get_bloginfo_rss, they get the text, but not what was requested making it very hard to acutally create a meaningful filter.

It needs to be changed to

return apply_filters( 'get_bloginfo_rss', array(convert_chars( $info ), $show) );

so that both items are passed to the filter.

Change History (1)

#1 @SergeyBiryukov
6 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi there, welcome to WordPress Trac! Thanks for the ticket.

There are 1200+ instances of passing more than two arguments to apply_filters() in WordPress core.

While the WP_Hook::apply_filters() method indeed only accepts two parameters, the apply_filters() function accepts any number of parameters to pass to the callback function using func_get_args().

If you want your callback function to receive these additional parameters, you have to specify the number of arguments as the 4th parameter in your add_filter() call:

add_filter( 'get_bloginfo_rss', 'my_function', 10, 2 );

There is no bug here, this code works as intended.

Related: #33891

Note: See TracTickets for help on using tickets.