Skip to main content
Version: v6

Programmatic Notifications

You can create and send notifications programmatically using PHP code.

Creating notifications via code​

// Create a new notification
$notification = new \BracketSpace\Notification\Defaults\Notification();
$notification->set_title('My Custom Notification');
$notification->set_trigger('post_published');

// Add email carrier
$email_carrier = new \BracketSpace\Notification\Defaults\Carrier\Email();
$email_carrier->set_field('recipients', ['[email protected]']);
$email_carrier->set_field('subject', 'New post published');
$email_carrier->set_field('body', 'Post {post_title} has been published');

$notification->add_carrier($email_carrier);

Sending notifications manually​

You can also trigger notifications manually for specific events:

// Trigger a notification
do_action('notification/trigger', 'post_published', $post);