Last active
March 24, 2024 23:51
-
-
Save rwsite/779081c91179ce1ff78447f2cbbe8ee5 to your computer and use it in GitHub Desktop.
Wordpress class autoloder with PSR4 standart.
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
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