Created
February 17, 2016 19:07
-
-
Save markopostma/d787e2067f273ad54351 to your computer and use it in GitHub Desktop.
Autoloader for wordpress
This file contains hidden or 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
| function autoload_classes( $class ) { | |
| $class_name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', $class)), '_'); | |
| $filename = dirname(__DIR__)."/includes/classes/" . $class_name . ".php"; | |
| if ( file_exists($filename) ) { | |
| require_once $filename; | |
| } | |
| } | |
| function autoload_custom_post_types( $class ) { | |
| $filename = dirname(__DIR__)."/includes/custom-post-types/" . $class . ".php"; | |
| if ( file_exists($filename) ) { | |
| require_once $filename; | |
| } | |
| } | |
| function autoload_lib( $class ) { | |
| $filename = dirname(__DIR__)."/includes/library/" . $class . ".php"; | |
| if ( file_exists($filename) ) { | |
| require_once $filename; | |
| } | |
| } | |
| spl_autoload_register( 'autoload_custom_post_types' ); | |
| spl_autoload_register( 'autoload_lib' ); | |
| spl_autoload_register( 'autoload_classes' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment