first commit all files
This commit is contained in:
74
includes/class-autoloader.php
Normal file
74
includes/class-autoloader.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Autoloader for WP Agentic Writer classes.
|
||||
*
|
||||
* @package WP_Agentic_Writer
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class WP_Agentic_Writer_Autoloader
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class WP_Agentic_Writer_Autoloader {
|
||||
|
||||
/**
|
||||
* Singleton instance.
|
||||
*
|
||||
* @var WP_Agentic_Writer_Autoloader
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Get singleton instance.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @return WP_Agentic_Writer_Autoloader
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
private function __construct() {
|
||||
spl_autoload_register( array( $this, 'autoload' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload classes.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @param string $class Class name.
|
||||
*/
|
||||
public function autoload( $class ) {
|
||||
// Check if class is in our namespace.
|
||||
if ( strpos( $class, 'WP_Agentic_Writer_' ) !== 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove namespace prefix.
|
||||
$class_name = str_replace( 'WP_Agentic_Writer_', '', $class );
|
||||
$class_name = strtolower( str_replace( '_', '-', $class_name ) );
|
||||
|
||||
// Build file path.
|
||||
$file_path = WP_AGENTIC_WRITER_DIR . 'includes/class-' . $class_name . '.php';
|
||||
|
||||
// Include file if exists.
|
||||
if ( file_exists( $file_path ) ) {
|
||||
require_once $file_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WP_Agentic_Writer_Autoloader::get_instance();
|
||||
Reference in New Issue
Block a user