-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Hi,
as I see in documentation page (https://docs.bracketspace.com/notification/developer/notifications/programmatic-notifications) I would like to add a notification (with email carrier) by code, not using WP (admin) > Notifications > Add New Notification.
I have already registered in function.php my custom trigger with:
add_action( 'notification/elements', function() {
require_once ( 'class-my-trigger.php' );
notification_register_trigger( new MyCustomTrigger() );
});
Now, I would like to associate it to a custom notification declared in function.php. Using the sample in (https://docs.bracketspace.com/notification/developer/notifications/programmatic-notifications) I would expect to see my new notification in the list of WP notification setting page (as it happen adding custom triggers that I can associate to my notifications) but it doesn't.
In particular I tried this code:
add_action( 'notification/trigger/registered', function( $trigger ) {
if ( 'post/updated' !== $trigger->get_slug() ) {
return;
}
$content = '';
foreach ( $trigger->get_merge_tags( 'visible' ) as $merge_tag ) {
$content .= $merge_tag->get_name() . ': {' . $merge_tag->get_slug() . '}' . "\r\n\r\n";
}
notification( [
'title' => 'My programmatic notification',
'trigger' => 'trigger_slug',
'carriers' => [
'email' => [
'activated' => true,
'enabled' => true,
'subject' => 'Email from ghost notification!',
'body' => 'This is nice, huh?',
'recipients' => [
[
'type' => 'role',
'recipient' => 'administrator',
],
],
],
],
'enabled' => true,
] );
} );
Thank you.
Greeting,
Enzo