-
Is it possible to use variables like this? Your snippet: https://github.com/flyntwp/flynt#advanced-custom-fields My snippet: <?php
namespace Flynt\Components\BlockWysiwyg;
$var = "foo";
function getACFLayout()
{
global $var;
return [
'name' => $var,
'label' => 'Block: Wysiwyg',
'sub_fields' => [
[
'label' => __('Content', 'flynt'),
'name' => 'contentHtml',
'type' => 'wysiwyg',
'delay' => 1,
'media_upload' => 0,
'required' => 1,
],
]
];
}
function foo() {
global $var;
echo $var;
}
Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @wanjapflueger, <?php
namespace Flynt\Components\BlockWysiwyg;
global $var;
$var = "foo";
function getACFLayout() Hope that helps! |
Beta Was this translation helpful? Give feedback.
Hi @wanjapflueger,
I was actually a bit surprised, when I saw your question. I would expected it to actually work exactly like you tried it.
However, after a bit of digging around, I found the reason why it is not working as expected.
We
require_once
the components'function.php
files inside other functions inside WordPress hooks. So your initial$var ='foo';
does actually not set a global variable.In order to explicitly achieve what you are trying to, change the beginning of you code to
Hope that helps!