forked from anspress/anspress
/
loader.php
42 lines (35 loc) · 981 Bytes
/
loader.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
<?php
/**
* AnsPress class auto loader.
*
* @link https://anspress.io/anspress
* @since 1.0.0
* @author Rahul Aryan <support@anspress.io>
* @package AnsPressPro
*/
namespace AnsPress;
/**
* Callback function for auto loading class on demand.
*
* @param string $class Name of class.
* @return boolean True if files is included.
* @since 4.1.8
*/
function autoloader( $class ) {
if ( false === strpos( $class, 'AnsPress\\' ) ) {
return;
}
// Replace AnsPress\Pro\ and change to lowercase to fix WPCS warning.
$class = strtolower( str_replace( 'AnsPress\\', '', $class ) );
$filename = ANSPRESS_DIR . str_replace( '_', '-', str_replace( '\\', '/', $class ) ) . '.php';
// Check if file exists before including.
if ( file_exists( $filename ) ) {
require_once $filename;
// Check class exists.
if ( class_exists( $class ) ) {
return true;
}
}
return false;
}
spl_autoload_register( __NAMESPACE__ . '\\autoloader' );