Skip to main content

Add a custom icon to the per-tier badge picker

Premium Beginner

Tier badges are picked from a set of built-in icons — a crown, a star, a microphone. benecaster_badge_icons lets an add-on add its own to that picker, so a badge it defines looks like part of the product rather than an exception.

Draw the icon so it takes its colour from its surroundings rather than specifying one. Each badge chip has a podcaster-chosen accent colour, and an icon with a colour baked into it ignores that choice and clashes with every chip it is placed on.

An incomplete entry is dropped without complaint. An icon missing any of its required parts simply never appears in the picker — no error, no warning, nothing in the log. If yours does not show up, that is the first thing to check.

Removing an icon later is safe. Badges already using it keep working and render with their label and colour, just without the glyph — so an add-on being deactivated degrades a badge rather than breaking it.

Code

<?php
add_filter( 'benecaster_badge_icons', function ( array $icons ): array {
    $icons['rocket'] = [
        'slug'  => 'rocket',
        'label' => __( 'Rocket', 'my-addon' ),
        'svg'   => '<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><path d="M..."/></svg>',
    ];
    return $icons;
} );

View on GitHub →

Hooks Used

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