Forked from ForGravity/fg_entryautomation_after_export.php
Created
August 15, 2019 23:54
-
-
Save travislopes/a7ac3149c29962d2ee40b204bd0daaa8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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