autoloader.php (1130B)
1 <?php 2 3 if ( ! function_exists( 'kirki_autoload_classes' ) ) { 4 /** 5 * The Kirki class autoloader. 6 * Finds the path to a class that we're requiring and includes the file. 7 */ 8 function kirki_autoload_classes( $class_name ) { 9 $paths = array(); 10 if ( 0 === stripos( $class_name, 'Kirki' ) ) { 11 12 $path = dirname( __FILE__ ) . '/includes/'; 13 $filename = 'class-' . strtolower( str_replace( '_', '-', $class_name ) ) . '.php'; 14 15 $paths[] = $path . $filename; 16 $paths[] = dirname( __FILE__ ) . '/includes/lib/' . $filename; 17 18 $substr = str_replace( 'Kirki_', '', $class_name ); 19 $exploded = explode( '_', $substr ); 20 $levels = count( $exploded ); 21 22 $previous_path = ''; 23 for ( $i = 0; $i < $levels; $i++ ) { 24 $paths[] = $path . $previous_path . strtolower( $exploded[ $i ] ) . '/' . $filename; 25 $previous_path .= strtolower( $exploded[ $i ] ) . '/'; 26 } 27 28 foreach ( $paths as $path ) { 29 $path = wp_normalize_path( $path ); 30 if ( file_exists( $path ) ) { 31 include_once $path; 32 return; 33 } 34 } 35 36 } 37 38 } 39 // Run the autoloader 40 spl_autoload_register( 'kirki_autoload_classes' ); 41 }