Skip to content

Instantly share code, notes, and snippets.

@starise
Created February 2, 2015 03:27
Show Gist options
  • Save starise/29cb4bae001d50bccbe3 to your computer and use it in GitHub Desktop.
Save starise/29cb4bae001d50bccbe3 to your computer and use it in GitHub Desktop.
Wordpress autoloader for plugins and themes
<?php
/**
* Autoloader for WordPress plugins and themes
* http://wordpress.stackexchange.com/a/66484
*/
spl_autoload_register(__NAMESPACE__ . '\\autoload');
function autoload($cls)
{
$cls = ltrim($cls, '\\');
if(strpos($cls, __NAMESPACE__) !== 0)
return;
$cls = str_replace(__NAMESPACE__, '', $cls);
$path = PLUGIN_PATH_PATH . 'inc' .
str_replace('\\', DIRECTORY_SEPARATOR, $cls) . '.php';
require_once($path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment