How to Suppress WordPress Notifications Conditionally
WordPress notification suppression enables developers to conditionally disable entire notifications using filters and custom logic. This approach is ideal for testing specific notifications or implementing complex conditional notification delivery based on user data, settings, or environmental factors.
To do this, you should use the filter:
add_filter(
'notification/should_send',
function($shouldSend, $notification, $trigger) {
if ($something) {
$should_send = false;
}
return $should_send;
},
10,
3
);
danger
At this point, the Trigger doesn't execute the context() method so you cannot use the Merge Tags. If you rely on Merge Tags, suppress the Carrier instead.