MyBB Community Forums

Full Version: Global variable in plugin doesn't work in some template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to retrieve {$this_var} in template named "member_profile_avatar", but it doesn't allow me do that.

Near the top of plugin's code, I have:

...
$plugins->add_hook('member_profile_end', 'my_plugin_function');
...


And below in the same file, I have:
...
function my_plugin_function()
{
    global $this_var;
    echo "<script>console.log('Debug Objects:' );</script>";

    $this_var = 'aaa';
}
...

This "$this_var" can be accessed from "member_profile" template.
However, "member_profile_avatar" template couldn't access that variable.

I also tried "index_start" instead of "member_profile_end", but it didn't work either.

How can I make a variable that can be accessed from any template?
Thank you very much!
The member_profile_avatar template is rendered at https://github.com/mybb/mybb/blob/mybb_1....php#L2064 and should have access to variables defined up to that point; the member_profile_end hook runs later than that, but member_profile_start (https://github.com/mybb/mybb/blob/mybb_1....php#L2029) should work.