miniCal
  • Quick Start
    • Introduction
  • miniCal Configuration
    • miniCal Hosted Service
    • Configure Feature Settings
    • Install Extensions
    • Create Multiple Properties
  • Local Installation
    • Local Installation
    • ENV Set-Up
    • Configuration Settings
    • Common Installations Errors
  • Contribution
    • Contribute to miniCal Core
  • Build an Extension
    • Build Your First Extension
      • Controllers
      • Assets
      • Config
      • language
      • Models
      • View
      • Helper
      • Library
      • Hooks
    • Open-source Extensions
    • Config Folder Files
      • Autoload File
      • Config File
      • Route File
    • miniCal Filters
    • miniCal Actions
    • Create Custom Hooks
    • Store Custom Data
      • POSTS
      • POSTMETA
      • OPTIONS
    • Composer Dependencies
  • Marketplace
    • miniCal Marketplace
  • Other resources
    • Overbooking for OTAs
    • miniCal Cron Setup
    • Automated Night Audit
    • Nginx Configuration
    • Docker Installation
    • Custom Domain Setup
  • Minical API Docs
    • API Documentation
  • Coming soon!
    • Access minical Data Using Helpers
      • Company Helper Functions
      • Customer Helper Functions
      • Booking Helper Functions
      • Rates Helper Functions
      • Rate Plan Helper Functions
      • Availability Helper Functions
      • Statement Helper Functions
      • Tax Helper Functions
      • Room Helper Functions
      • Charge Helper Functions
      • Payment Helper Functions
    • Access data in Extension
Powered by GitBook
On this page
  • How to Create a Hook
  • Add a Callback to the Hook
  • Naming Conflicts
  • Examples
  • Extensible Action: Add Custom Field
  • Extensible Filter: Customer Type
  1. Build an Extension

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' );
?>
PreviousminiCal ActionsNextStore Custom Data

Last updated 3 years ago