Hi I've an issue while dealing with a php code inside Wordpress;
I've my aaa.php file wich contains code:
<?php
require_once("lang_file.php");
echo $GLOBALS['general']['username'];
?>
My lang_file.php contains:
<?php
$language['general']['username'] = 'User';
?>
And my Wordpress page contains this:
<?php
include("aaa.php");
?>
If i access directly aaa.php through browser i get the "User" message from the echo on aaa.php.
If i access the Wordpress page with include code it doesn't show nothing. I've already read this answer: Does WordPress clear $GLOBALS?
And i tried to define the variables on lang_file.php as $GLOBALS but this sti开发者_Go百科ll don't work.
You'd need to use
$GLOBALS['language']['general']['username']
instead.
In PHP, $GLOBALS
is an array of all variables defined globally. The first element of the array is the global variable name.
Therefore, to access the global variable $language
via $GLOBALS
, you would need to use $GLOBALS['language']
. You can then append any array structure after that which you want to reference from $language
.
You can also access it directly via the name $language
if you prefer, by adding global $language;
to the code prior to where you want to use it.
精彩评论