[wp-trac] [WordPress Trac] #22256: Hook namespacing (was: Hook namespaceing)
WordPress Trac
noreply at wordpress.org
Mon Oct 22 19:09:38 UTC 2012
#22256: Hook namespacing
-------------------------+------------------------------
Reporter: scribu | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Plugins | Version:
Severity: normal | Resolution:
Keywords: |
-------------------------+------------------------------
Description changed by scribu:
Old description:
> 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:
>
> * class instance methods, where you don't have access to the instance
> * PHP 5.3 closures
>
> 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:
>
> * remove all callbacks to 'the_content' added by plugin X
> * remove all callbacks to the 'parse_query' action added by theme Y
New description:
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.
You need to know all of them in order to use `remove_action()`
successfully.
Acquiring the callback is especially problematic when it's:
* an instance method, and you don't have access to the instance
* a PHP 5.3 closure
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.
Proposed syntax:
{{{
add_action( 'after_setup_theme.twentytwelve', function() {
// do stuff
}
add_action( 'after_setup_theme.twentytwelve', function() {
// do more stuff
}
add_filter( 'parse_query.p2p', function() {
// do stuff
}
}}}
Later:
{{{
// remove specific callbacks added by the Twentytwelve theme
remove_action( 'after_setup_theme.twentytwelve' );
// remove all callbacks added by the P2P plugin
remove_action( '*.p2p' );
}}}
--
--
Ticket URL: <http://core.trac.wordpress.org/ticket/22256#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list