| @@ -1,20 +1,39 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace RadiusTheme\SB\Modules; |
| 4 | + | |
| 4 | 5 | defined( 'ABSPATH' ) || exit(); |
| 5 | 6 | |
| 6 | 7 | use RadiusTheme\SB\Models\ModuleList; |
| 7 | - | |
| 8 | 8 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 9 | 9 | |
| 10 | +/** | |
| 11 | + * Module Manager class. | |
| 12 | + * | |
| 13 | + * Handles loading and instantiation of all plugin modules. | |
| 14 | + */ | |
| 10 | 15 | class ModuleManager { |
| 11 | 16 | |
| 12 | 17 | use SingletonTrait; |
| 13 | 18 | |
| 19 | + /** | |
| 20 | + * Module list. | |
| 21 | + * | |
| 22 | + * @var array|null | |
| 23 | + */ | |
| 14 | 24 | private $module_list; |
| 15 | 25 | |
| 16 | - private $module_instances = array(); | |
| 26 | + /** | |
| 27 | + * Module instances. | |
| 28 | + * | |
| 29 | + * @var array | |
| 30 | + */ | |
| 31 | + private $module_instances = []; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Constructor. | |
| 35 | + */ | |
| 17 | 36 | private function __construct() { |
| 18 | 37 | add_action( 'init', [ $this, 'load_modules' ], 15 ); |
| 19 | 38 | } |
| 20 | 39 | |
| @@ -43,21 +62,14 @@ | ||
| 43 | 62 | if ( ! class_exists( $module['base_class'] ) ) { |
| 44 | 63 | continue; |
| 45 | 64 | } |
| 46 | 65 | |
| 47 | - // Check if the instance is already in the cache | |
| 48 | - $cached_instance = wp_cache_get( $module['base_class'], 'module_instances' ); | |
| 49 | - if ( false === $cached_instance ) { | |
| 50 | - // Create an instance and store it in the cache | |
| 51 | - $this->module_instances[ $module['base_class'] ] = $module['base_class']::instance(); | |
| 52 | - wp_cache_set( $module['base_class'], $this->module_instances[ $module['base_class'] ], 'module_instances' ); | |
| 53 | - } else { | |
| 54 | - // Use the cached instance | |
| 55 | - $this->module_instances[ $module['base_class'] ] = $cached_instance; | |
| 66 | + try { | |
| 67 | + $module['base_class']::instance(); | |
| 68 | + } catch ( \Throwable $e ) { | |
| 69 | + error_log( 'ShopBuilder module error (' . $module['base_class'] . '): ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | |
| 70 | + continue; | |
| 56 | 71 | } |
| 57 | 72 | |
| 58 | 73 | } |
| 59 | - | |
| 60 | 74 | } |
| 61 | - | |
| 62 | - | |
| 63 | -} | |
| 75 | +} | |