-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-newspaper-x-autoloader.php
54 lines (46 loc) · 1.29 KB
/
class-newspaper-x-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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Class Newspaper_X_Autoloader
*/
class Newspaper_X_Autoloader {
public function __construct() {
spl_autoload_register( array( $this, 'load' ) );
}
/**
* @param $class
*/
public function load( $class ) {
/**
* All classes are prefixed with Sigma_
*/
$parts = explode( '_', $class );
$bind = implode( '-', $parts );
$directories = array(
get_template_directory() . '/inc/',
get_template_directory() . '/inc/libraries/',
get_template_directory() . '/inc/helpers/',
get_template_directory() . '/inc/customizer/',
get_template_directory() . '/inc/libraries/epsilon-framework/',
get_template_directory() . '/inc/libraries/welcome-screen/'
);
foreach ( $directories as $directory ) {
if ( file_exists( $directory . '/class-' . strtolower( $bind ) . '.php' ) ) {
require_once $directory . '/class-' . strtolower( $bind ) . '.php';
return;
}
}
/**
* Load widgets
*/
if ( ( count( $parts ) > 2 ) && $parts[0] == 'Widget' && $parts[1] == 'Newspaper' ) {
$path = get_template_directory() . '/inc/libraries/widgets/' . strtolower( $bind ) . '/class-' . strtolower( $bind ) . '.php';
if ( file_exists( $path ) ) {
require_once $path;
}
}
}
}
$autoloader = new Newspaper_X_Autoloader();