I've been researching autoloaders in wordpress and have been using them in custom plugins with no issues - however I wanted to try using it in a functions file inside a custom theme and it's not working random classes are being auto loaded. My question is can I use a custom autoloader in the functions.php file
some code is below:
spl_autoload_register('my_class_file_autoloader');
function my_class_file_autoloader($class_name) {
if(0 !== strpos($class_name, 'Mt')) {
return;
}
$class_name = strtolower($class_name);
require get_template_directory() . '/classes/' . $class_name . '.php';}
classes are inside a classes folder, filenames are mt_class.php and the class name is Mt_Class
Any help is appreciated