Automattic\WooCommerce\Admin
ReportExporter::get_requested_export
Build the exporter a download request is asking for.
A read-only download of a report the requesting user is already allowed to view, gated on the view_woocommerce_reports capability, so a nonce would only prevent nuisance CSRF. The action is compared verbatim against a fixed name, and set_filename() applies sanitize_file_name(), which keeps the path inside the reports directory. A nonce is not an option here either: nonces last 24 hours, and this link is emailed and kept for a week.
Method of the class: ReportExporter{}
No Hooks.
Returns
ReportCSVExporter|null. The exporter for the requested export, or null when the request asks for no export.
Usage
$result = ReportExporter::get_requested_export( $request );
- $request(array) (required)
- Unslashed request parameters, expected to be
$_GET.
ReportExporter::get_requested_export() ReportExporter::get requested export code WC 11.2.1
private static function get_requested_export( $request ) {
if (
! is_array( $request ) ||
! isset( $request['action'] ) ||
self::DOWNLOAD_EXPORT_ACTION !== $request['action'] ||
empty( $request['filename'] ) ||
! is_string( $request['filename'] ) ||
! current_user_can( 'view_woocommerce_reports' )
) {
return null;
}
$exporter = new ReportCSVExporter();
$exporter->set_filename( $request['filename'] );
// The stored name only identifies the export, so the emailed link carries the report's date
// range to name the download after the period it covers. It never reaches the file path.
if ( ! empty( $request['date_range'] ) && is_string( $request['date_range'] ) ) {
$exporter->set_download_suffix( $request['date_range'] );
}
return $exporter;
}