[wp-trac] [WordPress Trac] #21170: JavaScript actions and filters

WordPress Trac noreply at wordpress.org
Sat Jul 22 10:25:46 UTC 2017


#21170: JavaScript actions and filters
-----------------------------+------------------------------
 Reporter:  koopersmith      |       Owner:  adamsilverstein
     Type:  feature request  |      Status:  assigned
 Priority:  normal           |   Milestone:  4.9
Component:  General          |     Version:  3.4
 Severity:  normal           |  Resolution:
 Keywords:  has-patch        |     Focuses:  javascript
-----------------------------+------------------------------

Comment (by jnylen0):

 Replying to [comment:131 azaozz]:
 > Thinking it should be mandatory so we have parity with the way hooks
 work in PHP. A plugin should always be able to remove an action or a
 filter, also when it is added by another plugin. If the callback name is
 not mandatory some plugins will probably skip it. Then we will have to do
 "Doing it wrong..." etc. again.

 In the plugins repo there are about 6500 instances of plugins adding
 anonymous functions to PHP filters or actions.  These are currently
 impossible for other plugins to remove.  Is this something we want to
 prevent for JS filters?

 Maybe, but sacrificing the very natural JavaScript pattern `add_filter(
 'some_filter_name', function() { ...` doesn't really seem worth it to me.

 I'm in favor of requiring that core JS filters always have a namespace or
 function name, but not so sure about making these mandatory for plugins.
 I think it would add a significant amount of friction for a fairly minor
 use case.

 Either way, PHP parity is not something we should necessarily strive for
 because the two languages are very, very different.  Here's an example of
 an alternative approach that would allow the same functionality in a way
 that is fairly natural in JavaScript, but impossible in PHP:

 {{{#!javascript
 forEachFilter( 'filter_name', function( callback, priority, namespaces ) {
     // Inspect `callback` (including looking at the function name and
     // maybe even its code) and call `removeFilter` if necessary
 } );
 }}}

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


More information about the wp-trac mailing list