From 2a3477d95c509ee001c414ce262d42acac838732 Mon Sep 17 00:00:00 2001 From: Jake Jackson Date: Mon, 17 Aug 2026 15:14:05 +1000 Subject: [PATCH] refactor: decouple the localised script data from PDF_TEMPLATE_LOCATION `Helper_Data::get_localised_script_data()` sourced `pdfWorkingDir` from the v3 `PDF_TEMPLATE_LOCATION` constant, which is defined inside `src/deprecated.php`. That made a file slated for deletion in 7.0 load-bearing for the React Template Manager: `pdfWorkingDir` is what `TemplateFooterActions::notCoreTemplate()` compares each template path against to decide whether the delete button renders. The constant is defined as `Helper_Templates::get_template_path()`, so pass that helper in and call it directly. Value is identical on both single and multisite; as a bonus it is no longer frozen at `after_setup_theme`. Phase 1 of the 7.0 deprecated code removal plan. Co-Authored-By: Claude Opus 5 (1M context) --- src/Helper/Helper_Data.php | 6 ++++-- src/bootstrap.php | 2 +- tests/phpunit/integration/Helper/Test_Helper_Data.php | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Helper/Helper_Data.php b/src/Helper/Helper_Data.php index a1cd4f762..c93287df4 100644 --- a/src/Helper/Helper_Data.php +++ b/src/Helper/Helper_Data.php @@ -206,12 +206,14 @@ public function addon_license_responses( $addon_name ) { * * @param Helper_Abstract_Options $options * @param Helper_Abstract_Form $gform + * @param Helper_Templates $templates * * @return array * * @since 4.0 + * @since 6.17.0 Added the $templates parameter */ - public function get_localised_script_data( Helper_Abstract_Options $options, Helper_Abstract_Form $gform ) { + public function get_localised_script_data( Helper_Abstract_Options $options, Helper_Abstract_Form $gform, Helper_Templates $templates ) { $custom_fonts = array_values( $options->get_custom_fonts() ); $user_data = get_userdata( get_current_user_id() ); @@ -228,7 +230,7 @@ public function get_localised_script_data( Helper_Abstract_Options $options, Hel 'restUrl' => rest_url( 'gravity-pdf/v1/' ), 'restNonce' => wp_create_nonce( 'wp_rest' ), 'currentVersion' => PDF_EXTENDED_VERSION, - 'pdfWorkingDir' => PDF_TEMPLATE_LOCATION, + 'pdfWorkingDir' => $templates->get_template_path(), 'pluginUrl' => PDF_PLUGIN_URL, 'pluginPath' => PDF_PLUGIN_DIR, 'customFontData' => wp_json_encode( $custom_fonts ), diff --git a/src/bootstrap.php b/src/bootstrap.php index 9f5a75c6e..06cf07d09 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -446,7 +446,7 @@ public function load_admin_assets() { add_filter( 'tiny_mce_before_init', [ $this, 'tinymce_styles' ] ); /* Localise admin script */ - $data = $this->data->get_localised_script_data( $this->options, $this->gform ); + $data = $this->data->get_localised_script_data( $this->options, $this->gform, $this->templates ); wp_localize_script( 'gfpdf_js_entrypoint', 'GFPDF', $data ); wp_localize_script( 'gfpdf_js_settings', 'GFPDF', $data ); diff --git a/tests/phpunit/integration/Helper/Test_Helper_Data.php b/tests/phpunit/integration/Helper/Test_Helper_Data.php index 85aa3bdbb..ef93cf9f1 100644 --- a/tests/phpunit/integration/Helper/Test_Helper_Data.php +++ b/tests/phpunit/integration/Helper/Test_Helper_Data.php @@ -154,7 +154,7 @@ public function provider_setter(): array { public function test_localised_script() { global $gfpdf; - $localised_data = $this->data->get_localised_script_data( $gfpdf->options, $gfpdf->gform ); + $localised_data = $this->data->get_localised_script_data( $gfpdf->options, $gfpdf->gform, $gfpdf->templates ); $required_keys = [ 'ajaxUrl', 'ajaxNonce', @@ -168,6 +168,10 @@ public function test_localised_script() { foreach ( $required_keys as $key ) { $this->assertArrayHasKey( $key, $localised_data ); } + + /* The React Template Manager compares this against each template path to decide if it can be deleted */ + $working_dir = is_multisite() ? $gfpdf->data->multisite_template_location : $gfpdf->data->template_location; + $this->assertSame( $working_dir, $localised_data['pdfWorkingDir'] ); } public function test_get_conditional_logic_options() {