I am trying to work with autoloader in my plugin.
In the main file of my plugin I have
use My_Plugin\Includes;
require_once( plugin_dir_path( __FILE__ ) . 'includes/class-autoloader.php' );
$autoloader = new Includes\Autoloader();
And in my includes/class-autoloader.php
file I have
namespace My_Plugin\Includes;
class Autoloader() {
public __construct() {
spl_autoload_register( [ $this, 'autoloader' ] );
}
public autoloader( $class_name ) {
error_log( print_r( $class_name, true ) );
if ( strpos( $class_name, 'My_Plugin' ) === false ) {
return;
}
}
}
But none of the classes that I have in my plugin will be shown in my error_log.txt
. I see classes from WooCommerce which I have activated on my test site.
Why am I not seeing my classes in the plugin?