Skip to content

Use global variables for component functions #365

Answered by domtra
wanjakarl asked this question in Q&A
Discussion options

You must be logged in to vote

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

<?php

namespace Flynt\Components\BlockWysiwyg;

global $var;
$var = "foo";

function getACFLayout()

Hope that helps!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wanjakarl
Comment options

Answer selected by wanjakarl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants