-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoloader.php
30 lines (25 loc) · 928 Bytes
/
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
<?php
/**
* WordPress Class Autoloader
*/
spl_autoload_register(
function ( $classname ) {
// Remove base.
$classname = str_replace( 'BernskioldMedia\\WP\\PageSpecificCSS\\', '', $classname );
// Regular
$class = str_replace( '\\', DIRECTORY_SEPARATOR, strtolower( $classname ) );
$classpath = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $class . '.php';
// WordPress
$parts = explode( '\\', $classname );
$class = strtolower( array_pop( $parts ) );
$class = str_replace( '_', '-', $class );
$folders = strtolower( implode( DIRECTORY_SEPARATOR, $parts ) );
$folders = str_replace( '_', '-', $folders );
$wppath = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folders . DIRECTORY_SEPARATOR . $class . '.php';
if ( file_exists( $classpath ) ) {
require_once $classpath;
} elseif ( file_exists( $wppath ) ) {
require_once $wppath;
}
}
);