Skip to:

global $variables in header not passed to body

  • I’m seeing some interesting behavior. Though I am a php rookie it seems like what I am trying to do should work.

    I include some code in the header that parses cookies and sets variables appropriately. I use the exact same code and approach in WordPress and it works perfectly.

    This is at the top of my bbpress header.php:

    global $research_subscriber; // '1' if user is research subscriber
    global $forums_subscriber; // '1' if user is forums subscriber
    if (condition) $nyquist_research_subscriber=1;
    if (condition) $nyquist_forums_subscriber=1;

    Just to make sure, I echo’ed out the variables afterward within header.php and they are all being set as expected.

    Later on, in files that include header.php (topic.php or front-page.php) by invoking bb_get_header(), I attempt to access these global variables and they are all null.

    Why are these variables not being passed? Why does this work in WordPress but not BBpress? What am I missing (bangs head against wall)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Note I mistyped above – the variables in the if statement match the global declaration. I just neglected to edit out the ‘nyquist’ from the if statement in the name of a little privacy.

    After much hacking about I figured out the problem.

    This post offered a clue:

    It turns out that any global variables declared or set in header.php must also be set in the calling page. I added the following to the top of front_page.php and now the variables are properly set after calling bb_head().

    <?php global $research_subscriber; // ‘1’ if user is research subscriber

    global $forums_subscriber; // ‘1’ if user is forums subscriber


    The global variables don’t need to be set in the calling page in wordpress (single.php, search.php). I have no idea why bbpress handles this differently – must be in the way the header is called.

    Much frustration. I hope someone finds this post useful.



    thanks.. this helped a lot.had the same problem.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar