I'm working on plugin that uses autoloader from composer. But for some reason, when I'm creating new object, PHP loads different autoloader from different plugin, and all my work is not accessible. So here is composer.json:
{
"autoload": {
"psr-4": {
"CustomizableProduct\\": "inc"
}
},
"config": {
"vendor-dir": "lib"
}
}
That's how I'm trying to load base plugin class in my_plugin.php file:
define('MY_PLUGIN_PATH', plugin_dir_path(__FILE__));
add_action('init', function () {
require_once MY_PLUGIN_PATH . "/lib/autoload.php";
new \CustomizableProduct\CustomizableProduct();
});
Every time PHP shows me error that class was not found. BUT when I'm dumping autoload with optimize-autoloader param, suddenly it works great.
Ok, I can live with that optimized autoloader, but I need to load Woocommerce classes to create custom product type. Unfortunately, changing composer.json to
"autoload": {
"psr-4": {
"CustomizableProduct\\": "inc",
"Woocommerce\\": "../woocommerce"
}
},
or with simpler, global version
"autoload": {
"psr-4": {
"CustomizableProduct\\": "inc",
"\\": "../"
}
},
not working, even with dumping autoloader with optimization param.
I have no idea what to do. Am I doing something wrong? I'm thinking about setting my own autoloader, or eventually just to create file only with include_once, including all my classes.