1: <?php
2: if ( ! defined( 'ABSPATH' ) ) exit;
3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Sensei_Autoloader {
13:
14: 15: 16:
17: private $include_path = 'includes';
18:
19: 20: 21:
22: private $class_file_map = array();
23:
24: 25: 26: 27:
28: public function __construct(){
29:
30:
31: if( function_exists('__autoload') ){
32: spl_autoload_register( '__autoload' );
33: }
34:
35:
36: $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
37:
38:
39: $this->initialize_class_file_map();
40:
41:
42: spl_autoload_register( array( $this, 'autoload' ) );
43:
44: }
45:
46: 47: 48: 49: 50: 51:
52: public function initialize_class_file_map(){
53:
54: $this->class_file_map = array(
55:
56: 57: 58:
59: 'Sensei_Main' => 'class-sensei.php',
60:
61: 62: 63:
64: 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' ,
65: 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
66:
67: 68: 69:
70: 'Sensei_Shortcode_Loader' => 'shortcodes/class-sensei-shortcode-loader.php',
71: 'Sensei_Shortcode_Interface' => 'shortcodes/interface-sensei-shortcode.php',
72: 'Sensei_Shortcode_Featured_Courses' => 'shortcodes/class-sensei-shortcode-featured-courses.php',
73: 'Sensei_Shortcode_User_Courses' => 'shortcodes/class-sensei-shortcode-user-courses.php',
74: 'Sensei_Shortcode_Courses' => 'shortcodes/class-sensei-shortcode-courses.php',
75: 'Sensei_Shortcode_Teachers' => 'shortcodes/class-sensei-shortcode-teachers.php',
76: 'Sensei_Shortcode_User_Messages' => 'shortcodes/class-sensei-shortcode-user-messages.php',
77: 'Sensei_Shortcode_Course_Page' => 'shortcodes/class-sensei-shortcode-course-page.php',
78: 'Sensei_Shortcode_Lesson_Page' => 'shortcodes/class-sensei-shortcode-lesson-page.php',
79: 'Sensei_Shortcode_Course_Categories' => 'shortcodes/class-sensei-shortcode-course-categories.php',
80: 'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
81: 'Sensei_Legacy_Shortcodes' => 'shortcodes/class-sensei-legacy-shortcodes.php',
82:
83: 84: 85:
86: 'Sensei_Theme_Integration_Loader' => 'theme-integrations/theme-integration-loader.php',
87: 'Sensei__S' => 'theme-integrations/_s.php',
88: 'Sensei_Twentyeleven' => 'theme-integrations/twentyeleven.php',
89: 'Sensei_Twentytwelve' => 'theme-integrations/twentytwelve.php',
90: 'Sensei_Twentythirteen' => 'theme-integrations/Twentythirteen.php',
91: 'Sensei_Twentyfourteen' => 'theme-integrations/Twentyfourteen.php',
92: 'Sensei_Twentyfifteen' => 'theme-integrations/Twentyfifteen.php',
93: 'Sensei_Twentysixteen' => 'theme-integrations/Twentysixteen.php',
94: 'Sensei_Storefront' => 'theme-integrations/Storefront.php',
95:
96: 97: 98:
99: 'Sensei_WC' => 'class-sensei-wc.php',
100:
101: );
102: }
103:
104: 105: 106:
107: public function autoload( $class ){
108:
109:
110: if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
111:
112: return;
113:
114: }
115:
116:
117: if( isset( $this->class_file_map[ $class ] ) ){
118:
119: $file_location = $this->include_path . $this->class_file_map[ $class ];
120: require_once( $file_location);
121: return;
122:
123: }
124:
125:
126: $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
127: if( file_exists( $class_file_path ) ){
128:
129: require_once( $class_file_path );
130: return;
131: }
132:
133:
134: $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) );
135: $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
136: if( file_exists( $legacy_class_file_path ) ){
137:
138: require_once( $legacy_class_file_path );
139: return;
140: }
141:
142: return;
143:
144: }
145:
146: }
147: new Sensei_Autoloader();
148: