| 1 |
<?php |
| 2 |
/** |
| 3 |
* Autoloader for WPbot Automator |
| 4 |
* |
| 5 |
* @package WPbot_Automator |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPbot_Automator; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Autoloader class |
| 16 |
*/ |
| 17 |
class Autoloader { |
| 18 |
|
| 19 |
/** |
| 20 |
* Run autoloader. |
| 21 |
*/ |
| 22 |
public static function run() { |
| 23 |
spl_autoload_register( array( __CLASS__, 'autoload' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Autoload classes. |
| 28 |
* |
| 29 |
* @param string $class Class name. |
| 30 |
*/ |
| 31 |
public static function autoload( $class ) { |
| 32 |
// Check if the class uses our namespace. |
| 33 |
if ( strpos( $class, 'WPbot_Automator\\' ) !== 0 ) { |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
// Remove namespace prefix. |
| 38 |
$class = str_replace( 'WPbot_Automator\\', '', $class ); |
| 39 |
|
| 40 |
// Convert class name to file path. |
| 41 |
$file = str_replace( '_', '-', strtolower( $class ) ); |
| 42 |
$file = str_replace( '\\', DIRECTORY_SEPARATOR, $file ); |
| 43 |
|
| 44 |
// Build the file path. |
| 45 |
$path = WPBOT_AUTOMATOR_PLUGIN_DIR . 'includes/' . $file . '.php'; |
| 46 |
|
| 47 |
// Include the file if it exists. |
| 48 |
if ( file_exists( $path ) ) { |
| 49 |
require_once $path; |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
|