-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-autoloader.php
36 lines (26 loc) · 1.05 KB
/
wp-autoloader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
spl_autoload_register( function ( $class ) {
$file_path = explode( '\\', $class );
if ( empty( $file_path[0] ) || ( 'Espdopt' !== $file_path[0] && 'Espdopt_Pro' !== $file_path[0] ) ) {
return;
}
//the first element is always just application name - the folder is either app or pro
$file_path[0] = 'Espdopt_Pro' === $file_path[0] ? 'pro' : 'app';
foreach ( $file_path as $k => $v ) {
$v = mb_strtolower( str_replace( '_', '-', $v ) );
$file_path[ $k ] = $v;
}
$file_name = end( $file_path );
if ( false !== array_search( 'interfaces', $file_path ) ) {
$file_name = 'interface-' . $file_name . '.php';
} elseif ( false !== array_search( 'traits', $file_path ) ) {
$file_name = 'trait-' . $file_name . '.php';
} else {
$file_name = 'class-' . $file_name . '.php';
}
$file_path[ count( $file_path ) - 1 ] = $file_name;
$fully_qualified_path = trailingslashit( __DIR__ ) . implode( '/', $file_path );
if ( stream_resolve_include_path( $fully_qualified_path ) ) {
include_once $fully_qualified_path;
}
} );