@@ -37,6 +37,7 @@ class Pdf_Forms_For_WPForms
37
37
private $ storage = null ;
38
38
private $ tmp_dir = null ;
39
39
private $ wpforms_mail_attachments = array ();
40
+ private $ need_plaintext_smart_tag_value_flag = false ;
40
41
41
42
private function __construct ()
42
43
{
@@ -78,6 +79,8 @@ public function plugin_init()
78
79
add_action ( 'admin_menu ' , array ( $ this , 'register_services ' ) );
79
80
80
81
add_filter ( 'wpforms_save_form_args ' , array ( $ this , 'wpforms_save_form_args ' ), 10 , 3 );
82
+
83
+ add_filter ( 'wpforms_smarttags_process_value ' , array ( $ this , 'plaintext_smart_tag_value_workaround_filter ' ), PHP_INT_MAX , 6 );
81
84
// fill_pdfs: we can't use wpforms_process_complete (because notifications have already been sent) and wpforms_process because uploaded files haven't been processed yet
82
85
add_filter ( 'wpforms_process_after_filter ' , array ( $ this , 'fill_pdfs ' ), 999999 , 3 );
83
86
add_action ( 'wpforms_process_complete ' , array ( $ this , 'remove_tmp_dir ' ), 99 , 0 );
@@ -839,6 +842,37 @@ public static function decode_form_settings( $data )
839
842
return $ form_settings ;
840
843
}
841
844
845
+ /**
846
+ * Wrapper for WPForms' wpforms_process_smart_tags()
847
+ *
848
+ * The function wpforms_process_smart_tags() formats smart tag values for HTML output (via `wp_kses_post()`), but we need plain text.
849
+ * Additional issue is that the content we are passing into wpforms_process_smart_tags() is plain text mixed with smart tags, but the smart tags will be formatted in HTML.
850
+ * So, we need to use a workaround to make sure we get plain text smart tag values.
851
+ */
852
+ public function wpforms_process_smart_tags ( $ content , $ form_data , $ fields = [], $ entry_id = '' , $ context = '' )
853
+ {
854
+ // enable flag to convert smart tag values from HTML to plain text
855
+ $ this ->need_plaintext_smart_tag_value_flag = true ;
856
+
857
+ $ value = wpforms_process_smart_tags ( $ content , $ form_data , $ fields , $ entry_id , $ context );
858
+
859
+ // disable conversion
860
+ $ this ->need_plaintext_smart_tag_value_flag = false ;
861
+
862
+ return $ value ;
863
+ }
864
+
865
+ /**
866
+ * Filter the smart tag values late to convert HTML to plain text when we are inside our own wpforms_process_smart_tags call
867
+ */
868
+ public function plaintext_smart_tag_value_workaround_filter ( $ value , $ tag_name , $ form_data , $ fields , $ entry_id , $ smart_tag_object )
869
+ {
870
+ if ( $ this ->need_plaintext_smart_tag_value_flag )
871
+ return html_entity_decode ( strip_tags ( $ value ), ENT_QUOTES , 'UTF-8 ' );
872
+ else
873
+ return $ value ;
874
+ }
875
+
842
876
/**
843
877
* We need to fill the pdf's document fields and then create attachment file and attach them
844
878
*/
@@ -881,7 +915,7 @@ public function fill_pdfs( $wpforms_fields, $entry, $form_data )
881
915
if ( isset ( $ embed ["wpf_field " ] ) )
882
916
$ url = $ wpforms_fields [$ embed ["wpf_field " ]]['value ' ];
883
917
if ( isset ( $ embed ['smart_tags ' ] ) )
884
- $ url = wpforms_process_smart_tags ( $ embed ["smart_tags " ], $ form_data , $ wpforms_fields , $ entry_id );
918
+ $ url = $ this -> wpforms_process_smart_tags ( $ embed ["smart_tags " ], $ form_data , $ wpforms_fields , $ entry_id );
885
919
886
920
if ( $ url != null )
887
921
{
@@ -1034,7 +1068,7 @@ public function fill_pdfs( $wpforms_fields, $entry, $form_data )
1034
1068
$ data [$ field ] = $ wpforms_fields [$ mapping ["wpf_field " ]]['value ' ];
1035
1069
1036
1070
if ( isset ( $ mapping ["smart_tags " ] ) )
1037
- $ data [$ field ] = wpforms_process_smart_tags ( $ mapping ["smart_tags " ], $ form_data , $ wpforms_fields , $ entry_id );
1071
+ $ data [$ field ] = $ this -> wpforms_process_smart_tags ( $ mapping ["smart_tags " ], $ form_data , $ wpforms_fields , $ entry_id );
1038
1072
1039
1073
if ( $ multiple )
1040
1074
{
@@ -1281,7 +1315,7 @@ public function fill_pdfs( $wpforms_fields, $entry, $form_data )
1281
1315
1282
1316
$ destfilename = strval ( $ attachment ['options ' ]['filename ' ] );
1283
1317
if ( $ destfilename != "" )
1284
- $ destfilename = strval ( wpforms_process_smart_tags ( $ destfilename , $ form_data , $ wpforms_fields , $ entry_id ) );
1318
+ $ destfilename = strval ( $ this -> wpforms_process_smart_tags ( $ destfilename , $ form_data , $ wpforms_fields , $ entry_id ) );
1285
1319
if ( $ destfilename == "" )
1286
1320
$ destfilename = sanitize_file_name ( get_the_title ( $ attachment_id ) );
1287
1321
@@ -1356,7 +1390,7 @@ public function fill_pdfs( $wpforms_fields, $entry, $form_data )
1356
1390
$ path_elements = explode ( "/ " , $ save_directory );
1357
1391
$ tag_replaced_path_elements = array ();
1358
1392
foreach ( $ path_elements as $ key => $ value )
1359
- $ tag_replaced_path_elements [$ key ] = wpforms_process_smart_tags ( $ value , $ form_data , $ wpforms_fields , $ entry_id );
1393
+ $ tag_replaced_path_elements [$ key ] = $ this -> wpforms_process_smart_tags ( $ value , $ form_data , $ wpforms_fields , $ entry_id );
1360
1394
1361
1395
foreach ( $ tag_replaced_path_elements as $ elmid => &$ new_element )
1362
1396
{
0 commit comments