The wpDiscuz User Notifications addon allows you to disable notifications for specific user roles using the wpdiscuz_un_add_notification hook.
Below is an example of how the hook can be used:
add_filter('wpdiscuz_un_add_notification', function($should_add, $data) {
if (!$should_add || empty($data['recipient_id'])) {
return $should_add;
}
$recipient = get_userdata((int)$data['recipient_id']);
if (!$recipient || empty($recipient->roles)) {
return $should_add;
}
$blocked_roles = ['subscriber'];
foreach ($blocked_roles as $role) {
if (in_array($role, $recipient->roles, true)) {
return false;
}
}
return $should_add;
}, 10, 2);
Hook parameters explanation:
-
$should_add — determines whether the notification should be added to the database (true/false)
-
$data — an array containing notification details, including:
-
recipient_id — ID of the user receiving the notification
-
recipient_email — email of the recipient
-
recipient_name — display name of the recipient
-
user_id — ID of the user who triggered the action
-
user_email — email of the triggering user
-
user_name — name of the triggering user
-
user_ip — IP of the triggering user
-
item_id — post/topic ID (wpDiscuz / wpForo / BuddyPress)
-
secondary_item_id — comment ID (wpDiscuz), post ID (wpForo), or 0 for follows/ratings
-
component_name — source plugin (wpdiscuz, wpforo, bp.friends)
-
component_action — action type
-
action_date — MySQL datetime of the action
-
action_timestamp — Unix timestamp of the action
-
is_new — 1/0 unread status
-
extras — additional data such as vote direction or rating value
-
For guidance on safely adding custom PHP code to WordPress, you can refer to this article:
How to add custom code in WordPress safely
