Extends av-add-submenus.php to attach 3 editorial pages as children of
the 'Why Asterion' top-level menu item :
Why Asterion
├ About
├ Customers
└ Partners
Re-running ?av_add_submenus=1 is idempotent : Solutions / Industries /
Technology children stay as-is (matched by URL), only the new Why Asterion
children get inserted (menu items #150-152).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
152 lines
6.9 KiB
PHP
152 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Asterion — Add submenus to Header — Main + style nav-menu dropdown
|
|
* /?av_add_submenus=1
|
|
* 1. For each of Solutions, Industries, Technology (top-level items in
|
|
* Header — Main, term_id=9), adds child menu items pointing to the
|
|
* respective detail pages.
|
|
* 2. Updates the Bricks nav-menu element settings (hdrnav in template 25)
|
|
* with dropdown styling : navy background, gold hover, padding.
|
|
*
|
|
* Idempotent : skips children that already exist (matched by URL).
|
|
*/
|
|
defined('ABSPATH') || exit;
|
|
|
|
add_action('template_redirect', function () {
|
|
if (! in_array($_SERVER['SERVER_NAME'] ?? '', ['localhost', '127.0.0.1'], true)) return;
|
|
if (empty($_GET['av_add_submenus'])) return;
|
|
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
|
|
/* -----------------------------------------------------------------
|
|
1. Map slug → list of children for each top-level URL
|
|
----------------------------------------------------------------- */
|
|
$sub_menus = [
|
|
'/solutions/' => [
|
|
['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/'],
|
|
],
|
|
'/why-asterion/' => [
|
|
['title' => 'About', 'url' => '/about/'],
|
|
['title' => 'Customers', 'url' => '/customers/'],
|
|
['title' => 'Partners', 'url' => '/partners/'],
|
|
],
|
|
];
|
|
|
|
$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;
|
|
});
|