markjaquith / feedback

Ask @markjaquith anything!
42 stars 4 forks source link

jQuery-like filter namespacing #20

Closed nyordanov closed 10 years ago

nyordanov commented 10 years ago

Hi,

Do you think that namespaces for action/filter tags similar to the way jQuery handles event namespaces is a good idea? Here's an example:

add_action( 'init.myplugin', function() {
    dosomething();
} );

remove_action( 'init.myplugin' ); // removes just this action
remove_action( 'init' );  // removes everything hooked to init

If I am not mistaken, this can be implemented pretty easily by modifying _wp_filter_build_unique_id(). Some default argument values will also need to be changed.

I know that WP still has to support PHP 5.2.4. However, not supporting anonymous functions in the filters API has been cited as a reason for keeping the current minimum required version. [1].

[1] https://groups.google.com/d/msg/php-fig/ogp03OHbVJ0/1Od2g234vo0J

markjaquith commented 10 years ago

I think it's a very interesting idea. It might also be useful for the case where the developer is using a class but hasn't made the instance variable available, rendering their hook "non-unhookable". @scribu opened a ticket for this very idea, although he modified his proposal to use : as the namespacing character, because @nacin noted that some hooks already have a . character in them.

As for WP minimum versions, even if we had a way of making anonymous functions unhookable, we're still not ready to require PHP 5.3, because 44.5% of WordPress installs are still on PHP 5.2.x. Eek. But of course individual plugin developers can still (and some do) require PHP 5.3.x.

nyordanov commented 10 years ago

Sorry, I must have missed @scribu's ticket.

Regarding the stats - are they actually accurate? Of our customer base, 5.2 is just 15% with 5.3 at 39% and the rest being 5.4+. We get these numbers by only counting sites which had an user logged in at least once in the last 7 days. This way we exclude any sites which are left untouched once they were set up. Similarly, we have 3.9.x at over 60% and 3.8.x at 32%

nacin commented 10 years ago

@nyordanov Yes, they are actually accurate. While the public aggregate numbers are for all WP versions (technically, all versions >= 3.0), we've at various times calculated a snapshot using only the most recent version(s) of WordPress, and have always found them to be negligibly different.