Skip to main content

Append, hide, or reorder a subscriber’s badges per show

Free Intermediate Since v1.0.0

Badges are assembled from tier assignments and manual grants, then passed through benecaster_user_badges before rendering. Hook into this filter to change what a subscriber sees — hide a badge on a specific show, inject badges from an external system like a forum or community platform, or reorder the set for display priority.

Each item in $badges is an object with label, icon_slug, icon_attachment_id, color, source, granted_at, and granted_by. Synthetic rows you inject should match this shape. The $show_id parameter lets you scope changes per show without affecting badge storage, which is site-wide.

Code

<?php
add_filter( 'benecaster_user_badges', function ( array $badges, int $user_id, ?int $show_id ): array {
    // Hide a specific badge from public-facing display on one show.
    if ( $show_id === 42 ) {
        $badges = array_values( array_filter(
            $badges,
            fn( $row ) => $row->label !== 'Internal Tester'
        ) );
    }

    // Append a synthetic badge sourced from an add-on (e.g. forum reputation).
    $badges[] = (object) [
        'label'     => sprintf( 'Reputation: %d', my_forum_get_reputation( $user_id ) ),
        'icon_slug' => 'star',
        'color'     => '#FFD700',
        'source'    => 'manual',
    ];

    return $badges;
}, 10, 3 );

View on GitHub →

Hooks Used

  • benecaster_user_badges