Phase 2: Schema-Based Form System
- Add ModuleSettingsController with GET/POST/schema endpoints
- Create SchemaField component supporting 8 field types (text, textarea, email, url, number, toggle, checkbox, select)
- Create SchemaForm component for automatic form generation from schema
- Add ModuleSettings page with dynamic routing (/settings/modules/:moduleId)
- Add useModuleSettings React hook for settings management
- Implement NewsletterSettings as example with 8 configurable fields
- Add has_settings flag to module registry
- Settings stored as woonoow_module_{module_id}_settings
Phase 3: Advanced Features
- Create windowAPI.ts exposing React, hooks, components, icons, utils to addons via window.WooNooW
- Add DynamicComponentLoader for loading external React components
- Create TypeScript definitions (woonoow-addon.d.ts) for addon developers
- Initialize Window API in App.tsx on mount
- Enable custom React components for addon settings pages
Phase 4: Production Polish & Example
- Create complete Biteship addon example demonstrating both approaches:
* Schema-based settings (no build required)
* Custom React component (with build)
- Add comprehensive README with installation and testing guide
- Include package.json with esbuild configuration
- Demonstrate window.WooNooW API usage in custom component
Bug Fixes:
- Fix footer newsletter form visibility (remove redundant module check)
- Fix footer contact_data and social_links not saving (parameter name mismatch: snake_case vs camelCase)
- Fix useModules hook returning undefined (remove .data wrapper, add fallback)
- Add optional chaining to footer settings rendering
- Fix TypeScript errors in woonoow-addon.d.ts (use any for external types)
Files Added (15):
- includes/Api/ModuleSettingsController.php
- includes/Modules/NewsletterSettings.php
- admin-spa/src/components/forms/SchemaField.tsx
- admin-spa/src/components/forms/SchemaForm.tsx
- admin-spa/src/routes/Settings/ModuleSettings.tsx
- admin-spa/src/hooks/useModuleSettings.ts
- admin-spa/src/lib/windowAPI.ts
- admin-spa/src/components/DynamicComponentLoader.tsx
- types/woonoow-addon.d.ts
- examples/biteship-addon/biteship-addon.php
- examples/biteship-addon/src/Settings.jsx
- examples/biteship-addon/package.json
- examples/biteship-addon/README.md
- PHASE_2_3_4_SUMMARY.md
Files Modified (11):
- admin-spa/src/App.tsx
- admin-spa/src/hooks/useModules.ts
- admin-spa/src/routes/Appearance/Footer.tsx
- admin-spa/src/routes/Settings/Modules.tsx
- customer-spa/src/hooks/useModules.ts
- customer-spa/src/layouts/BaseLayout.tsx
- customer-spa/src/components/NewsletterForm.tsx
- includes/Api/Routes.php
- includes/Api/ModulesController.php
- includes/Core/ModuleRegistry.php
- woonoow.php
API Endpoints Added:
- GET /woonoow/v1/modules/{module_id}/settings
- POST /woonoow/v1/modules/{module_id}/settings
- GET /woonoow/v1/modules/{module_id}/schema
For Addon Developers:
- Schema-based: Define settings via woonoow/module_settings_schema filter
- Custom React: Build component using window.WooNooW API, externalize react/react-dom
- Both approaches use same storage and retrieval methods
- TypeScript definitions provided for type safety
- Complete working example (Biteship) included
50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: WooNooW
|
|
* Description: The modern experience layer for WooCommerce (no migration, no risk).
|
|
* Version: 0.1.0
|
|
* Author: WooNooW
|
|
* Requires Plugins: woocommerce
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
// Define plugin constants
|
|
define('WOONOOW_PATH', plugin_dir_path(__FILE__));
|
|
define('WOONOOW_URL', plugin_dir_url(__FILE__));
|
|
define('WOONOOW_VERSION', '0.1.0');
|
|
|
|
spl_autoload_register(function ($class) {
|
|
$prefix = 'WooNooW\\';
|
|
$base_dir = __DIR__ . '/includes/';
|
|
if (strncmp($prefix, $class, strlen($prefix)) !== 0) return;
|
|
$relative = substr($class, strlen($prefix));
|
|
$file = $base_dir . str_replace('\\', '/', $relative) . '.php';
|
|
if (file_exists($file)) require $file;
|
|
});
|
|
|
|
// Load translations on init hook (WordPress 6.7+ requirement)
|
|
add_action('init', function() {
|
|
load_plugin_textdomain('woonoow', false, dirname(plugin_basename(__FILE__)) . '/languages');
|
|
});
|
|
|
|
add_action('plugins_loaded', function () {
|
|
if (!class_exists('WooCommerce')) {
|
|
add_action('admin_notices', function () {
|
|
echo '<div class="notice notice-error"><p>WooNooW membutuhkan WooCommerce aktif.</p></div>';
|
|
});
|
|
return;
|
|
}
|
|
WooNooW\Core\Bootstrap::init();
|
|
|
|
// Initialize module settings
|
|
WooNooW\Modules\NewsletterSettings::init();
|
|
});
|
|
|
|
// Activation/Deactivation hooks
|
|
register_activation_hook(__FILE__, ['WooNooW\Core\Installer', 'activate']);
|
|
register_deactivation_hook(__FILE__, ['WooNooW\Core\Installer', 'deactivate']);
|
|
|
|
// Dev mode filters removed - use wp-config.php if needed:
|
|
// add_filter('woonoow/admin_is_dev', '__return_true');
|
|
// add_filter('woonoow/admin_dev_server', fn() => 'https://woonoow.local:5173');
|