wip trying to get the var name directly, first try not working
This commit is contained in:
@@ -28,10 +28,28 @@ function add_script_to_front($script_files_arr) {
|
||||
|
||||
}
|
||||
|
||||
# https://stackoverflow.com/a/61442261/9497573
|
||||
function get_varname(&$var) {
|
||||
$tmp = $var; // store the variable value
|
||||
$var = '_$_%&33xc$%^*7awdlawidawd__D:DWD2398q_r4'; // give the variable a new unique value
|
||||
$name = array_search($var, $GLOBALS); // search $GLOBALS for that unique value and return the key(variable)
|
||||
$var = $tmp; // restore the variable old value
|
||||
console_log("name : " . $name);
|
||||
return $name;
|
||||
}
|
||||
|
||||
function add_var_to_front($var_array) {
|
||||
foreach ($var_array as $key => $var)
|
||||
# foreach ($var_array as $key => $var)
|
||||
# {
|
||||
# $js_var = 'const ' . $key . ' = ';
|
||||
# $js_var .= json_encode($var);
|
||||
# $js_var .= ';';
|
||||
# console_log("in php, js_var: " . $js_var);
|
||||
# wp_add_inline_script('myscript', $js_var, 'before');
|
||||
# }
|
||||
foreach ($var_array as $var)
|
||||
{
|
||||
$js_var = 'const ' . $key . ' = ';
|
||||
$js_var = 'const ' . get_varname($var) . ' = ';
|
||||
$js_var .= json_encode($var);
|
||||
$js_var .= ';';
|
||||
console_log("in php, js_var: " . $js_var);
|
||||
|
||||
Reference in New Issue
Block a user