Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion classes/Visualizer/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,15 @@ private function _getCSV( $rows, $filename, $enclose ) {
$bom = chr( 0xEF ) . chr( 0xBB ) . chr( 0xBF );
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$fp = function_exists( 'tmpfile' ) ? @tmpfile() : null;
if ( null === $fp ) {
if ( ! $fp ) {
if ( ! function_exists( 'wp_tempnam' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
$fp = fopen( wp_tempnam(), 'w+' );
}
if ( ! $fp ) {
return array( 'csv' => '', 'name' => $filename, 'string' => '' );
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_getCSV() now returns a non-empty array even when it cannot obtain a writable temp file handle. Because callers (e.g. the AJAX export handler) typically treat any non-empty return value as success, this can result in success: true responses with an empty CSV payload, which is misleading and makes failures harder to detect. Consider returning null/false on file-handle failure (or including an explicit error indicator) so the export endpoint can fail gracefully (e.g. send a JSON error) instead of reporting success with empty data.

Suggested change
return array( 'csv' => '', 'name' => $filename, 'string' => '' );
return null;

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, do we have a handler that works with an empty string property? Or they just download an empty file?

}
if ( ! apply_filters( 'vizualizer_export_include_series_type', true ) ) {
unset( $rows[1] );
$rows = array_values( $rows );
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"phpcompatibility/phpcompatibility-wp": "*",
"phpstan/phpstan": "^2.1",
"szepeviktor/phpstan-wordpress": "^2.0"
"szepeviktor/phpstan-wordpress": "^2.0",
"yoast/phpunit-polyfills": "^4.0"
}
}
Loading
Loading