fix: resolve container width issues, spa redirects, and appearance settings overwrite. feat: enhance order/sub details and newsletter layout
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace WooNooW\Compat;
|
||||
|
||||
if ( ! defined('ABSPATH') ) exit;
|
||||
if (! defined('ABSPATH')) exit;
|
||||
|
||||
/**
|
||||
* Navigation Registry
|
||||
@@ -11,36 +12,39 @@ if ( ! defined('ABSPATH') ) exit;
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class NavigationRegistry {
|
||||
class NavigationRegistry
|
||||
{
|
||||
const NAV_OPTION = 'wnw_nav_tree';
|
||||
const NAV_VERSION = '1.3.0'; // Added Subscriptions section
|
||||
|
||||
|
||||
/**
|
||||
* Initialize hooks
|
||||
*/
|
||||
public static function init() {
|
||||
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() {
|
||||
public static function build_nav_tree()
|
||||
{
|
||||
// Check if we need to rebuild (version mismatch)
|
||||
$cached = get_option(self::NAV_OPTION, []);
|
||||
$cached_version = $cached['version'] ?? '';
|
||||
|
||||
|
||||
if ($cached_version === self::NAV_VERSION && !empty($cached['tree'])) {
|
||||
// Cache is valid, no need to rebuild
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Base navigation tree (core WooNooW sections)
|
||||
$tree = self::get_base_tree();
|
||||
|
||||
|
||||
/**
|
||||
* Filter: woonoow/nav_tree
|
||||
*
|
||||
@@ -64,7 +68,7 @@ class NavigationRegistry {
|
||||
* });
|
||||
*/
|
||||
$tree = apply_filters('woonoow/nav_tree', $tree);
|
||||
|
||||
|
||||
// Allow per-section modification
|
||||
foreach ($tree as &$section) {
|
||||
$key = $section['key'] ?? '';
|
||||
@@ -90,7 +94,7 @@ class NavigationRegistry {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Store in option
|
||||
update_option(self::NAV_OPTION, [
|
||||
'version' => self::NAV_VERSION,
|
||||
@@ -98,13 +102,14 @@ class NavigationRegistry {
|
||||
'updated' => time(),
|
||||
], false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get base navigation tree (core sections)
|
||||
*
|
||||
* @return array Base navigation tree
|
||||
*/
|
||||
private static function get_base_tree(): array {
|
||||
private static function get_base_tree(): array
|
||||
{
|
||||
$tree = [
|
||||
[
|
||||
'key' => 'dashboard',
|
||||
@@ -198,37 +203,39 @@ class NavigationRegistry {
|
||||
'children' => [], // Empty array = no submenu bar
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get marketing submenu children
|
||||
*
|
||||
* @return array Marketing submenu items
|
||||
*/
|
||||
private static function get_marketing_children(): array {
|
||||
private static function get_marketing_children(): array
|
||||
{
|
||||
$children = [];
|
||||
|
||||
|
||||
// Newsletter - only if module enabled
|
||||
if (\WooNooW\Core\ModuleRegistry::is_enabled('newsletter')) {
|
||||
$children[] = ['label' => __('Newsletter', 'woonoow'), 'mode' => 'spa', 'path' => '/marketing/newsletter'];
|
||||
}
|
||||
|
||||
|
||||
// Coupons - always available
|
||||
$children[] = ['label' => __('Coupons', 'woonoow'), 'mode' => 'spa', 'path' => '/coupons'];
|
||||
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get settings submenu children
|
||||
*
|
||||
* @return array Settings submenu items
|
||||
*/
|
||||
private static function get_settings_children(): array {
|
||||
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'],
|
||||
@@ -236,25 +243,27 @@ class NavigationRegistry {
|
||||
['label' => __('Shipping & Delivery', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/shipping'],
|
||||
['label' => __('Tax', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/tax'],
|
||||
['label' => __('Customers', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/customers'],
|
||||
['label' => __('Security', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/security'],
|
||||
['label' => __('Notifications', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/notifications'],
|
||||
['label' => __('Modules', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/modules'],
|
||||
['label' => __('Developer', 'woonoow'), 'mode' => 'spa', 'path' => '/settings/developer'],
|
||||
];
|
||||
|
||||
|
||||
return $children;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get subscriptions navigation section
|
||||
* Returns empty array if module is not enabled
|
||||
*
|
||||
* @return array Subscriptions section or empty array
|
||||
*/
|
||||
private static function get_subscriptions_section(): array {
|
||||
private static function get_subscriptions_section(): array
|
||||
{
|
||||
if (!\WooNooW\Core\ModuleRegistry::is_enabled('subscription')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
return [
|
||||
[
|
||||
'key' => 'subscriptions',
|
||||
@@ -267,24 +276,26 @@ class NavigationRegistry {
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the complete navigation tree
|
||||
*
|
||||
* @return array Navigation tree
|
||||
*/
|
||||
public static function get_nav_tree(): array {
|
||||
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 {
|
||||
public static function get_section(string $key): ?array
|
||||
{
|
||||
$tree = self::get_nav_tree();
|
||||
foreach ($tree as $section) {
|
||||
if (($section['key'] ?? '') === $key) {
|
||||
@@ -293,22 +304,24 @@ class NavigationRegistry {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Flush navigation cache
|
||||
*/
|
||||
public static function flush() {
|
||||
public static function flush()
|
||||
{
|
||||
delete_option(self::NAV_OPTION);
|
||||
// Rebuild immediately after flush
|
||||
self::build_nav_tree();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get navigation tree for frontend
|
||||
*
|
||||
* @return array Array suitable for JSON encoding
|
||||
*/
|
||||
public static function get_frontend_nav_tree(): array {
|
||||
public static function get_frontend_nav_tree(): array
|
||||
{
|
||||
return self::get_nav_tree();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user