title: functions file, plugin, and theme scoping in wordpress mu
body: <p>I've got a plugin that is declared and hooked following best practices described in this related question: </p>
  
  <p><a href="https://stackoverflow.com/questions/1615118/wordpress-accessing-a-plugins-function-from-a-theme">Wordpress: Accessing A Plugin&#39;s Function From A Theme</a></p>
  
  <p>So it looks (platonically) like this:</p>
  
  <pre><code>if ( !class_exists( 'Foo' ) ) {
    class Foo {
      ...
      public function do_stuff() {
        // does stuff
      }
    }
  }
  
  if ( class_exists( 'Foo' ) ) {
    $MyFoo = new Foo();
  }
  </code></pre>
  
  <p>Now, if I call $MyFoo->do_stuff() from a theme file, such as, say, single.php, $MyFoo in fact <em>does_stuff</em> and I see the output in the page.</p>
  
  <p>However, if I write a function in functions.php that wants to call $MyFoo->do_stuff() and then call that function from single.php the object is not found. In summary,</p>
  
  <p>Works:</p>
  
  <pre><code>in themes/my_theme/single.php:
    if (isset($MyFoo))
      $MyFoo-&gt;do_stuff();
  </code></pre>
  
  <p>Does not work:</p>
  
  <pre><code>in themes/my_theme/functions.php:
    function do_some_foo_stuff() {
      ...
      if (isset($MyFoo)) {
         $MyFoo-&gt;do_stuff();
      } else {
         echo "no MyFoo set";
      }
      ...
    }
   themes/my_theme/single.php:
     if (isset($MyFoo))
       do_some_foo_stuff();
  </code></pre>
  
  <p>Outputs -> "no MyFoo set"</p>
  
  <p>This may be totally unsurprising, but it's something I need/want to work, so if anyone can explain what is going on it'd be appreciated. Why can't the theme's functions file (or other plugin files in mu-plugins for that matter) find $MyFoo object? </p>