Skip to main content

benecaster_export_sheet_rows_sheet_id

Filter Free

Pattern filter that provides or filters the row data for one specific sheet in the “Your Data” XLSX export. The filter name is dynamic — {sheet_id} is replaced with the sheet’s id value as registered via benecaster_export_sheets. For example: benecaster_export_sheet_rows_subscribers, benecaster_export_sheet_rows_sponsor_placements.

Fires only during XLSX file generation (POST /export) — not during the UI render pass. Benecaster sheets (subscribers, subscription_events, shows, episodes) arrive pre-populated with rows; add-on-registered sheets arrive as an empty array that the add-on must populate. Each inner array must contain cell values in the same order as the sheet’s columns map.

Rows are re-indexed after filtering, so returning an associative or sparse array is safe. Returning a non-array yields an empty sheet rather than an error — a callback that bails early should return $rows unchanged rather than null or false.

Parameters

Name Type Default Description
$rows array Array of row arrays; each inner array is ordered cell values matching the sheet's columns
$context array Export context: {show_id: int|null, date_start: string, date_end: string}

Returns: array

Examples

Provide rows for custom donations sheet

// Provide rows for the custom "donations" sheet registered in benecaster_export_sheets.
add_filter( 'benecaster_export_sheet_rows_donations', function( $rows, $context ) {
    $donations = my_addon_get_donations( $context['show_id'], $context['date_start'], $context['date_end'] );
    foreach ( $donations as $d ) {
        $rows[] = [ $d->date, $d->email, $d->amount, $d->currency ];
    }
    return $rows;
}, 10, 2 );

Populate sponsor placements with a database query

add_filter( 'benecaster_export_sheet_rows_sponsor_placements', function ( array $rows, array $context ): array {
    // Row generation always runs with a chosen show, so unlike the
    // sheet-registration pass above there is a real context here.
    if ( ! benecaster_addon_is_active( 'sponsor-manager', (int) $context['show_id'] ) ) {
        return $rows;
    }
    global $wpdb;
    $results = $wpdb->get_results( $wpdb->prepare(
        "SELECT episode_id, sponsor_name, placement, clicks
         FROM {$wpdb->prefix}my_sponsor_placements
         WHERE placed_date BETWEEN %s AND %s",
        $context['date_start'],
        $context['date_end']
    ), ARRAY_A );

    foreach ( $results as $row ) {
        $rows[] = [ $row['episode_id'], $row['sponsor_name'], $row['placement'], (int) $row['clicks'] ];
    }
    return $rows;
}, 10, 2 );

Notes

Cell values must be in the same order as the sheet's columns map. A mismatch between the number of values per row and the column count produces misaligned cells in the XLSX file. The sheet must first be registered via benecaster_export_sheets for this filter to have any effect. Apply $context['date_start'] and $context['date_end'] (ISO 8601 strings) to time-series data; export content data such as subscribers, shows, and episodes regardless of date range.

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