Actions
WordPress Action hooks can be added to the Main Class with Ayuco or manually.
Ayuco Command
php ayuco add action:{action} {handler}
{action} | A WordPress action hook, such as "init". |
{handler} | A controller or view to handle the action. |
Example:
php ayuco add action:init AppController@init
In the command above, Ayuco will add WordPress action hook "init" to the project and will establish a controller "AppController" method "init" as the handler.
Ayuco Is Awesome
If no handler is defined, Ayuco will default it to "AppController". If the defined controller in the command doesn't exist then Ayuco will create it. If the defined controller's method in the command doesn't exist then Ayuco will create it.Add Manually
Action hooks can be added manually by defining them in the Main Class.
class Main extends Bridge { public function init() { // Manual hook added for hook "init". $this->add_action( 'init', 'CustomController@app_init' ); // Manual hook added for hook "wp_head". $this->add_action( 'wp_head', 'CustomController@header' ); } }
In the sample above, multiple manual action hooks have been added to the Main Class. Notice how handlers are defined.
Ayuco?
When a hook is added using ayuco, the hook is defined in the Main Class same as if it would have been defined manually.The add_action()
Main Class methods support the same parameters as WordPress's global function, this means that the execution priority and the number of parameters expected can be defined as parameters, see the example below:
class Main extends Bridge { public function init() { // Hook init at priority 20 $this->add_action( 'init', 'CustomController@app_init', 20 ); } }