diff --git a/comment-hacks.php b/comment-hacks.php index 40a8e31..e17cf6e 100644 --- a/comment-hacks.php +++ b/comment-hacks.php @@ -29,6 +29,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +use EmiliaProjects\WP\Comment\Inc\Autoload; use EmiliaProjects\WP\Comment\Inc\Hacks; /** @@ -45,9 +46,7 @@ define( 'EMILIA_COMMENT_HACKS_PATH', plugin_dir_path( __FILE__ ) ); } -/* ***************************** CLASS AUTOLOADING *************************** */ -if ( file_exists( EMILIA_COMMENT_HACKS_PATH . 'vendor/autoload.php' ) ) { - require EMILIA_COMMENT_HACKS_PATH . 'vendor/autoload.php'; -} +require_once EMILIA_COMMENT_HACKS_PATH . 'inc/autoload.php'; +new Autoload(); new Hacks(); diff --git a/composer.json b/composer.json index efb9034..a80c18c 100644 --- a/composer.json +++ b/composer.json @@ -41,12 +41,6 @@ }, "minimum-stability": "dev", "prefer-stable": true, - "autoload": { - "classmap": [ - "admin/", - "inc/" - ] - }, "autoload-dev": { "classmap": [ "tests/" diff --git a/inc/autoload.php b/inc/autoload.php new file mode 100644 index 0000000..f3e6555 --- /dev/null +++ b/inc/autoload.php @@ -0,0 +1,46 @@ + 'admin/admin.php', + 'EmiliaProjects\WP\Comment\Admin\Comment_Parent' => 'admin/comment-parent.php', + 'EmiliaProjects\WP\Comment\Inc\Clean_Emails' => 'inc/clean-emails.php', + 'EmiliaProjects\WP\Comment\Inc\Email_Links' => 'inc/email-links.php', + 'EmiliaProjects\WP\Comment\Inc\Forms' => 'inc/forms.php', + 'EmiliaProjects\WP\Comment\Inc\Hacks' => 'inc/hacks.php', + 'EmiliaProjects\WP\Comment\Inc\Length' => 'inc/length.php', + 'EmiliaProjects\WP\Comment\Inc\Notifications' => 'inc/notifications.php', + ]; + + /** + * Constructor. + * + * Register the autoloader. + */ + public function __construct() { + \spl_autoload_register( [ __CLASS__, 'autoload' ] ); + } + + /** + * Autoload the classes. + * + * @param string $class_name The class name. + */ + public static function autoload( string $class_name ): void { + if ( ! isset( static::$classmap[ $class_name ] ) ) { + return; + } + require_once EMILIA_COMMENT_HACKS_PATH . static::$classmap[ $class_name ]; + } +}