Filters
WordPress Filter hooks can be added to the Main Class with Ayuco or manually.
Ayuco Command
php ayuco add filter:{filter} {handler}
{filter} | A WordPress filter hook, such as "body_class". |
{handler} | A controller or view to handle the action. |
Example:
php ayuco add filter:body_class AppController@body_class
In the command above, Ayuco will add WordPress filter hook "body_class" to the project and will establish a controller "AppController" method "body_class" 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
Filter hooks can be added manually by defining them in the Main Class.
class Main extends Bridge { public function init() { // Manual hook added for hook "body_class". $this->add_filter( 'body_class', 'CustomController@body' ); // Manual hook added for hook "the_content". $this->add_filter( 'the_content', 'CustomController@content' ); } }
In the sample above, multiple manual filter 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_filter()
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_filter( 'body_class', 'CustomController@body', 20 ); } }