WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #22256


Ignore:
Timestamp:
10/22/12 19:09:37 (18 months ago)
Author:
scribu
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #22256

    • Property Summary changed from Hook namespaceing to Hook namespacing
  • 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: 
     1Currently, 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. 
    22 
    3 * class instance methods, where you don't have access to the instance 
    4 * PHP 5.3 closures 
     3You need to know all of them in order to use `remove_action()` successfully. 
    54 
    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: 
     5Acquiring the callback is especially problematic when it's: 
    76 
    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 
     10Introducing 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 
     12Proposed syntax: 
     13 
     14{{{ 
     15add_action( 'after_setup_theme.twentytwelve', function() { 
     16  // do stuff 
     17} 
     18 
     19add_action( 'after_setup_theme.twentytwelve', function() { 
     20  // do more stuff 
     21} 
     22 
     23add_filter( 'parse_query.p2p', function() { 
     24  // do stuff 
     25} 
     26}}} 
     27 
     28Later: 
     29 
     30{{{ 
     31// remove specific callbacks added by the Twentytwelve theme 
     32remove_action( 'after_setup_theme.twentytwelve' ); 
     33 
     34// remove all callbacks added by the P2P plugin 
     35remove_action( '*.p2p' ); 
     36}}}