Skip to content

Instantly share code, notes, and snippets.

@rwsite
Last active March 24, 2024 23:51
Show Gist options
  • Save rwsite/779081c91179ce1ff78447f2cbbe8ee5 to your computer and use it in GitHub Desktop.
Save rwsite/779081c91179ce1ff78447f2cbbe8ee5 to your computer and use it in GitHub Desktop.
Wordpress class autoloder with PSR4 standart.
spl_autoload_register(function ($className){
if ( strpos( $className, __NAMESPACE__ ) !== 0 ) {
return;
}
$className = str_replace(__NAMESPACE__ . '\\', 'includes\\', $className);
$path = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($className, '\\', DIRECTORY_SEPARATOR) . '.php';
if (is_readable($path)) {
require_once $path;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment