WooCommerce Code Reference

WC_CSV_Batch_Exporter extends WC_CSV_Exporter
in package

WC_CSV_Exporter Class.

Table of Contents

$column_names  : array
Columns ids and names.
$columns_to_export  : array
List of columns to export, or empty for all.
$delimiter  : string
The delimiter parameter sets the field delimiter (one character only).
$export_type  : string
Type of export used in filter names.
$exported_row_count  : int
Number exported.
$filename  : string
Filename to export to.
$limit  : int
Batch limit.
$page  : int
Page being exported
$row_data  : array
Raw data to export.
$total_rows  : int
Total rows to export.
__construct()  : mixed
Constructor.
escape_data()  : string
Escape a string to be used in a CSV context
export()  : mixed
Serve the file and remove once sent to the client.
format_data()  : string
Format and escape data ready for the CSV file.
format_term_ids()  : string
Format term ids to names.
generate_file()  : mixed
Generate the CSV file.
get_column_names()  : array
Return an array of supported column names and ids.
get_columns_to_export()  : array
Return an array of columns to export.
get_default_column_names()  : array
Return default columns.
get_delimiter()  : string
Return the delimiter to use in CSV file
get_file()  : string
Get the file contents.
get_filename()  : string
Generate and return a filename.
get_limit()  : int
Get batch limit.
get_page()  : int
Get page.
get_percent_complete()  : int
Get total % complete.
get_total_exported()  : int
Get count of records exported.
is_column_exporting()  : bool
See if a column is to be exported or not.
prepare_data_to_export()  : mixed
Prepare data that will be exported.
send_content()  : mixed
Set the export content.
send_headers()  : mixed
Set the export headers.
set_column_names()  : mixed
Set column names.
set_columns_to_export()  : mixed
Set columns to export.
set_filename()  : mixed
Set filename to export to.
set_limit()  : mixed
Set batch limit.
set_page()  : mixed
Set page.
export_column_headers()  : string
Export column headers in CSV format.
export_row()  : mixed
Export rows to an array ready for the CSV.
export_rows()  : string
Export rows in CSV format.
fputcsv()  : mixed
Write to the CSV file, ensuring escaping works across versions of PHP.
get_csv_data()  : string
Get CSV data for this export.
get_data_to_export()  : array
Get data that will be exported.
get_file_path()  : string
Get file path to export to.
implode_values()  : string
Implode CSV cell values using commas by default, and wrapping values which contain the separator.
write_csv_data()  : mixed
Write data to the file.

Properties

Methods

escape_data()

Escape a string to be used in a CSV context

public escape_data(string $data) : string

Malicious input can inject formulas into CSV files, opening up the possibility for phishing attacks and disclosure of sensitive information.

Additionally, Excel exposes the ability to launch arbitrary commands through the DDE protocol.

Parameters
$data : string

CSV field to escape.

Tags
see
http://www.contextis.com/resources/blog/comma-separated-vulnerabilities/
see
https://hackerone.com/reports/72785
since
3.1.0
Return values
string

format_data()

Format and escape data ready for the CSV file.

public format_data(string $data) : string
Parameters
$data : string

Data to format.

Tags
since
3.1.0
Return values
string

format_term_ids()

Format term ids to names.

public format_term_ids(array $term_ids, string $taxonomy) : string
Parameters
$term_ids : array

Term IDs to format.

$taxonomy : string

Taxonomy name.

Tags
since
3.1.0
Return values
string

is_column_exporting()

See if a column is to be exported or not.

public is_column_exporting(string $column_id) : bool
Parameters
$column_id : string

ID of the column being exported.

Tags
since
3.1.0
Return values
bool

send_content()

Set the export content.

public send_content(string $csv_data) : mixed
Parameters
$csv_data : string

All CSV content.

Tags
since
3.1.0
Return values
mixed

set_column_names()

Set column names.

public set_column_names(array $column_names) : mixed
Parameters
$column_names : array

Column names array.

Tags
since
3.1.0
Return values
mixed

set_columns_to_export()

Set columns to export.

public set_columns_to_export(array $columns) : mixed
Parameters
$columns : array

Columns array.

Tags
since
3.1.0
Return values
mixed

export_row()

Export rows to an array ready for the CSV.

protected export_row(array $row_data, string $key, resource $buffer) : mixed
Parameters
$row_data : array

Data to export.

$key : string

Column being exported.

$buffer : resource

Output buffer.

Tags
since
3.1.0
Return values
mixed

fputcsv()

Write to the CSV file, ensuring escaping works across versions of PHP.

protected fputcsv(resource $buffer, array $export_row) : mixed

PHP 5.5.4 uses '\' as the default escape character. This is not RFC-4180 compliant. \0 disables the escape character.

Parameters
$buffer : resource

Resource we are writing to.

$export_row : array

Row to export.

Tags
see
https://bugs.php.net/bug.php?id=43225
see
https://bugs.php.net/bug.php?id=50686
see
https://github.com/woocommerce/woocommerce/issues/19514
see
https://github.com/woocommerce/woocommerce/issues/24579
since
3.4.0
since
3.9.0
Return values
mixed

implode_values()

Implode CSV cell values using commas by default, and wrapping values which contain the separator.

protected implode_values(array $values) : string
Parameters
$values : array

Values to implode.

Tags
since
3.2.0
Return values
string