Jump to Content

Objective HTML

Postmaster

The definitive email solution for ExpressionEngine

Tasks API

Overview

The Base Task class is the class from which all other tasks are extended. To add your own tasks, create a class that extends the Task_hook class. The basic principle here is to be able to do anything you want that is different than "sending email". Tasks don't have contents like Parcels, Hooks, and Notifications. Tasks are meant to bridge the gap of tasks that blur the lines of sending email. So for instance, auto-subscribing members to email campaigns after hooks have been triggered is a perfect scenario for a task.

Tasks Directory
/system/expressionengine/third_party/postmaster/tasks
Class Suffix
_postmaster_task

Example


class Your_task_name_postmaster_task extends Base_task {
	
	protected $title = 'Your Task Name';

    // If need a CRON job, set to TRUE
	protected $enable_cron = TRUE;

	// If need to use hooks, create them here and Postmaster will install them automatically
	protected $hooks = array(
		array(
			'method' 	=> 'your_hook_method',
			'hook'   	=> 'some_hook_name',
			'priority'	=> 10
		),
		array(
			'method' 	=> 'your_hook_method_2',
			'hook'   	=> 'some_hook_name_2',
			'priority'	=> 10
		)
	);
	
	// If you need an interface of settings for your task, create the InterfaceBuilder array here
	protected $fields = array(
		'first_name_field' => array(
			'label'       => 'First Name Field',
			'description' => 'This is the name of the member field that stores the member\'s first name. If defined, the value will be used for the subscribers.'
		),
		'last_name_field' => array(
			'label'       => 'Last Name Field',
			'description' => 'This is the name of the member field that stores the member\'s last name. If defined, the value will be used for the subscribers.'
		)
	);
	
	public function your_hook_method()
	{
		// Do something for the 'some_hook_name' hook
	}

	public function your_hook_method_2()
	{
		
		// Do something for the 'some_hook_name_2' hook
	}

	public function trigger_cron()
	{
		// Do something for the cron job
	}
}

This a simple example. None of these method are required and will still work if you don't replace them.

Properties

$hook
Actual EE hook name to use
$responses
An array of service response objects

Extends

Postmaster Base API

Methods

Note, the tasks API does not currently utilize the parse(), send(), pre_process(), or post_process() methods. If you need those methods, it's likely that the Tasks API is not the right tool for the job.

display_settings($settings)

The display_settings method accepts an array to use for the the settings data. The settings property will be used for the settings schema.

$settings
An associative array of settings and values.
Return

(string) HTML Table of Settings

get_task()

Get the name of the task (if different than the name property, for whatever reason).

Return

(string) The task name