Skip to main content

Post-process a multi-tier assembled feed as a whole

Free Intermediate Since v1.0.0

benecaster_feed_xml fires at two call sites: once per tier inside FeedCompiler::compile() and once in FeedAssembler::assemble() after all tiers are merged. This recipe demonstrates how to target only the assembled multi-tier call site (when the third arg is an array) to inject a custom XML comment or namespace declaration into the final combined document.

Code

<?php
add_filter( 'benecaster_feed_xml', function ( string $xml, int $show_id, string|array $tier_arg ): string {
    // Only act on the assembled multi-tier feed.
    if ( ! is_array( $tier_arg ) ) {
        return $xml;
    }

    // Example: insert a custom channel element after <channel>.
    $badge = '<!-- Assembled from tiers: ' . implode( ', ', $tier_arg ) . ' -->';
    return str_replace( '<channel>', '<channel>' . $badge, $xml );
}, 10, 3 );

View on GitHub →

Hooks Used