From fd2d748f4815032e4ca6a2a9987cf48bee7ec8b1 Mon Sep 17 00:00:00 2001 From: Daryll Doyle Date: Wed, 15 Feb 2023 13:07:19 +0000 Subject: [PATCH] Fix issue with static classes Because the classfinder uses static methods, it only works on a single application root. To get around this, we need to manually set the application root before we look for classes in a namespace, so that it can find the right composer.json file --- .../10up-plugin/includes/classes/ModuleInitialization.php | 4 +++- themes/10up-theme/includes/classes/ModuleInitialization.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mu-plugins/10up-plugin/includes/classes/ModuleInitialization.php b/mu-plugins/10up-plugin/includes/classes/ModuleInitialization.php index b5a8ea87..bf22ec64 100644 --- a/mu-plugins/10up-plugin/includes/classes/ModuleInitialization.php +++ b/mu-plugins/10up-plugin/includes/classes/ModuleInitialization.php @@ -56,7 +56,9 @@ private function __construct() { * @return array */ protected function get_classes() { - return ClassFinder::getClassesInNamespace( 'TenUpPlugin', ClassFinder::RECURSIVE_MODE ); + $class_finder = new ClassFinder(); + $class_finder::setAppRoot( TENUP_PLUGIN_PATH ); + return $class_finder::getClassesInNamespace( 'TenUpPlugin', ClassFinder::RECURSIVE_MODE ); } /** diff --git a/themes/10up-theme/includes/classes/ModuleInitialization.php b/themes/10up-theme/includes/classes/ModuleInitialization.php index a80628ba..ce71761f 100644 --- a/themes/10up-theme/includes/classes/ModuleInitialization.php +++ b/themes/10up-theme/includes/classes/ModuleInitialization.php @@ -56,7 +56,9 @@ private function __construct() { * @return array */ protected function get_classes() { - return ClassFinder::getClassesInNamespace( 'TenUpTheme', ClassFinder::RECURSIVE_MODE ); + $class_finder = new ClassFinder(); + $class_finder::setAppRoot( TENUP_THEME_PATH ); + return $class_finder::getClassesInNamespace( 'TenUpTheme', ClassFinder::RECURSIVE_MODE ); } /**