Extensions are a part of the Hooks API that extend the available settings for a Reaction. Extensions can do things like prevent a Reaction from from actually responding to a particular fire of an Event, and listen for when an event fire is a “hit,” or when it is a “miss.” Extensions are different than Reactors, in that extensions do not actually take action to respond to an event, they only dictate and/or detect whether the Reactor fires.
Extensions extend the WordPoints_Hook_Extension
class, and are registered with the hook extensions class registry:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /** * Register hook extension when the extension registry is initialized. * * @since 1.0.0 * * @WordPress\action wordpoints_init_app_registry-hooks-extensions * * @param WordPoints_Class_Registry_Persistent $extensions The extension registry. */ function wordpoints_my_prefix_hook_extensions_init( $extensions ) { $extensions->register( 'example', 'WordPoints_Hook_Extension_Example' ); } add_action( 'wordpoints_init_app_registry-hooks-extensions' , 'wordpoints_my_prefix_hook_extensions_init' ); |
Extensions can also implement several different interfaces, in order to listen for whether a fire hit or missed:
WordPoints_Hook_Extension_Hit_ListenerI
WordPoints_Hook_Extension_Miss_ListenerI