Added a filter to set fopen mode for streams that dont support a+ (#33652)

Added a filter to set fopen mode for streams that dont support a+

Co-authored-by: barryhughes <3594411+barryhughes@users.noreply.github.com>
This commit is contained in:
Matthew Hodge 2022-06-30 19:34:02 +02:00 committed by GitHub
parent 3fc11126a4
commit 6cb6fd02df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: tweak
The file writing mode used during CSV exports is now filterable via new hook `woocommerce_csv_exporter_fopen_mode`.

View File

@ -130,7 +130,18 @@ abstract class WC_CSV_Batch_Exporter extends WC_CSV_Exporter {
return false;
}
$fp = fopen( $this->get_file_path(), 'a+' );
/**
* Filters the mode parameter which specifies the type of access you require to the stream (used during file
* writing for CSV exports). Defaults to 'a+' (which supports both reading and writing, and places the file
* pointer at the end of the file).
*
* @see https://www.php.net/manual/en/function.fopen.php
* @since 6.8.0
*
* @param string $fopen_mode, either (r, r+, w, w+, a, a+, x, x+, c, c+, e)
*/
$fopen_mode = apply_filters( 'woocommerce_csv_exporter_fopen_mode', 'a+' );
$fp = fopen( $this->get_file_path(), $fopen_mode );
if ( $fp ) {
fwrite( $fp, $data );