feat: Implement centralized module management system
- Add ModuleRegistry for managing built-in modules (newsletter, wishlist, affiliate, subscription, licensing) - Add ModulesController REST API for module enable/disable - Create Modules settings page with category grouping and toggle controls - Integrate module checks across admin-spa and customer-spa - Add useModules hook for both SPAs to check module status - Hide newsletter from footer builder when module disabled - Hide wishlist features when module disabled (product cards, account menu, wishlist page) - Protect wishlist API endpoints with module checks - Auto-update navigation tree when modules toggled - Clean up obsolete documentation files - Add comprehensive documentation: - MODULE_SYSTEM_IMPLEMENTATION.md - MODULE_INTEGRATION_SUMMARY.md - ADDON_MODULE_INTEGRATION.md (proposal) - ADDON_MODULE_DESIGN_DECISIONS.md (design doc) - FEATURE_ROADMAP.md - SHIPPING_INTEGRATION.md Module system provides: - Centralized enable/disable for all features - Automatic navigation updates - Frontend/backend integration - Foundation for addon-module unification
This commit is contained in:
223
includes/Core/ModuleRegistry.php
Normal file
223
includes/Core/ModuleRegistry.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* Module Registry
|
||||
*
|
||||
* Central registry for managing WooNooW modules (features).
|
||||
* Allows enabling/disabling modules to improve performance and reduce clutter.
|
||||
*
|
||||
* @package WooNooW\Core
|
||||
*/
|
||||
|
||||
namespace WooNooW\Core;
|
||||
|
||||
class ModuleRegistry {
|
||||
|
||||
/**
|
||||
* Get all registered modules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_all_modules() {
|
||||
$modules = [
|
||||
'newsletter' => [
|
||||
'id' => 'newsletter',
|
||||
'label' => __('Newsletter & Campaigns', 'woonoow'),
|
||||
'description' => __('Email newsletter subscription and campaign management', 'woonoow'),
|
||||
'category' => 'marketing',
|
||||
'icon' => 'mail',
|
||||
'default_enabled' => true,
|
||||
'features' => [
|
||||
__('Subscriber management', 'woonoow'),
|
||||
__('Email campaigns', 'woonoow'),
|
||||
__('Campaign scheduling', 'woonoow'),
|
||||
],
|
||||
],
|
||||
'wishlist' => [
|
||||
'id' => 'wishlist',
|
||||
'label' => __('Customer Wishlist', 'woonoow'),
|
||||
'description' => __('Allow customers to save products for later', 'woonoow'),
|
||||
'category' => 'customers',
|
||||
'icon' => 'heart',
|
||||
'default_enabled' => true,
|
||||
'features' => [
|
||||
__('Save products to wishlist', 'woonoow'),
|
||||
__('Wishlist page', 'woonoow'),
|
||||
__('Share wishlist', 'woonoow'),
|
||||
],
|
||||
],
|
||||
'affiliate' => [
|
||||
'id' => 'affiliate',
|
||||
'label' => __('Affiliate Program', 'woonoow'),
|
||||
'description' => __('Referral tracking and commission management', 'woonoow'),
|
||||
'category' => 'marketing',
|
||||
'icon' => 'users',
|
||||
'default_enabled' => false,
|
||||
'features' => [
|
||||
__('Referral tracking', 'woonoow'),
|
||||
__('Commission management', 'woonoow'),
|
||||
__('Affiliate dashboard', 'woonoow'),
|
||||
__('Payout system', 'woonoow'),
|
||||
],
|
||||
],
|
||||
'subscription' => [
|
||||
'id' => 'subscription',
|
||||
'label' => __('Product Subscriptions', 'woonoow'),
|
||||
'description' => __('Recurring product subscriptions with flexible billing', 'woonoow'),
|
||||
'category' => 'products',
|
||||
'icon' => 'refresh-cw',
|
||||
'default_enabled' => false,
|
||||
'features' => [
|
||||
__('Recurring billing', 'woonoow'),
|
||||
__('Subscription management', 'woonoow'),
|
||||
__('Automatic renewals', 'woonoow'),
|
||||
__('Trial periods', 'woonoow'),
|
||||
],
|
||||
],
|
||||
'licensing' => [
|
||||
'id' => 'licensing',
|
||||
'label' => __('Software Licensing', 'woonoow'),
|
||||
'description' => __('License key generation and validation for digital products', 'woonoow'),
|
||||
'category' => 'products',
|
||||
'icon' => 'key',
|
||||
'default_enabled' => false,
|
||||
'features' => [
|
||||
__('License key generation', 'woonoow'),
|
||||
__('Activation management', 'woonoow'),
|
||||
__('Validation API', 'woonoow'),
|
||||
__('Expiry management', 'woonoow'),
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return apply_filters('woonoow/modules/registry', $modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enabled modules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_enabled_modules() {
|
||||
$enabled = get_option('woonoow_enabled_modules', null);
|
||||
|
||||
// First time - use defaults
|
||||
if ($enabled === null) {
|
||||
$modules = self::get_all_modules();
|
||||
$enabled = [];
|
||||
foreach ($modules as $module) {
|
||||
if ($module['default_enabled']) {
|
||||
$enabled[] = $module['id'];
|
||||
}
|
||||
}
|
||||
update_option('woonoow_enabled_modules', $enabled);
|
||||
}
|
||||
|
||||
return $enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a module is enabled
|
||||
*
|
||||
* @param string $module_id
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_enabled($module_id) {
|
||||
$enabled = self::get_enabled_modules();
|
||||
return in_array($module_id, $enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable a module
|
||||
*
|
||||
* @param string $module_id
|
||||
* @return bool
|
||||
*/
|
||||
public static function enable($module_id) {
|
||||
$modules = self::get_all_modules();
|
||||
|
||||
if (!isset($modules[$module_id])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$enabled = self::get_enabled_modules();
|
||||
|
||||
if (!in_array($module_id, $enabled)) {
|
||||
$enabled[] = $module_id;
|
||||
update_option('woonoow_enabled_modules', $enabled);
|
||||
|
||||
// Clear navigation cache when module is toggled
|
||||
if (class_exists('\WooNooW\Compat\NavigationRegistry')) {
|
||||
\WooNooW\Compat\NavigationRegistry::flush();
|
||||
}
|
||||
|
||||
do_action('woonoow/module/enabled', $module_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable a module
|
||||
*
|
||||
* @param string $module_id
|
||||
* @return bool
|
||||
*/
|
||||
public static function disable($module_id) {
|
||||
$enabled = self::get_enabled_modules();
|
||||
|
||||
if (in_array($module_id, $enabled)) {
|
||||
$enabled = array_diff($enabled, [$module_id]);
|
||||
update_option('woonoow_enabled_modules', array_values($enabled));
|
||||
|
||||
// Clear navigation cache when module is toggled
|
||||
if (class_exists('\WooNooW\Compat\NavigationRegistry')) {
|
||||
\WooNooW\Compat\NavigationRegistry::flush();
|
||||
}
|
||||
|
||||
do_action('woonoow/module/disabled', $module_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get modules by category
|
||||
*
|
||||
* @param string $category
|
||||
* @return array
|
||||
*/
|
||||
public static function get_by_category($category) {
|
||||
$modules = self::get_all_modules();
|
||||
$enabled = self::get_enabled_modules();
|
||||
|
||||
$result = [];
|
||||
foreach ($modules as $module) {
|
||||
if ($module['category'] === $category) {
|
||||
$module['enabled'] = in_array($module['id'], $enabled);
|
||||
$result[] = $module;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all modules with enabled status
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function get_all_with_status() {
|
||||
$modules = self::get_all_modules();
|
||||
$enabled = self::get_enabled_modules();
|
||||
|
||||
foreach ($modules as $id => $module) {
|
||||
$modules[$id]['enabled'] = in_array($id, $enabled);
|
||||
}
|
||||
|
||||
return $modules;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user