Changes between Initial Version and Version 1 of Ticket #22256
- Timestamp:
- 10/22/2012 07:09:37 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #22256
-
Property
Summary
changed from
Hook namespaceingtoHook namespacing
-
Property
Summary
changed from
-
Ticket #22256 – Description
initial v1 1 We have a handy `remove_action()` function, but it works only if you can acquire the exact callback that was passed to add_action(), which is tricky when it comes to: 1 Currently, callbacks passed to add_action() and add_filter() are already sort of namespaced by the hook name, by the callback itself, by priority and by argument count. 2 2 3 * class instance methods, where you don't have access to the instance 4 * PHP 5.3 closures 3 You need to know all of them in order to use `remove_action()` successfully. 5 4 6 Introducing namespaces for hooks, similar to jQuery's [http://docs.jquery.com/Namespaced_Events namespaced events], we would not only take care of that problem, but also enable things like:5 Acquiring the callback is especially problematic when it's: 7 6 8 * remove all callbacks to 'the_content' added by plugin X 9 * remove all callbacks to the 'parse_query' action added by theme Y 7 * an instance method, and you don't have access to the instance 8 * a PHP 5.3 closure 9 10 Introducing namespaces for hooks, similar to jQuery's [http://docs.jquery.com/Namespaced_Events namespaced events], would not only take care of that problem, but also enable things like removing all callbacks added by plugin X, regardless of hook name or anything else. 11 12 Proposed syntax: 13 14 {{{ 15 add_action( 'after_setup_theme.twentytwelve', function() { 16 // do stuff 17 } 18 19 add_action( 'after_setup_theme.twentytwelve', function() { 20 // do more stuff 21 } 22 23 add_filter( 'parse_query.p2p', function() { 24 // do stuff 25 } 26 }}} 27 28 Later: 29 30 {{{ 31 // remove specific callbacks added by the Twentytwelve theme 32 remove_action( 'after_setup_theme.twentytwelve' ); 33 34 // remove all callbacks added by the P2P plugin 35 remove_action( '*.p2p' ); 36 }}}