diff --git a/tools/av-add-submenus.php b/tools/av-add-submenus.php new file mode 100644 index 0000000..cb26886 --- /dev/null +++ b/tools/av-add-submenus.php @@ -0,0 +1,146 @@ + [ + ['title' => 'MY PROSERVE', 'url' => '/solutions/my-proserve/'], + ['title' => 'PROSERVE FLEX', 'url' => '/solutions/proserve-flex/'], + ['title' => 'PROSERVE ACADEMY', 'url' => '/solutions/proserve-academy/'], + ['title' => 'PROSERVE+', 'url' => '/solutions/customization/'], + ], + '/industries/' => [ + ['title' => 'Police', 'url' => '/industries/police/'], + ['title' => 'Special Forces', 'url' => '/industries/special-forces/'], + ['title' => 'Military', 'url' => '/industries/military/'], + ['title' => 'Firefighters', 'url' => '/industries/firefighters/'], + ], + '/technology/' => [ + ['title' => 'VR Hardware', 'url' => '/technology/vr-hardware/'], + ['title' => 'Software & AI', 'url' => '/technology/software-ai/'], + ['title' => 'Weapons & Tracking', 'url' => '/technology/weapons-tracking/'], + ['title' => 'Scenarios', 'url' => '/technology/scenarios/'], + ['title' => 'Instructor Cockpit', 'url' => '/technology/instructor-cockpit/'], + ['title' => 'After-Action Review', 'url' => '/technology/after-action-review/'], + ], + ]; + + $term_id = 9; // Header — Main + $existing = wp_get_nav_menu_items($term_id) ?: []; + $by_url = []; + foreach ($existing as $item) { + $by_url[$item->url] = $item; + } + + $total_added = 0; + foreach ($sub_menus as $parent_url => $children) { + if (! isset($by_url[$parent_url])) { + echo " Parent $parent_url not found in menu — skipping\n"; + continue; + } + $parent_id = $by_url[$parent_url]->ID; + echo "── Parent '{$by_url[$parent_url]->title}' (#$parent_id, url=$parent_url) ──\n"; + + foreach ($children as $child) { + if (isset($by_url[$child['url']])) { + echo " '{$child['title']}' ({$child['url']}) already exists (#{$by_url[$child['url']]->ID}) — skip\n"; + continue; + } + $new_id = wp_update_nav_menu_item($term_id, 0, [ + 'menu-item-title' => $child['title'], + 'menu-item-url' => $child['url'], + 'menu-item-type' => 'custom', + 'menu-item-status' => 'publish', + 'menu-item-parent-id' => $parent_id, + ]); + if (is_wp_error($new_id) || ! $new_id) { + echo " '{$child['title']}' : FAILED\n"; + } else { + echo " '{$child['title']}' → #$new_id (parent=$parent_id)\n"; + $total_added++; + } + } + echo "\n"; + } + + echo "Added $total_added new menu item(s).\n\n"; + + /* ----------------------------------------------------------------- + 2. Patch nav-menu element 'hdrnav' settings : dropdown styling + ----------------------------------------------------------------- */ + global $wpdb; + foreach (['_bricks_page_content_2', '_bricks_page_header_2'] as $key) { + $val = $wpdb->get_var($wpdb->prepare( + "SELECT meta_value FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s LIMIT 1", + 25, $key + )); + if (! is_string($val) || $val === '') continue; + $is_json = ($val[0] === '['); + $elements = $is_json ? json_decode($val, true) : @unserialize($val); + if (! is_array($elements)) continue; + + $modified = false; + foreach ($elements as $i => $el) { + if (($el['id'] ?? '') !== 'hdrnav') continue; + + // Dropdown background + padding + typography + $elements[$i]['settings']['subMenuBackgroundColor'] = ['hex' => '#0B1F3A', 'raw' => 'var(--color-brand-navy)']; + $elements[$i]['settings']['subMenuBorder'] = [ + 'width' => ['top' => '1px', 'right' => '1px', 'bottom' => '1px', 'left' => '1px'], + 'color' => ['raw' => 'rgba(201, 164, 90, 0.2)'], + 'style' => 'solid', + ]; + $elements[$i]['settings']['subMenuPadding'] = [ + 'top' => '0.5rem', 'right' => '0', 'bottom' => '0.5rem', 'left' => '0', + ]; + $elements[$i]['settings']['subMenuItemPadding'] = [ + 'top' => '0.6rem', 'right' => '1.25rem', 'bottom' => '0.6rem', 'left' => '1.25rem', + ]; + $elements[$i]['settings']['subMenuTypography'] = [ + 'color' => ['raw' => 'var(--color-text-on-dark)'], + 'font-size' => '0.875rem', + 'font-weight' => '500', + 'text-decoration' => 'none', + 'white-space' => 'nowrap', + ]; + $elements[$i]['settings']['subMenuItemHoverTypography'] = [ + 'color' => ['raw' => 'var(--color-brand-gold)'], + ]; + $elements[$i]['settings']['subMenuMinWidth'] = '14rem'; + // Show arrow indicator next to parents with submenu + $elements[$i]['settings']['subMenuIndicator'] = true; + + $modified = true; + break; + } + if ($modified) { + $new = $is_json ? wp_json_encode($elements) : maybe_serialize($elements); + $wpdb->update($wpdb->postmeta, ['meta_value' => $new], + ['post_id' => 25, 'meta_key' => $key], ['%s'], ['%d', '%s']); + wp_cache_delete(25, 'post_meta'); + echo " $key : hdrnav settings updated (dropdown styling)\n"; + } + } + + echo "\nDONE. Reload the site → hover Solutions/Industries/Technology in header → submenu drops down.\n"; + exit; +});