Created
December 4, 2015 11:23
-
-
Save BinaryKitten/1fd2d64440ae921ecec8 to your computer and use it in GitHub Desktop.
ThemeAutoloader
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
| <?php | |
| spl_autoload_register( 'my_theme_autoloader' ); | |
| function my_theme_autoloader( $class_name ) { | |
| if ( substr( $class_name, 0, 6 ) == 'theme_' ) { | |
| $cur_theme_file = get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_name . '.php'; | |
| $parent_theme_file = get_template_directory() . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_name . '.php'; | |
| if ( file_exists( $cur_theme_file ) ) { | |
| require_once $cur_theme_file; | |
| } elseif ( file_exists( $parent_theme_file ) ) { | |
| require_once $parent_theme_file; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment