[wp-trac] [WordPress Trac] #33492: Slightly better add_filter

WordPress Trac noreply at wordpress.org
Sat Aug 22 04:47:38 UTC 2015


#33492: Slightly better add_filter
-------------------------+------------------------------
 Reporter:  Iazel        |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by dd32):

 FWIW, the best way to handle this at present is to assign the anonymous
 function to a variable which you later remove, the following code would
 print `false, true, false` for example:
 {{{
 var_dump( has_filter( 'test' ) );

 add_filter( 'test', $function = function() {} );

 var_dump( has_filter( 'test' ) );

 remove_filter( 'test', $function );

 var_dump( has_filter( 'test' ) );
 }}}

 It seems to me, that allowing the closures to be named in this way could
 result in conflicts with other plugins and functions. assigning it to a
 variable and removing it later also encourages developers not to use
 anonymous functions when they should be using a real function or method.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33492#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list