WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 9 months ago

#19306 closed enhancement (fixed)

remove_all_filters() should set to array(), not unset

Reported by: nacin Owned by: wonderboymusic
Milestone: 4.0 Priority: normal
Severity: normal Version:
Component: Plugins Keywords: has-patch
Focuses: Cc:

Description

Consider this use case: You want to hook into priority 0 of an action and run remove_all_actions() for all other callbacks.

Since we use current() and next() to iterate, rather than making a copy of $wp_filter to loop through it, this should work.

Unfortunately, current() and next() expect an array, and only stop when next() returns === false. remove_all_filters() does an unset() on $wp_filter[$tag], which means next() returns A) a warning, and B) null. The null causes an indefinite loop.

Test code:

add_filter( 'test_filter', function() { remove_all_filters( 'test_filter' ); return 0; }, 0 );
add_filter( 'test_filter', function() { return 1; }, 1 );
add_filter( 'test_filter', function() { return 2; }, 2 );
var_dump( apply_filters( 'test_filter', -1 ) );

Attachments (2)

19306.diff (502 bytes) - added by nacin 3 years ago.
19306.2.patch (502 bytes) - added by c3mdigital 19 months ago.
Refresh or Nacin's patch

Download all attachments as: .zip

Change History (7)

@nacin3 years ago

comment:1 @kawauso3 years ago

  • Cc kawauso added

comment:2 @mythemes19 months ago

21 months... wp 3.6 and nobody reviewed this patch???

comment:3 @helen19 months ago

I mean, Nacin wrote it, so if he still wants it, it's been reviewed by a lead dev. :)

@c3mdigital19 months ago

Refresh or Nacin's patch

comment:4 @wonderboymusic9 months ago

  • Milestone changed from Awaiting Review to 4.0

comment:5 @wonderboymusic9 months ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 28883:

remove_all_filters() should set to array(), not call unset().

Props nacin, c3mdigital.
Fixes #19306.

Note: See TracTickets for help on using tickets.