Created
February 2, 2015 03:27
-
-
Save starise/29cb4bae001d50bccbe3 to your computer and use it in GitHub Desktop.
Wordpress autoloader for plugins and themes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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