Created
December 7, 2022 00:27
-
-
Save jmichaelward/b7c81806692191a937afd39c11523041 to your computer and use it in GitHub Desktop.
Class for wrapping native WordPress hooks in separate callbacks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Thinking through a possible implementation for wrapping native WordPress hooks with my own. | |
*/ | |
declare( strict_types=1 ); | |
namespace JMichaelWard\PluginConcept; | |
/** | |
* Service class to wrap native WordPress hooks in our own native hooks. | |
*/ | |
class CustomHookService { | |
/** | |
* Register hooks with WordPress. | |
*/ | |
public function register_hooks(): void { | |
add_action( 'wp', [ $this, 'jmw_wp' ] ); | |
add_action( 'wp_head', [ $this, 'jmw_wp_head' ] ); | |
add_action( 'init', [ $this, 'jmw_init' ] ); | |
} | |
/** | |
* `wp` callback | |
*/ | |
public function jmw_wp(): void { | |
do_action( 'jmw_wp' ); | |
} | |
/** | |
* `wp_head` callback | |
*/ | |
public function jmw_wp_head(): void { | |
do_action( 'jmw_wp_head' ); | |
} | |
/** | |
* `init` callback | |
*/ | |
public function jmw_init(): void { | |
do_action( 'jmw_init' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment