From cbfbfabd187deb49a464fcae60376063613fb54f Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 19 Mar 2024 18:44:53 +0100 Subject: [PATCH] made the plugin dont redeclare font variable if used two times --- plugins/cipf_plugin/utils/plgntls_class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/cipf_plugin/utils/plgntls_class.php b/plugins/cipf_plugin/utils/plgntls_class.php index ec3f464..7f61e9c 100644 --- a/plugins/cipf_plugin/utils/plgntls_class.php +++ b/plugins/cipf_plugin/utils/plgntls_class.php @@ -124,6 +124,7 @@ class PLGNTLS_class { private static $_file_name; private static $_root_path; private static $_root_url; + private static $_instance_count = 0; private $_first_script; private $_first_style; @@ -137,6 +138,7 @@ class PLGNTLS_class { public function __construct() { if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path)) self::set_root_dir(); + ++self::$_instance_count; $this->_prefix = "PLGNTLS"; $this->_first_script = null; $this->_first_style = null; @@ -335,8 +337,7 @@ class PLGNTLS_class { * this name is the filename + "_" + extension : * init.js -> init_js */ - private function add_vars_to_front($vars_arr) - { + private function add_vars_to_front($vars_arr) { if (is_null($this->_first_script)) return ; if (is_null($vars_arr)) @@ -345,7 +346,11 @@ class PLGNTLS_class { $object_name = $this->_prefix . "_data"; $vars_json = json_encode($vars_arr); - $front = "let $object_name = $vars_json;"; + $front = ""; + if (self::$_instance_count === 0) { + $front .= "let "; + } + $front .= "$object_name = $vars_json;"; wp_add_inline_script($handle, $front, 'before'); }