Programmatic Notifications
The notifications doesn't necessarly have to be saved in WordPress database nor loaded from JSON files. A good example is dynamic trigger testing where all the notifications are created on the fly.

Basic example

You can define the notification with a simple array. Below is a minimal example with all the required parameters.
1
if ( function_exists( 'notification' ) ) :
2
notification( [
3
'title' => 'My programmatic notification', // For internal reference.
4
'trigger' => 'trigger_slug', // Trigger slug (can be a Triggerable object).
5
'carriers' => [ // An array with format: carrier_slug => data array
6
'email' => [
7
'activated' => true, // Must be true.
8
'enabled' => true, // Must be true.
9
'subject' => 'Email from ghost notification!',
10
'body' => 'This is nice, {user_first_name}, huh?',
11
'recipients' => [
12
[
13
'type' => 'administrator',
14
'recipient' => '',
15
],
16
[
17
'type' => 'email',
18
'recipient' => '{user_email}',
19
],
20
],
21
],
22
],
23
'enabled' => true, // Must be true.
24
] );
25
endif;
Copied!
You can reference the Carrier fields by checking the source code. You should check the add_form_field method calls which will contain the field slug and other useful info about the type.

All arguments

All arguments available:
1
if ( function_exists( 'notification' ) ) :
2
notification( [
3
'hash' => 'my_programmatic_notification', // Unique notification hash, automatically generated.
4
'title' => 'My programmatic notification',
5
'trigger' => 'trigger_slug',
6
'carriers' => [
7
'email' => [
8
'activated' => true,
9
'enabled' => true,
10
'subject' => 'Email from ghost notification!',
11
'body' => 'This is nice, {user_first_name}, huh?',
12
'recipients' => [
13
[
14
'type' => 'administrator',
15
'recipient' => '',
16
],
17
[
18
'type' => 'email',
19
'recipient' => '{user_email}',
20
],
21
],
22
],
23
],
24
'enabled' => true,
25
'extras' => [], // Extra data array, ie. config for add-ons.
26
'version' => time(), // Version of the notification, should be a timestamp. Default: current time.
27
] );
28
endif;
Copied!
Last modified 11d ago