| 1 |
<?php |
| 2 |
/** |
| 3 |
* Register plugin autoloader. Example namespace: LassoLite\Models, LassoLite\Pages, LassoLite\Ajax,... |
| 4 |
* |
| 5 |
* @package Autoload |
| 6 |
* |
| 7 |
* @param string $class_name Name of the class to load. |
| 8 |
*/ |
| 9 |
|
| 10 |
spl_autoload_register( |
| 11 |
function( $class_name ) { |
| 12 |
$namespace_prefix = 'LassoLite'; |
| 13 |
$class_file_prefix = 'class-'; |
| 14 |
// ? Only do autoload for our plugin files |
| 15 |
if ( strpos( $class_name, $namespace_prefix . '\\' ) === 0 ) { |
| 16 |
$class_file = str_replace( array( '\\', $namespace_prefix . DIRECTORY_SEPARATOR ), array( DIRECTORY_SEPARATOR, '' ), $class_name ) . '.php'; |
| 17 |
$class_file = strtolower( $class_file ); |
| 18 |
$temp = explode( DIRECTORY_SEPARATOR, $class_file ); |
| 19 |
$file_name = end( $temp ); |
| 20 |
$correct_file_name = $class_file_prefix . $file_name; |
| 21 |
$class_file = str_replace( $file_name, $correct_file_name, $class_file ); |
| 22 |
$class_file = str_replace( '_', '-', $class_file ); |
| 23 |
$class_file_path = SIMPLE_URLS_DIR . DIRECTORY_SEPARATOR . $class_file; |
| 24 |
|
| 25 |
if ( file_exists( $class_file_path ) ) { |
| 26 |
require_once $class_file_path; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
); |
| 31 |
|