loading-img

Introduction

This is the documentation for Mailwizz Hooks. Here you can find a detailed list with all the available hooks in Mailwizz, together with a description and their signature as they are used in the application.
Some hooks will be truncated because they receive too much data to be shown here, therefore we suggest always going into the source code to get all the info.

We automatically extract the actions and filters from MailWizz's source code, so you can search and find the right hook to use.

Hooks

Hooks are a way for one piece of code to interact/modify another piece of code.

There are two types of hooks: Actions and Filters.

To use either, you need to write a custom function known as a Callback, and then register it with Mailwizz hook for a specific Action or Filter.

Actions allow you to add data or change how Mailwizz operates. Callback functions for Actions will run at a specific point in in the execution of Mailwizz, and can perform some kind of a task, like echoing output to the user or inserting something into the database.

Filters give you the ability to change data during the execution of Mailwizz. Callback functions for Filters will accept a variable, modify it, and return it. They are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.

Mailwizz provides many hooks that you can use, but you can also create your own so that other developers can extend and modify the code base.

Actions are one of the two types of Hooks. They provide a way for running a function at a specific point in the execution of Mailwizz Core and extensions. They are the counterpart to Filters.

Add Action 

The process of adding an action includes two steps. First, you need to create a Callback function which will be called when the action is run. Second, you need to add your Callback function to a hook which will perform the calling of the function. You will use the addAction() function, passing at least two parameters, string $tagcallable $callback.
Yii::app()->hooks->addAction('console_command_daily', array($this, '_runBackup'), 1000);
This will add an action called 'console_command_daily', that will execute the method '_runBackup' of the class where the action was added.

Do Action

To trigger an action use the doAction($tag, $arg = null), where $tag is the action name and $arg possible arguments to that will be used by the callback. For the above added action, the following code will trigger the callback execution:
Yii::app()->hooks->doAction('console_command_daily', $this);
Filters are one of the two types of Hooks. They provide a way for functions to modify data of other functions. They are the counterpart to Actions. Unlike actions, filters are meant to work in an isolated manner, and should never have side effects such as affecting global variables and output.

Add Filter 

The process of adding a filter includes two steps. First, you need to create a Callback function which will be called when the filter is run. Second, you need to add your Callback function to a hook which will perform the calling of the function. To add a filter to an existing tag, you will use the
Yii::app()->hooks->addFilter($tag, $callback, $priority = 10)
function, passing at least two parameters, string $tagcallable $callback. Example: The following code will add a filter to the 'backend_left_navigation_menu_items' tag, that will execute the method of the class where this filter was added, named '_registerBackendMenuItem'.
// add the menu item
Yii::app()->hooks->addFilter('backend_left_navigation_menu_items', array($this, '_registerBackendMenuItem'))

Apply Filter

To apply a filter use applyFilters($tag, $arg) function, passing as parameters the filter name and the variable that we want to filter For the above added filter you will apply it using the following code at the place needed:
$menuItems = (array)Yii::app()->hooks->applyFilters('backend_left_navigation_menu_items', $menuItems);