| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! class_exists( 'Plugin_Autoloader' ) ) : |
| 4 |
|
| 5 |
class Plugin_Autoloader { |
| 6 |
|
| 7 |
public $directory = __DIR__; |
| 8 |
|
| 9 |
public function __construct( $directory = '' ) { |
| 10 |
$this->set_directory( $directory ); |
| 11 |
spl_autoload_register( array( $this, 'autoload' ) ); |
| 12 |
} |
| 13 |
|
| 14 |
public function set_directory( $directory ) { |
| 15 |
if ( ! empty( $directory ) ) { |
| 16 |
$this->directory = $directory; |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
public function autoload( $class ) { |
| 21 |
$file = $this->directory . '/class-' . strtolower( str_replace( '_', '-', $class ) ) . '.php'; |
| 22 |
$this->get_class( $file ); |
| 23 |
} |
| 24 |
|
| 25 |
private function get_class( $file ) { |
| 26 |
if ( file_exists( $file ) ) { |
| 27 |
require_once( $file ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
endif; |
| 34 |
|