WC_CSV_Batch_Exporter::write_csv_data()protectedWC 3.1.0

Write data to the file.

Метод класса: WC_CSV_Batch_Exporter{}

Хуки из метода

Возвращает

null. Ничего.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->write_csv_data( $data );
$data(строка) (обязательный)
Data.

Список изменений

С версии 3.1.0 Введена.

Код WC_CSV_Batch_Exporter::write_csv_data() WC 7.3.0

protected function write_csv_data( $data ) {

	if ( ! file_exists( $this->get_file_path() ) || ! is_writeable( $this->get_file_path() ) ) {
		return false;
	}

	/**
	 * 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 );
		fclose( $fp );
	}

	// Add all columns when finished.
	if ( 100 === $this->get_percent_complete() ) {
		$header = chr( 239 ) . chr( 187 ) . chr( 191 ) . $this->export_column_headers();

		// We need to use a temporary file to store headers, this will make our life so much easier.
		@file_put_contents( $this->get_headers_row_file_path(), $header ); //phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_file_put_contents, Generic.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
	}

}