Modify or suppress an admin notice per display context immediately before it reaches the React app
Runs from NoticesController::get_notices() once per display context (bell and/or bar) a notice would appear in. Return the array (modified or unchanged) to keep the notice, or return null/false to suppress it in that context. For a display_mode='both' notice, the filter fires twice; suppressing one context but not the other yields the surviving context as the notice’s display_mode. The filter runs after the user’s minimum-tier preference has already filtered rows — use it for contextual/add-on-state-aware suppression, not severity preferences.
Code
<?php
add_filter(
'benecaster_before_notice_display',
function ( array $notice, string $context ): ?array {
// Hide marketing notices from the persistent bar — keep them in the bell panel only.
if ( 'marketing' === $notice['type'] && 'bar' === $context ) {
return null;
}
// Rewrite the action label of a specific notice when shown in the bar
// so the CTA fits on one line, while keeping the original copy in the bell.
if ( 'feed_sync_failures' === $notice['notice_id'] && 'bar' === $context ) {
$notice['action_label'] = __( 'Fix now', 'my-addon' );
}
return $notice;
},
10,
2
);