Automattic\WooCommerce\Admin

ReportExporter::download_export_file │ public static │ WC 1.0

Serve the export file.

Method of the class: ReportExporter{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ReportExporter::download_export_file();

ReportExporter::download_export_file() code WC 11.2.1

public static function download_export_file() {
	// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Read in get_requested_export(), which documents why there is no nonce and validates every value it reads.
	$exporter = self::get_requested_export( wp_unslash( $_GET ) );

	if ( ! $exporter ) {
		return;
	}

	// Say so rather than serving an empty CSV: the exporter creates a blank file for a path
	// that no longer exists, which reads as a report with no results.
	if ( ! $exporter->export_file_exists() ) {
		wp_die(
			esc_html(
				sprintf(
					/* translators: %s: length of time an export is kept, e.g. "1 week". */
					__( 'This report export is no longer available. Exports are kept for %s, so please request a new one.', 'woocommerce' ),
					human_time_diff( 0, self::EXPORT_RETENTION_PERIOD )
				)
			),
			esc_html__( 'Report export unavailable', 'woocommerce' ),
			array( 'response' => 404 )
		);
	}

	$exporter->send_headers();
	$exporter->stream_export_file();
	exit;
}