-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
47 lines (37 loc) · 1.05 KB
/
bootstrap.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
<?php
/**
* Bootstrap.
*
* @package Plance\Plugin\Redirects_For_Htaccess
*/
namespace Plance\Plugin\Redirects_For_Htaccess;
defined( 'ABSPATH' ) || exit;
const PATH = __DIR__;
const VERSION = '1.0.0';
define( __NAMESPACE__ . '\URL', rtrim( plugin_dir_url( __FILE__ ), '/' ) );
/**
* Autoload plugin classes.
*/
spl_autoload_register(
function ( $class ) { // phpcs:ignore
if ( strpos( $class, __NAMESPACE__ . '\\' ) !== 0 ) {
return;
}
$class = str_replace( __NAMESPACE__ . '\\', '', $class );
$class = str_replace( '_', '-', strtolower( $class ) );
$folders = explode( '\\', $class );
$classname = array_pop( $folders );
$path = '';
if ( ! empty( $folders ) ) {
$path = join( DIRECTORY_SEPARATOR, $folders ) . DIRECTORY_SEPARATOR;
}
$prefixes = array( 'class' );
foreach ( $prefixes as $prefix ) {
$file_name = PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $path . $prefix . '-' . $classname . '.php';
if ( file_exists( $file_name ) ) {
require_once $file_name;
return;
}
}
}
);