Function Reference: geodir_save_csv_data

Summary

Save the data in CSV file to export.

Global Values

$wp_filesystem
(null|object) (required) WP_Filesystem object.

Default: None

Package

GeoDirectory

Parameters

$file_path
(string) (required) Full path to file.

Default: None
$csv_data
(array) (required) Array of csv data.

Default: None
$clear
(bool) (required) If true then it overwrite data otherwise add rows at the end of file.

Default: None

Return Values

(bool)
  • true if success otherwise false.

Change Log

Since: 1.4.6

Source File

geodir_save_csv_data() is located in geodirectory-admin/admin_functions.php [Line: 5718]

Source Code

function geodir_save_csv_data( $file_path, $csv_data = array(), $clear = true ) {
	if ( empty( $csv_data ) ) {
		return false;
	}
	
	global $wp_filesystem;
	
	$mode = $clear ? 'w+' : 'a+';
	
	if ( function_exists( 'fputcsv' ) ) {
		$file = fopen( $file_path, $mode );
		foreach( $csv_data as $csv_row ) {
			//$csv_row = array_map( 'utf8_decode', $csv_row );
			$write_successful = fputcsv( $file, $csv_row, ",", $enclosure = '"' );
		}
		fclose( $file );
	} else {
		foreach( $csv_data as $csv_row ) {
			//$csv_row = array_map( 'utf8_decode', $csv_row );
			$wp_filesystem->put_contents( $file_path, $csv_row );
		}
	}
		
	return true;
}