Help Center
Find answers or browse our knowledge base.
Latest Questions
post_notification
๐ Hook: post_notification
Overview
The post_notification hook lets add-ons customize notifications before they are displayed to users. It is triggered every time a new notification is created, giving you full control over the icon, URL, and message.
// Inside traits/notifications.php
/* ---- ScriptsTribe Hook for notifications ---- */
$notification = apply_filters('post_notification', $notification, $args);
๐ Hook File Placement
Place your handler file inside your addon:
modules//hooks/post_notification.php
The file must return a callable closure that receives $notification and $args, then returns the modified notification.
Arguments
$notification(array) – Includesaction,node_type,node_url,icon,url,message$args(array) – Extra parameters, usually not required
Return
Return the modified $notification array. If unchanged, just return it as is.
โ Example: Customize Book Notifications
This addon example transforms a book_finished notification into a user-friendly message, pulling the book title and slug from the database.
query(sprintf(
"SELECT title, slug FROM books WHERE id = %s",
secure($book_id, 'int')
));
if ($get && $get->num_rows > 0) {
$row = $get->fetch_assoc();
$title = $row['title'] ?: $title;
$slug = $row['slug'] ?: $slug;
}
// Customize
$notification['icon'] = "fa fa-book";
$notification['url'] = $system['system_url'] . '/books/view/' . $slug;
$notification['message'] = __("Just finished reading ") . $title;
}
return $notification;
};
Other Use Cases
- Change or translate messages for custom actions
- Add unique icons and URLs for your addon content
- Suppress notifications (return
null)
๐ Flow
- Trigger: An addon calls
$user->post_notification([...]) - Hook:
post_notificationfires, your hook file runs - Render: Modified notification is displayed to the user
With this hook, you never need to touch traits/notifications.php again — simply drop your logic inside hooks/post_notification.php.
Was this answer helpful?
How could it be better?
What went wrong?