Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save travislopes/a7ac3149c29962d2ee40b204bd0daaa8 to your computer and use it in GitHub Desktop.
Save travislopes/a7ac3149c29962d2ee40b204bd0daaa8 to your computer and use it in GitHub Desktop.
<?php
add_action( 'fg_entryautomation_after_export', 'fg_entryautomation_remove_header_row', 10, 3 );
/**
* Remove header line from generated CSV export file.
*
* @param array $task The current Entry Automation task's settings.
* @param array $form The current Form object.
* @param string $file_path File path of export file.
*/
function fg_entryautomation_remove_header_row( $task, $form, $file_path ) {
// If this is not a CSV export, return.
if ( rgar( $task, 'exportFileType' ) !== 'csv' ) {
return;
}
// Get the file.
$file = file( $file_path, FILE_SKIP_EMPTY_LINES );
// Remove the first line.
unset( $file[0] );
// Remove empty items.
$file = array_map( 'trim', $file );
$file = array_filter( $file );
// Convert file back to string.
$file = implode( PHP_EOL, $file );
// Save file.
file_put_contents( $file_path, $file );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment