Tribe__Tickets__Attendees::maybe_generate_csv()
Checks if the user requested a CSV export from the attendees list.
If so, generates the download and finishes the execution.
Source
File: src/Tribe/Attendees.php
public function maybe_generate_csv() {
if ( empty( $_GET['attendees_csv'] ) || empty( $_GET['attendees_csv_nonce'] ) || empty( $_GET['event_id'] ) ) {
return;
}
if ( ! wp_verify_nonce( $_GET['attendees_csv_nonce'], 'attendees_csv_nonce' ) || ! $this->user_can( 'edit_posts', $_GET['event_id'] ) ) {
return;
}
/**
* Allow for filtering and modifying the list of attendees that will be exported via CSV for a given event.
*
* @param array $items The array of attendees that will be exported in this CSV file.
* @param int $event_id The ID of the event these attendees are associated with.
*/
$items = apply_filters( 'tribe_events_tickets_attendees_csv_items', $this->generate_filtered_list( $_GET['event_id'] ), $_GET['event_id'] );
$event = get_post( $_GET['event_id'] );
if ( ! empty( $items ) ) {
$charset = get_option( 'blog_charset' );
$filename = sanitize_file_name( $event->post_title . '-' . __( 'attendees', 'event-tickets' ) );
// output headers so that the file is downloaded rather than displayed
header( "Content-Type: text/csv; charset=$charset" );
header( "Content-Disposition: attachment; filename=$filename.csv" );
// create a file pointer connected to the output stream
$output = fopen( 'php://output', 'w' );
// Get indexes by keys
$flip = array_flip( $items[0] );
$name = $flip['Customer Name'];
$email = $flip['Customer Email Address'];
//And echo the data
foreach ( $items as $item ) {
fputcsv( $output, $item );
}
fclose( $output );
exit;
}
}
Changelog
| Version | Description |
|---|---|
| 4.6.2 | Introduced. |