芝麻web文件管理V1.00
编辑当前文件:/home/ezdajrnh/www/wp-content/plugins/facebook-for-woocommerce/includes/Feed/CsvFeedFileWriter.php
get_temp_file_path(); $temp_feed_file = false; try { // phpcs:ignore -- use php file i/o functions $temp_feed_file = fopen( $temp_file_path, 'a' ); if ( false === $temp_feed_file ) { // phpcs:ignore -- Escaping function for translated string not available in this context throw new PluginException( "Unable to open temporary file {$temp_file_path} for appending.", 500 ); } // Convert the header row (CSV string) to an array to use as field accessors. $accessors = str_getcsv( $this->header_row ); // Process and write each data row. foreach ( $data as $obj ) { $row = []; foreach ( $accessors as $accessor ) { // Map each field in the row to ensure proper string conversion $value = $obj[ $accessor ] ?? ''; $row[] = $this->format_field( $value ); } if ( fputcsv( $temp_feed_file, $row, $this->delimiter, $this->enclosure, $this->escape_char ) === false ) { throw new PluginException( 'Failed to write a CSV data row.', 500 ); } } } catch ( \Exception $exception ) { Logger::log( 'Error while writing temporary feed file.', array( 'event' => 'feed_upload', 'event_type' => 'write_temp_feed_file', 'extra_data' => [ 'feed_name' => $this->feed_name, 'temp_file_path' => $temp_file_path, 'file_type' => 'csv', ], ), array( 'should_send_log_to_meta' => true, 'should_save_log_in_woocommerce' => false, 'woocommerce_log_level' => \WC_Log_Levels::DEBUG, ), $exception, ); throw $exception; } finally { if ( $temp_feed_file ) { // phpcs:ignore -- use php file i/o functions fclose( $temp_feed_file ); } } } protected function format_field( $value ) { if ( is_array( $value ) || is_object( $value ) ) { return wp_json_encode( $value ); } return $value; } }