Skip to main content

Inject a synthetic reference group from an add-on

Free Intermediate Since v1.0.0

Prepend or append reference groups managed outside the database — for example, the Outlinks add-on can inject a “Tracked Links” group without storing it in benecaster_reference_groups. Synthetic groups use id: 0 to distinguish them from real DB rows. The template buckets reference entries by group_id; entries with group_id = null or an unrecognised ID fall under a configurable fallback heading.

Code

<?php
add_filter( 'benecaster_reference_groups', function ( array $groups, int $show_id ): array {
    if ( ! my_addon_is_active_for_show( $show_id ) ) {
        return $groups;
    }
    array_unshift( $groups, [
        'id'            => 0,
        'name'          => __( 'Tracked Links', 'my-addon' ),
        'display_order' => -1,
    ] );
    return $groups;
}, 10, 2 );

View on GitHub →

Hooks Used