Skip to main content
added 24 characters in body
Source Link

Once you have create your hook and have it saved, it will appear in the hooks dropdown menu within the Postmater CP. Simply select your hook from the list and create a template. Postmaster will parse all the variables you pass to the template.

Once you have create your hook and have it saved, it will appear in the hooks dropdown menu. Simply select your hook from the list and create a template. Postmaster will parse all the variables you pass to the template.

Once you have create your hook and have it saved, it will appear in the hooks dropdown menu within the Postmater CP. Simply select your hook from the list and create a template. Postmaster will parse all the variables you pass to the template.

Source Link

Hooks are rather abstract and require you to have a working plugin/module with your own hooks setup. So before you go any further I would be sure you have a good grasp on how to use the most basic forms of hooks. It might be wise to even write a simple extension just to go through the process.

Postmaster extends ExpressionEngine's native handling of hooks. So when you install a hook via Postmaster, you a really installing specialized extension. So knowing that building Postmaster hooks is similar to extensions, this might be worth a read before you get started. http://ellislab.com/expressionengine/user-guide/development/extensions.html

Note, the process varies and end results vary dramatically from regular extensions, but the logical is very similar.

Step 1 - Create a hook

Create a hook in your plugin. It can pass any data to the hook, just know that any data you pass to the hook can be used within the Postmaster template. Below is a sample hook from my Google Maps for EE add-on. It simply allows devs to alter the POST data each time it is retrieved. In this case, call this hook would pass all the $_POST vars to the Postmaster hook.

/* -------------------------------------------
/* 'gmap_post' hook.
/*  - Modify post variables before method executes
/*  - Added v3.0 */

    $edata = $this->EE->extensions->call('gmap_post', $_POST);          
        
    if($edata !== NULL) $_POST = $edata;
        
    if ($this->EE->extensions->end_script === TRUE) return;
/*
/* -------------------------------------------*/

Step 2. Extend Postmaster's Base_hook class

Once you have your hook installed in your plugin to do pass whatever data you want, you will want to reference the Base_hook class in Postmaster. https://objectivehtml.com/postmaster/api/hooks

Base_hook allows you to extend the default functionality and inherit all the tools I have provided to make it easy for devs to build these hook. You really only need one method, and that is the trigger() method.

class Gmap_post_postmaster_hook extends Base_hook {

protected $title = 'Gmap Post';

public function __construct()
{
    parent::__construct();
}

public function trigger($_POST)
{
    // Your trigger logic
    
    $vars = array_merge($_POST, array(
        'var_1' => 'Some Value 1',
        'var_2' => 'Some Value 2',
        'var_3' => 'Some Value 3'
    ));
    
    return parent::send($vars);
}
}

It's important to note that parameter passed to the trigger() method are the same as those that you passed in your hook. So in my example, I passed one parameters, the $_POST array. You could pass as many variables as you want, and they will get passed to the trigger method in the same fashion.

Once you have created your hook's class, save it in the system/expressionengine/third_party/postmaster/hooks directory.

Step 3 - Install Hook

Once you have create your hook and have it saved, it will appear in the hooks dropdown menu. Simply select your hook from the list and create a template. Postmaster will parse all the variables you pass to the template.

Method Reference

All the method in the classes are documented in full detail in the API docs. There are A TON of underlying features and capabilities. Pretty much anything is possible. https://objectivehtml.com/postmaster/api/hooks