Create Custom Hooks

Create New Actions/filters hooks

Custom hooks are created and called in the same way that miniCal Core hooks are.

How to Create a Hook

To create a custom hook, use do_action() for Actions and apply_filters() for Filters.

Add a Callback to the Hook

To add a callback function to a custom hook, use add_action() for Actions and add_filter() for Filters.

Naming Conflicts

Since any extension can create a custom hook, it’s important to prefix your hook names to avoid collisions with other extensions.

For example, the function extension_name_email_body_editor (where extension_name_ is a unique prefix for your extension) would avoid any collisions.

Examples

Extensible Action: Add Custom Field

Extension Name: Custom Field (customfield)

If your extension adds a custom field to a form, you can use Actions to allow other extensions to add their own settings to it.

<?php
    do_action( 'customfield_after_adding_field' );
?>

Now another extension can register a callback function for the customfield_after_adding_field hook and inject new settings:

<?php
    add_action( 'customfield_after_adding_field', 'callback_function' );
?>

Extensible Filter: Customer Type

Extension Name: Custom Type (customtype)

In this example, when the new customer is registered, the parameters that define it are passed through a filter, so another extension can change them before the customer is created.

<?php
  apply_filters( 'customtype_customer_type', $params )
?>
<?php 
  add_filter( 'customtype_customer_type', 'callback_functionhp' );
?>

Last updated