From 9fe00dc4da22bab7cd54bcd87433999d727d0021 Mon Sep 17 00:00:00 2001 From: Rens Tillmann Date: Tue, 20 Oct 2026 04:11:53 +0200 Subject: [PATCH] fix(pdf): attach the PDF font scripts to super-common so optimizers keep them in order --- docs/changelog.md | 4 ++ includes/class-shortcodes.php | 36 +++++----- .../test-security-pdf-font-inline-script.php | 72 +++++++++++++++++++ 3 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 tests/test-security-pdf-font-inline-script.php diff --git a/docs/changelog.md b/docs/changelog.md index ebef4dd3..b9c5960f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,10 @@ - [PDF Generator Add-on](https://renstillmann.github.io/super-forms/#/pdf-generator-add-on) +## Unreleased + +- **Fix:** PDF Generator font data (Cyrillic and Arabic) is now attached to the Super Forms common script, so it still loads when a JavaScript optimization plugin reorders or delays scripts. + ## Oct 09, 2026 - Version 6.3.322 - **Fix:** Date fields with omitted or empty date-format settings now use the default `dd-mm-yy` format during submission, while saved nonempty formats and strict date validation are preserved. diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index fb934032..a8da897c 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -6524,27 +6524,11 @@ public static function super_form_func( $atts, $elements_only=false ) { if($settings['_pdf']['textRendering']==='true'){ // Cyrillic compatible font if($settings['_pdf']['cyrillicText']==='true') { - add_action( 'wp_footer', function(){ - ?> - - - - ' . $js . ''; + }, 100 ); + } + } endif; diff --git a/tests/test-security-pdf-font-inline-script.php b/tests/test-security-pdf-font-inline-script.php new file mode 100644 index 00000000..4e38d76a --- /dev/null +++ b/tests/test-security-pdf-font-inline-script.php @@ -0,0 +1,72 @@ +create_form( 'publish', array(), array( '_pdf' => $pdf ) ); + SUPER_Shortcodes::super_form_func( array( 'id' => (string) $form ) ); + } + + public function test_fonts_attach_to_super_common_after_block() { + $this->render_pdf_form(); + + $after = wp_scripts()->get_data( 'super-common', 'after' ); + $this->assertIsArray( $after ); + $this->assertStringContainsString( 'super_common_i18n.fonts', implode( "\n", $after ) ); + } + + public function test_fonts_print_after_localized_var() { + $this->render_pdf_form(); + + ob_start(); + wp_print_scripts( array( 'super-common' ) ); + $out = ob_get_clean(); + + $var_pos = strpos( $out, 'var super_common_i18n' ); + $fonts_pos = strpos( $out, 'super_common_i18n.fonts' ); + $after_pos = strpos( $out, 'id="super-common-js-after"' ); + $this->assertNotFalse( $var_pos ); + $this->assertNotFalse( $fonts_pos ); + $this->assertNotFalse( $after_pos ); + $this->assertLessThan( $fonts_pos, $var_pos ); + $this->assertLessThan( $fonts_pos, $after_pos ); + } + + public function test_fonts_fall_back_to_footer_when_super_common_already_printed() { + wp_scripts()->done[] = 'super-common'; + $this->render_pdf_form(); + + remove_action( 'wp_footer', 'the_block_template_skip_link' ); + ob_start(); + do_action( 'wp_footer' ); + $out = ob_get_clean(); + + $this->assertStringContainsString( 'super_common_i18n.fonts', $out ); + } +}