I have this idea where I would create a class that would take in a set of hook names then create them, for me to use when ever, and where ever.
Currently the way to create a hook is we do something like:
function some_hook_name(){
do_action('some_hook_name');
}
And then from there we write some other function, well call – add_content and then pass it to the action as such:
add_action('some_hook_name', 'add_content');
and there we go.
But what if I wanted to create a class where I do something like:
$array_of_hook_names = array(
'hook_one', 'hook_two', ...
)
so that later on, I could do:
add_action('hook_one', 'add_content');
Is there any way to do this? Could I just do something like:
public function setup_hooks($array){
foreach($array as $hook_name){
do_action($hook_name);
}
}
Ideas?
Your proposal is OK – you can see this in action even in the WordPress itself. See admin-ajax.php where you can find this piece of code:
As you can see, the action hooks are generated dynamicaly…