made the plugin dont redeclare font variable if used two times
This commit is contained in:
@@ -124,6 +124,7 @@ class PLGNTLS_class {
|
|||||||
private static $_file_name;
|
private static $_file_name;
|
||||||
private static $_root_path;
|
private static $_root_path;
|
||||||
private static $_root_url;
|
private static $_root_url;
|
||||||
|
private static $_instance_count = 0;
|
||||||
|
|
||||||
private $_first_script;
|
private $_first_script;
|
||||||
private $_first_style;
|
private $_first_style;
|
||||||
@@ -137,6 +138,7 @@ class PLGNTLS_class {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
if (!isset(self::$_plugin_name, self::$_file_name, self::$_file_dir_path, self::$_plugin_dir_path))
|
||||||
self::set_root_dir();
|
self::set_root_dir();
|
||||||
|
++self::$_instance_count;
|
||||||
$this->_prefix = "PLGNTLS";
|
$this->_prefix = "PLGNTLS";
|
||||||
$this->_first_script = null;
|
$this->_first_script = null;
|
||||||
$this->_first_style = null;
|
$this->_first_style = null;
|
||||||
@@ -335,8 +337,7 @@ class PLGNTLS_class {
|
|||||||
* this name is the filename + "_" + extension :
|
* this name is the filename + "_" + extension :
|
||||||
* init.js -> init_js
|
* 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))
|
if (is_null($this->_first_script))
|
||||||
return ;
|
return ;
|
||||||
if (is_null($vars_arr))
|
if (is_null($vars_arr))
|
||||||
@@ -345,7 +346,11 @@ class PLGNTLS_class {
|
|||||||
$object_name = $this->_prefix . "_data";
|
$object_name = $this->_prefix . "_data";
|
||||||
|
|
||||||
$vars_json = json_encode($vars_arr);
|
$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');
|
wp_add_inline_script($handle, $front, 'before');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user