Skip to main content

Modify or suppress an admin notice per display context immediately before it reaches the React app

Premium Intermediate

Benecaster shows notices in two places: the bell panel in the corner of the admin, and the banner across the top of the screen. The same notice can appear in either or both. This filter lets an add-on change a notice — or hide it altogether — separately for each place.

That separation is the point. A warning can be worth a quiet entry in the bell panel without being worth a banner across every screen, and this is where you make that distinction.

When to Use This

Use it for suppression that depends on context your add-on knows about — a notice that is redundant because your own settings screen already says the same thing, or one that does not apply to how this particular site is configured.

Do not use it to express “only show me serious warnings.” Podcasters already have a severity preference of their own, and it has been applied before this filter runs. Rebuilding it here overrides a choice the podcaster made deliberately.

Each Place Is Asked Separately

A notice set to appear in both places is passed to your filter twice, once for each. You can keep it in one and drop it from the other — hide it from the banner, leave it in the bell panel — and it simply becomes a notice that shows in the surviving place only.

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
);

View on GitHub →

Hooks Used

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