Skip to content

Mustash plugin development

Mark Croxton edited this page Jun 25, 2013 · 25 revisions

Mustash plugins are classes that extend the Mustash_plugin class. Plugin class names must start with Stash_ and end with _pi, and the file named accordingly.

Plugins should be placed in ./system/expressionengine/third_party/mustash/plugins/

Sample plugin

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Mustash cache-breaking plugin
 *
 * @package	Mustash
 * @author  	Mark Croxton
 */

class Stash_my_plugin_pi extends Mustash_plugin {

	/**
	 * Name
	 *
	 * @var 	string
	 * @access 	public
	 */
	public $name = 'My Plugin';

	/**
	 * Version
	 *
	 * @var 	string
	 * @access 	public
	 */
	public $version = '1.0.0';

	/**
	 * Extension hook priority
	 *
	 * @var 	integer
	 * @access 	public
	 */
	public $priority = '10';

	/**
	 * Extension hooks and associated markers
	 *
	 * @var 	array
	 * @access 	protected
	 */
	protected $hooks = array(
		'hook_1' => array(
			'marker_1',
			'marker_2',
			'marker_3',
		)
	);

	/**
	 * Constructor
	 * 
	 * @return void
	 */
	public function __construct()
	{
		parent::__construct();	
	}

	/**
	 * Get groups for this object
	 *
	 * @access	public
	 * @return	array
	 */
	public function get_groups()
	{
		return array(
		 '1' => 'Group 1',
		 '2' => 'Group 2',
		 '3' => 'Group 3',
		);
	}

	/*
	================================================================
	Hooks
	================================================================
	*/

	/**
	 * Hook: hook_1
	 *
	 * @access	public
	 * @param	integer $group_id the group ID of item that was edited
	 * @return	void
	 */
	public function hook_1($group_id)
	{
		// prep marker data
		$markers = array(
			'marker_1' 	=> $group_id,
			'marker_2'	=> '',
			'marker_3'	=> '', 
		);

		// flush cache
		$this->flush_cache(__FUNCTION__, $group_id, $markers);
	}
}

Clone this wiki locally