# Create Custom 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 <mark style="color:blue;">do\_action()</mark> for Actions and <mark style="color:blue;">apply\_filters()</mark> for Filters.

### **Add a Callback to the Hook**&#x20;

To add a callback function to a custom hook, use <mark style="color:blue;">add\_action()</mark> for Actions and <mark style="color:blue;">add\_filter()</mark> 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 <mark style="color:blue;">extension\_name\_email\_body\_editor</mark> (where <mark style="color:blue;">extension\_name\_</mark> 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
<?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
<?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.<br>

```php
<?php
  apply_filters( 'customtype_customer_type', $params )
?>
```

```php
<?php 
  add_filter( 'customtype_customer_type', 'callback_functionhp' );
?>
```
