Skip to main content

benecaster_before_notice_display

Filter Free

Filters each admin notice immediately before it is included in the notices REST response. Fires once per display context — once for 'bell' and again for 'bar' when a notice has display_mode = 'both'. Return the $notice array to include it, optionally modified, or return null or false to suppress it from that context.

For notices with display_mode = 'both', the filter fires twice in sequence. The second call receives the $notice array as returned by the first, so modifications made in the bell context are visible during the bar context call. The filter runs after the user’s minimum-tier preference is applied — notices already filtered out by tier are not passed to this hook.

Parameters

Name Type Default Description
$notice array Notice data array
$context string Display context: 'bell' or 'bar'

Returns: array|null|false

Examples

Suppress all notices from the admin bar

add_filter( 'benecaster_before_notice_display', function( $notice, $context ) {
    if ( 'bar' === $context ) {
        return null;
    }
    return $notice;
}, 10, 2 );

Suppress marketing notices from the bar only

add_filter(
    'benecaster_before_notice_display',
    function ( array $notice, string $context ): ?array {
        if ( 'marketing' === $notice['tier'] && 'bar' === $context ) {
            return null; // Keep in bell panel, never in the bar.
        }
        return $notice;
    },
    10, 2
);

Override action label for a specific notice

add_filter(
    'benecaster_before_notice_display',
    function ( array $notice, string $context ): array {
        if ( 'feed_sync_failures' === $notice['notice_id'] && 'bar' === $context ) {
            $notice['action_label'] = __( 'Fix now', 'my-addon' );
        }
        return $notice;
    },
    10, 2
);

Suppress a notice when an add-on handles it

add_filter(
    'benecaster_before_notice_display',
    function ( array $notice, string $context ): ?array {
        if ( 'setup_wizard_nag' === $notice['notice_id'] && my_addon_wizard_complete() ) {
            return null;
        }
        return $notice;
    },
    10, 2
);

Notes

Suppressing a notice from one context downgrades its display mode rather than hiding it entirely. If you suppress 'bar' but allow 'bell', the response includes the notice with display_mode = 'bell'.

Affects

  • GET /benecaster/v1/notices REST response

Need this built rather than just documented? See our services →