WordPressMVC

  1. Get Started
  2. Documentation
  3. Tutorials
  4. Blog
  1. Documentation
  2. Tutorials
v1.0.8 Login
  • Blog
  • Download
  • Get Started
  • The Basics
    • Ayuco
    • Main Class
    • Configuration
  • Hooks
    • Actions
    • Filters
    • Widgets
    • Shortcodes
  • MVC
    • Models
    • Post Models
    • Option Models
    • Term Models
    • User Models
    • Views
    • Controllers
  • Resources
    • Assets
    • Styles
    • Scripts
  • Advanced
    • Request
    • Response
    • Localization
    • Cache
    • Logger
    • Database
    • Testing
    • Deployment
    • Functions
    • Add-ons

Actions

Last updated: January 12, 2020

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 );
    }
}
© 2023 10 Quality Studio . All rights reserved.
Search in: