title: PHP Auto-load and WordPress
body: <p>I am having a weird issue with the autoloader class I built in PHP to use in WordPress. </p>
  
  <p>The core concept is that it should load class regardless of if you are a child theme, parent theme or a plugin. It should find the class based on the name (coreesponding to the folder structure: <code>CoreTheme_Folder_SubFolder_ClassName(){}</code> = <code>CoreTheme/Folder/SubFolder/ClassName.php</code> </p>
  
  <p>This works fine in child themes and parent themes, In child themes I include the parent themes function.php and from there it loads the autoloader so that I can call parent theme classes in child themes and not have a bunch of <code>require_once()</code> every where.</p>
  
  <p>The problem comes, when I am doing the same concept in a plugin. The Autoloader is apart of a framework (think of zend) that you include at the root of your theme. If that theme is active and I set up the autoloader in a plugin, it spazzes out saying "there are two instances of this autoloader, what are you doing?" If I deactivate said theme then instantiate the autoloader in the plugin, it cant find any class I create using the pear naming standards.</p>
  
  <p>So My question to those who understand both WordPress and PHP on a deeper level, How do I create my autoloader such that, regardless of weather your theme, child theme or plugin it will always find the class you are looking for. </p>
  
  <p>the code below is the autloader class. If you take out: <code>plugin_dir_path(__FILE__)</code> then what will happen is the autoloader will load any class in the theme and corresponding child theme.</p>
  
  <pre><code>class AisisCore_Loader_AutoLoader{
  
      protected static $_instance;
  
      protected static $_directories;
  
      public function get_instance(){
          if(null == self::$_instance){
              self::$_instance = new self();
          }
  
          self::$_directories = array(
              get_template_directory(),
              get_stylesheet_directory(),
              plugin_dir_path(__FILE__),
          );
  
          return self::$_instance;
      }
  
      public function reset_instance(){
          self::$_instance = null;
      }
  
      public function register_auto_loader(){
          spl_autoload_register(array($this, 'load_class'));
      }
  
      public function load_class($class){
          $path = str_replace('_', '/', $class);
          foreach(self::$_directories as $directories){
              if(file_exists($directories . '/' . $path . '.php')){
                  require_once($directories . '/' . $path . '.php');
              }
          }
      }   
  }
  </code></pre>
  
  <p>The class is instantiated in your parent functions.php via:</p>
  
  <pre><code>// Load the autoloader.
  require_once(get_template_directory() . '/AisisCore/Loader/AutoLoader.php');
  
  // Setup the autoloader.
  $auto_loader = AisisCore_Loader_AutoLoader::get_instance();
  $auto_loader-&gt;register_auto_loader();
  </code></pre>
  
  <p>And then in the child theme all you have to do is:</p>
  
  <pre><code>require_once(TEMPLATEPATH . '/functions.php');
  </code></pre>
  
  <p>This allows the autoloader to work in both child and parent theme. The main issue is that when you create a plugin you place a copy of the framework in your plugin's Name root directory: <code>plugins/myplugin/AisisCore/</code> and one in your theme (parent) <code>Themes/MyTheme/AisisCore</code></p>
  
  <p>So I can see why it would freak out - sort of, how ever is there a way around it?</p>