Skip to main content

benecaster_export_sheets

Filter Free Since v1.0.0

Filters the available sheets for the “Your Data” XLSX export. Fires twice per export request: once during the UI render pass when building the sheet checkboxes in Settings > Your Data, and once during the generation pass when writing the XLSX file. During the UI render pass, `$context` date fields are empty strings.

Add-ons use this filter to register additional export sheets by pushing a sheet definition object onto `$sheets` and returning the modified array. Row data is provided separately via the [benecaster_export_sheet_rows_{sheet_id}](/hooks/benecaster_export_sheet_rows_{sheet_id}/) filter. A sheet registered here without a corresponding rows filter produces a sheet containing headers only.

Parameters

Name Type Default Description
$sheets array Ordered array of sheet objects {id: string, title: string, description: string, columns: array, add_on: string|null}
$context array Export context: {show_id: int|null, date_start: string, date_end: string}

Returns: array

Examples

Register custom donations export sheet

add_filter( 'benecaster_export_sheets', function( $sheets, $context ) {
    // Register a custom "Donations" export sheet from an add-on.
    $sheets[] = [
        'id'          => 'donations',
        'title'       => 'Donations',
        'description' => 'Listener Support donation transactions for the selected period.',
        'columns'     => [
            'date'      => 'Date',
            'email'     => 'Donor Email',
            'amount'    => 'Amount',
            'currency'  => 'Currency',
        ],
        'add_on'      => 'my-donations-addon',
    ];
    return $sheets;
}, 10, 2 );

Register sheet with add-on gate check

add_filter( 'benecaster_export_sheets', function ( array $sheets, array $context ): array {
    if ( ! benecaster_addon_is_active( 'sponsor-manager' ) ) {
        return $sheets;
    }
    $sheets[] = [
        'id'          => 'sponsor_placements',
        'title'       => 'Sponsor Placements',
        'description' => 'All sponsor placements and click data for the selected date range.',
        'columns'     => [
            'episode_id'   => 'Episode ID',
            'sponsor_name' => 'Sponsor',
            'placement'    => 'Placement',
            'clicks'       => 'Clicks',
        ],
        'add_on'      => 'sponsor-manager',
    ];
    return $sheets;
}, 10, 2 );

Notes

Built-in sheet IDs are subscribers, subscription_events, shows, and episodes. During the UI render pass $context date fields are empty strings — avoid date-dependent logic in the sheet definition itself. A registered sheet without a corresponding benecaster_export_sheet_rows_{sheet_id} filter produces a sheet with headers only and no data rows.