Skip to content

Commit fda1ee1

Browse files
authored
Merge pull request #11 from ibrahimlawal/hotfix/addcsvquotes
Add quotes to CSV items when exporting
2 parents fd747c1 + abebc19 commit fda1ee1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

admin/class-paystack-forms-admin.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ function kkd_pff_paystack_payment_submissions(){
636636
}
637637
add_action( 'admin_post_kkd_pff_export_excel', 'Kkd_pff_export_excel' );
638638

639+
function Kkd_pff_prep_csv_data($item){
640+
return '"'.str_replace('"', '""', $item).'"';
641+
}
642+
639643
function Kkd_pff_export_excel() {
640644
global $wpdb;
641645

@@ -659,12 +663,12 @@ function Kkd_pff_export_excel() {
659663
$text = '';
660664
if (array_key_exists("0", $new)) {
661665
foreach ($new as $key => $item) {
662-
$csv_output .= $item->display_name.",";
666+
$csv_output .= Kkd_pff_prep_csv_data($item->display_name).",";
663667
}
664668
}else{
665669
if (count($new) > 0) {
666670
foreach ($new as $key => $item) {
667-
$csv_output .= $key.",";
671+
$csv_output .= Kkd_pff_prep_csv_data($key).",";
668672
}
669673
}
670674
}
@@ -677,20 +681,20 @@ function Kkd_pff_export_excel() {
677681
}else{
678682
$txn_code = $dbdata->txn_code;
679683
}
680-
$csv_output .= $newkey.",";
681-
$csv_output .= $dbdata->email.",";
682-
$csv_output .= $currency.' '.$dbdata->amount.",";
683-
$csv_output .= $txn_code.",";
684+
$csv_output .= Kkd_pff_prep_csv_data($newkey).",";
685+
$csv_output .= Kkd_pff_prep_csv_data($dbdata->email).",";
686+
$csv_output .= Kkd_pff_prep_csv_data($currency.' '.$dbdata->amount).",";
687+
$csv_output .= Kkd_pff_prep_csv_data($txn_code).",";
684688
$new = json_decode($dbdata->metadata);
685689
$text = '';
686690
if (array_key_exists("0", $new)) {
687691
foreach ($new as $key => $item) {
688-
$csv_output .= $item->value.",";
692+
$csv_output .= Kkd_pff_prep_csv_data($item->value).",";
689693
}
690694
}else{
691695
if (count($new) > 0) {
692696
foreach ($new as $key => $item) {
693-
$csv_output .= $item.",";
697+
$csv_output .= Kkd_pff_prep_csv_data($item).",";
694698
}
695699
}
696700
}

0 commit comments

Comments
 (0)