Files
WooNooW/includes/Compat/NavigationRegistry.php
dwindown b39c1f1a95 refactor: Eliminate bloated settings tabs (13→5)
## Changes

### 1. Eliminated Unnecessary Tabs 

**Before:** 13 tabs (bloated!)
**After:** 5 tabs (clean, focused)

**Removed:**
-  WooNooW (nonsense toggles for essential features)
-  Checkout (mirror WooCommerce, not essential)
-  Customer Accounts (mirror WooCommerce, not essential)
-  Brand & Appearance (merged into Store Details)
-  Advanced (just redirected to WC)
-  Integrations (just redirected to WC)
-  System Status (just redirected to WC)
-  Extensions (just redirected to WC)

**Kept:**
-  Store Details (will enhance with branding)
-  Payments (existing, working)
-  Shipping & Delivery (existing, working)
-  Tax (existing, working)
-  Notifications (existing, working)

**Added:**
-  Developer (debug mode, API logs, system info)

---

### 2. Created Refined Implementation Plan V2 

**Document:** SETTINGS_PAGES_PLAN_V2.md

**Key Decisions:**

####  What We Build:
- Essential settings accessed frequently
- Simplified UI for complex WooCommerce features
- Industry best practices (Shopify, marketplaces)
- Critical features that enhance WooCommerce

####  What We Don't Build:
- Mirroring WooCommerce as-is
- Nonsense toggles for essential features
- Settings for non-tech users to break things
- Redundant configuration options

#### Philosophy:
> "We do the best config. Users focus on their business, not system configuration."

---

### 3. Specific Rejections (Based on Feedback)

**WooNooW Settings - ALL REJECTED:**
-  Plugin Version (can be anywhere)
-  Enable SPA Mode (plugin activation = enabled)
-  Admin Theme toggle (will be in topbar)
-  Items per page (per-table setting)
-  Enable caching (we do best config)
-  Cache duration (confusing for non-tech)
-  Preload data (we optimize)
-  Enable quick edit (essential, always on)
-  Enable bulk actions (essential, always on)
-  Enable keyboard shortcuts (essential, always on)
-  Enable auto-save (essential, always on)

**Brand & Appearance - MERGED TO STORE DETAILS:**
-  Store logo (merge to Store Details)
-  Store icon (merge to Store Details)
-  Store tagline (merge to Store Details)
-  Brand colors (merge to Store Details)
-  Typography (breaks design)
-  Font size (use browser zoom)
-  Sidebar position (we optimize)
-  Sidebar collapsed (we optimize)
-  Show breadcrumbs (we optimize)
-  Compact mode (we optimize)
-  Custom CSS (hard to use, move to Developer if needed)

**Checkout & Customer Accounts - NOT BUILDING:**
- We do the best config (industry standard)
- No need to mirror WooCommerce complexity
- Focus on business, not system configuration
- Users can use WC native settings if needed

---

### 4. Final Structure

```
Settings (5 tabs)
├── Store Details (enhanced with branding)
├── Payments (existing)
├── Shipping & Delivery (existing)
├── Tax (existing)
├── Notifications (existing)
└── Developer (new - debug, system info, cache)
```

---

### 5. Updated Both Backend and Frontend

**Backend:** NavigationRegistry.php
- Removed 8 tabs
- Added Developer tab
- Changed main settings path to /settings/store

**Frontend:** nav/tree.ts (fallback)
- Synced with backend
- Removed WooNooW tab
- Added Developer tab

---

## Philosophy

**We do the best config:**
- Essential features always enabled
- No confusing toggles
- Industry best practices
- Focus on business, not system

**Result:**
- 13 tabs → 5 tabs (62% reduction!)
- Clean, focused interface
- Professional
- Easy to use
- No bloat
2025-11-10 21:50:28 +07:00

234 lines
8.5 KiB
PHP

<?php
namespace WooNooW\Compat;
if ( ! defined('ABSPATH') ) exit;
/**
* Navigation Registry
*
* Manages dynamic navigation tree building. Allows addons to inject
* menu items into the main navigation or existing sections.
*
* @since 1.0.0
*/
class NavigationRegistry {
const NAV_OPTION = 'wnw_nav_tree';
const NAV_VERSION = '1.0.0';
/**
* Initialize hooks
*/
public static function init() {
// Use 'init' hook instead of 'plugins_loaded' to avoid translation loading warnings (WP 6.7+)
add_action('init', [__CLASS__, 'build_nav_tree'], 10);
add_action('activated_plugin', [__CLASS__, 'flush']);
add_action('deactivated_plugin', [__CLASS__, 'flush']);
}
/**
* Build the complete navigation tree
*/
public static function build_nav_tree() {
// Base navigation tree (core WooNooW sections)
$tree = self::get_base_tree();
/**
* Filter: woonoow/nav_tree
*
* Allows addons to modify the entire navigation tree.
*
* @param array $tree Array of main navigation nodes
*
* Example:
* add_filter('woonoow/nav_tree', function($tree) {
* $tree[] = [
* 'key' => 'subscriptions',
* 'label' => 'Subscriptions',
* 'path' => '/subscriptions',
* 'icon' => 'repeat', // lucide icon name
* 'children' => [
* ['label' => 'All Subscriptions', 'mode' => 'spa', 'path' => '/subscriptions'],
* ['label' => 'New', 'mode' => 'spa', 'path' => '/subscriptions/new'],
* ],
* ];
* return $tree;
* });
*/
$tree = apply_filters('woonoow/nav_tree', $tree);
// Allow per-section modification
foreach ($tree as &$section) {
$key = $section['key'] ?? '';
if ($key) {
/**
* Filter: woonoow/nav_tree/{key}/children
*
* Allows addons to inject items into specific sections.
*
* Example:
* add_filter('woonoow/nav_tree/products/children', function($children) {
* $children[] = [
* 'label' => 'Bundles',
* 'mode' => 'spa',
* 'path' => '/products/bundles',
* ];
* return $children;
* });
*/
$section['children'] = apply_filters(
"woonoow/nav_tree/{$key}/children",
$section['children'] ?? []
);
}
}
// Store in option
update_option(self::NAV_OPTION, [
'version' => self::NAV_VERSION,
'tree' => $tree,
'updated' => time(),
], false);
}
/**
* Get base navigation tree (core sections)
*
* @return array Base navigation tree
*/
private static function get_base_tree(): array {
return [
[
'key' => 'dashboard',
'label' => __('Dashboard', 'woonoow'),
'path' => '/',
'icon' => 'layout-dashboard',
'children' => [
['label' => __('Overview', 'woonoow'), 'mode' => 'spa', 'path' => '/', 'exact' => true],
['label' => __('Revenue', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/revenue'],
['label' => __('Orders', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/orders'],
['label' => __('Products', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/products'],
['label' => __('Customers', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/customers'],
['label' => __('Coupons', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/coupons'],
['label' => __('Taxes', 'woonoow'), 'mode' => 'spa', 'path' => '/dashboard/taxes'],
],
],
[
'key' => 'orders',
'label' => __('Orders', 'woonoow'),
'path' => '/orders',
'icon' => 'receipt-text',
'children' => [], // Orders has no submenu by design
],
[
'key' => 'products',
'label' => __('Products', 'woonoow'),
'path' => '/products',
'icon' => 'package',
'children' => [
['label' => __('All products', 'woonoow'), 'mode' => 'spa', 'path' => '/products'],
['label' => __('New', 'woonoow'), 'mode' => 'spa', 'path' => '/products/new'],
['label' => __('Categories', 'woonoow'), 'mode' => 'spa', 'path' => '/products/categories'],
['label' => __('Tags', 'woonoow'), 'mode' => 'spa', 'path' => '/products/tags'],
['label' => __('Attributes', 'woonoow'), 'mode' => 'spa', 'path' => '/products/attributes'],
],
],
[
'key' => 'coupons',
'label' => __('Coupons', 'woonoow'),
'path' => '/coupons',
'icon' => 'tag',
'children' => [
['label' => __('All coupons', 'woonoow'), 'mode' => 'spa', 'path' => '/coupons'],
['label' => __('New', 'woonoow'), 'mode' => 'spa', 'path' => '/coupons/new'],
],
],
[
'key' => 'customers',
'label' => __('Customers', 'woonoow'),
'path' => '/customers',
'icon' => 'users',
'children' => [
['label' => __('All customers', 'woonoow'), 'mode' => 'spa', 'path' => '/customers'],
],
],
[
'key' => 'settings',
'label' => __('Settings', 'woonoow'),
'path' => '/settings',
'icon' => 'settings',
'children' => self::get_settings_children(),
],
];
}
/**
* Get settings submenu children
*
* @return array Settings submenu items
*/
private static function get_settings_children(): array {
$admin = admin_url('admin.php');
$children = [
// Core Settings (Shopify-inspired)
['label' => __('Store Details', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/store'],
['label' => __('Payments', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/payments'],
['label' => __('Shipping & Delivery', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/shipping'],
];
// Only show Tax if enabled in WooCommerce
if (wc_tax_enabled()) {
$children[] = ['label' => __('Tax', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/tax'];
}
$children = array_merge($children, [
['label' => __('Notifications', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/notifications'],
['label' => __('Developer', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/developer'],
]);
return $children;
}
/**
* Get the complete navigation tree
*
* @return array Navigation tree
*/
public static function get_nav_tree(): array {
$data = get_option(self::NAV_OPTION, []);
return $data['tree'] ?? self::get_base_tree();
}
/**
* Get a specific section by key
*
* @param string $key Section key
* @return array|null Section data or null if not found
*/
public static function get_section(string $key): ?array {
$tree = self::get_nav_tree();
foreach ($tree as $section) {
if (($section['key'] ?? '') === $key) {
return $section;
}
}
return null;
}
/**
* Flush the navigation cache
*/
public static function flush() {
delete_option(self::NAV_OPTION);
}
/**
* Get navigation tree for frontend
*
* @return array Array suitable for JSON encoding
*/
public static function get_frontend_nav_tree(): array {
return self::get_nav_tree();
}
}