Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.