Что я хочу сделать, так это включить один из моих PHP-скриптов в тему Word Press. Проблема в том, что после включения файла сценария я не могу получить доступ внутри функций в файле темы к переменным, объявленным в файле сценария.
Я создал новый файл в папке темы и добавил тот же код, что и в header.php, и если я открою этот файл, он будет работать нормально. Насколько я могу судить, это что-то связанное с Word Press.
/other/path/wordpress/wp-content/themes/theme-name/header.php // this is broken
/other/path/wordpress/wp-content/themes/theme-name/test.php // this works
/var/www/vhosts/domain/wordpress/ ->(symlink)-> /other/path/wordpress/
/other/path/wordpress/wp-content/themes/theme-name/header.php
/var/www/vhosts/domain/include_file.php
Содержимое: /var/www/vhosts/domain/include_file.php
$global_var = 'global';
print_r($GLOBALS); // if I open this file directly this prints globals WITH $global_var;
// if this file is included in header this prints all the WP stuff WITHOUT $global_var;
Содержимое: /other/path/wordpress/wp-content/themes/theme-name/header.php require '/path/to/include_file.php';
print $global_var; // this prints 'global' as expected
function test()
{
global $global_var;
print $global_var; // this is NULL
}
test();
print_r($GLOBALS); // this prints all the WP stuff WITHOUT $global_var in it