gradient > color) so old headers keep rendering
* exactly as they did before.
*/
function adaire_header_get_effective_background_type( $attributes ) {
if ( ! empty( $attributes['backgroundType'] ) ) {
return $attributes['backgroundType'];
}
if ( ! empty( $attributes['bgImageUrl'] ) ) {
return 'image';
}
if ( ! empty( $attributes['useGradient'] ) ) {
return 'gradient';
}
return 'color';
}
}
if ( ! function_exists( 'adaire_header_get_style_vars' ) ) {
/**
* Mirrors save.js getHeaderStyle() (same CSS var names/values, same
* conditional inclusion logic) with one intentional improvement: it now
* also emits background-image vars when backgroundType resolves to
* "image", because save.js/the original frontend never rendered the
* background image at all (it only ever showed in the editor canvas).
* That silent gap is fixed here rather than preserved.
*/
function adaire_header_get_style_vars( $attributes ) {
$bg_type = adaire_header_get_effective_background_type( $attributes );
if ( ! empty( $attributes['transparentHeader'] ) ) {
$background = 'transparent';
} elseif ( 'image' === $bg_type && ! empty( $attributes['bgImageUrl'] ) ) {
// Background-color CSS var stays empty so a partially-transparent
// image doesn't get an opaque color layer painted behind it.
$background = 'transparent';
} elseif ( 'gradient' === $bg_type ) {
$background = $attributes['gradientBackground'];
} else {
$background = $attributes['backgroundColor'];
}
$topbar_justify_map = array(
'space-between' => 'space-between',
'left' => 'flex-start',
'center' => 'center',
'right' => 'flex-end',
);
$topbar_justify = isset( $topbar_justify_map[ $attributes['topBarLayout'] ] )
? $topbar_justify_map[ $attributes['topBarLayout'] ]
: 'space-between';
$styles = array(
'--adaire-header-font-family' => ! empty( $attributes['fontFamily'] ) ? $attributes['fontFamily'] : 'inherit',
'--adaire-header-background' => $background,
'--adaire-header-text-color' => $attributes['textColor'],
'--adaire-header-hover-color' => $attributes['hoverColor'],
'--adaire-header-border-color' => $attributes['borderColor'],
'--adaire-header-border-width' => ! empty( $attributes['borderBottom'] ) ? $attributes['borderThickness'] . 'px' : '0px',
'--adaire-header-padding-top' => $attributes['paddingTop'] . 'px',
'--adaire-header-padding-bottom' => $attributes['paddingBottom'] . 'px',
'--adaire-header-max-width' => ( 'contained' === $attributes['maxWidthMode'] ) ? $attributes['maxWidth'] . 'px' : '100%',
'--adaire-header-nav-gap' => $attributes['navSpacing'] . 'px',
'--adaire-header-nav-font-size' => $attributes['navFontSize'] . 'px',
'--adaire-header-nav-font-weight' => $attributes['navFontWeight'],
'--adaire-header-letter-spacing' => $attributes['letterSpacing'] . 'px',
'--adaire-header-text-transform' => $attributes['textTransform'],
'--adaire-header-logo-width' => $attributes['logoWidth'] . 'px',
'--adaire-header-mobile-logo-width' => $attributes['mobileLogoWidth'] . 'px',
'--adaire-header-topbar-bg' => $attributes['topBarBackgroundColor'],
'--adaire-header-topbar-color' => $attributes['topBarTextColor'],
'--adaire-header-topbar-font-size' => ( ! empty( $attributes['topBarFontSize'] ) ? $attributes['topBarFontSize'] : 13 ) . 'px',
'--adaire-header-topbar-justify' => $topbar_justify,
'--adaire-header-topbar-gap' => ( 'space-between' === $attributes['topBarLayout'] ) ? '24px' : '12px',
'--adaire-header-social-size' => $attributes['socialIconSize'] . 'px',
'--adaire-header-social-color' => $attributes['socialIconColor'],
'--adaire-header-cart-size' => ( ! empty( $attributes['cartIconSize'] ) ? $attributes['cartIconSize'] : 18 ) . 'px',
'--adaire-header-payment-size' => ( ! empty( $attributes['paymentIconSize'] ) ? $attributes['paymentIconSize'] : 22 ) . 'px',
'--adaire-header-nav-icon-color' => $attributes['navIconColor'],
'--adaire-header-z-index' => $attributes['zIndex'],
'--adaire-header-action-radius' => ( isset( $attributes['buttonBorderRadius'] ) && (int) $attributes['buttonBorderRadius'] >= 0 )
? (int) $attributes['buttonBorderRadius'] . 'px'
: adaire_header_get_action_radius( $attributes['buttonShape'] ),
'--adaire-header-hamburger-border' => ! empty( $attributes['hamburgerBorder'] ) ? ( '1px solid ' . $attributes['hamburgerBorderColor'] ) : 'none',
'--adaire-header-hamburger-border-radius' => $attributes['hamburgerBorderRadius'] . 'px',
'--adaire-header-hamburger-size' => ( ! empty( $attributes['hamburgerSize'] ) ? (int) $attributes['hamburgerSize'] : 42 ) . 'px',
'--adaire-header-hamburger-order' => ( isset( $attributes['hamburgerPosition'] ) && 'right' === $attributes['hamburgerPosition'] ) ? '1' : '0',
'--adaire-header-search-icon-size' => ( ! empty( $attributes['searchIconSize'] ) ? $attributes['searchIconSize'] : 18 ) . 'px',
'--adaire-header-search-btn-size' => ( ! empty( $attributes['searchButtonSize'] ) ? $attributes['searchButtonSize'] : 38 ) . 'px',
);
if ( ! empty( $attributes['searchIconColor'] ) ) {
$styles['--adaire-header-search-icon-color'] = $attributes['searchIconColor'];
}
if ( ! empty( $attributes['searchIconBgColor'] ) ) {
$styles['--adaire-header-search-btn-bg'] = $attributes['searchIconBgColor'];
}
if ( ! empty( $attributes['searchInputBgColor'] ) ) {
$styles['--adaire-header-search-input-bg'] = $attributes['searchInputBgColor'];
}
if ( ! empty( $attributes['searchInputBorderColor'] ) ) {
$styles['--adaire-header-search-input-border'] = $attributes['searchInputBorderColor'];
}
if ( ! empty( $attributes['searchInputTextColor'] ) ) {
$styles['--adaire-header-search-input-text'] = $attributes['searchInputTextColor'];
}
if ( ! empty( $attributes['searchPlaceholderColor'] ) ) {
$styles['--adaire-header-search-placeholder-color'] = $attributes['searchPlaceholderColor'];
}
if ( ! empty( $attributes['searchContainerBgColor'] ) ) {
$styles['--adaire-header-search-container-bg'] = $attributes['searchContainerBgColor'];
}
if ( ! empty( $attributes['cartIconColor'] ) ) {
$styles['--adaire-header-cart-color'] = $attributes['cartIconColor'];
}
if ( ! empty( $attributes['paymentIconColor'] ) ) {
$styles['--adaire-header-payment-color'] = $attributes['paymentIconColor'];
}
if ( ! empty( $attributes['navShowDots'] ) ) {
$styles['--adaire-header-dot-size'] = ( ! empty( $attributes['navDotSize'] ) ? $attributes['navDotSize'] : 6 ) . 'px';
$styles['--adaire-header-dot-spacing'] = ( isset( $attributes['navDotSpacing'] ) ? $attributes['navDotSpacing'] : 8 ) . 'px';
if ( ! empty( $attributes['navDotColor'] ) ) {
$styles['--adaire-header-dot-color'] = $attributes['navDotColor'];
}
}
if ( ! empty( $attributes['ctaHoverBgColor'] ) ) {
$styles['--adaire-header-cta-hover-bg'] = $attributes['ctaHoverBgColor'];
}
if ( ! empty( $attributes['ctaHoverTextColor'] ) ) {
$styles['--adaire-header-cta-hover-text'] = $attributes['ctaHoverTextColor'];
}
if ( isset( $attributes['buttonPaddingVertical'] ) && (int) $attributes['buttonPaddingVertical'] >= 0 ) {
$styles['--adaire-header-action-padding-y'] = (int) $attributes['buttonPaddingVertical'] . 'px';
}
if ( isset( $attributes['ctaBorderRadius'] ) && (int) $attributes['ctaBorderRadius'] >= 0 ) {
$styles['--adaire-header-cta-radius'] = (int) $attributes['ctaBorderRadius'] . 'px';
}
if ( isset( $attributes['ctaPaddingVertical'] ) && (int) $attributes['ctaPaddingVertical'] >= 0 ) {
$styles['--adaire-header-cta-padding-y'] = (int) $attributes['ctaPaddingVertical'] . 'px';
}
if ( isset( $attributes['ctaPaddingHorizontal'] ) && (int) $attributes['ctaPaddingHorizontal'] >= 0 ) {
$styles['--adaire-header-cta-padding-x'] = (int) $attributes['ctaPaddingHorizontal'] . 'px';
}
if ( ! empty( $attributes['signInBgColor'] ) ) {
$styles['--adaire-header-signin-bg'] = $attributes['signInBgColor'];
}
if ( ! empty( $attributes['signInTextColor'] ) ) {
$styles['--adaire-header-signin-text'] = $attributes['signInTextColor'];
}
if ( ! empty( $attributes['signInBorderColor'] ) ) {
$styles['--adaire-header-signin-border'] = $attributes['signInBorderColor'];
}
if ( ! empty( $attributes['signInFontSize'] ) ) {
$styles['--adaire-header-signin-font-size'] = intval( $attributes['signInFontSize'] ) . 'px';
}
if ( ! empty( $attributes['signUpBgColor'] ) ) {
$styles['--adaire-header-signup-bg'] = $attributes['signUpBgColor'];
}
if ( ! empty( $attributes['signUpTextColor'] ) ) {
$styles['--adaire-header-signup-text'] = $attributes['signUpTextColor'];
}
if ( ! empty( $attributes['signUpBorderColor'] ) ) {
$styles['--adaire-header-signup-border'] = $attributes['signUpBorderColor'];
}
if ( ! empty( $attributes['signUpFontSize'] ) ) {
$styles['--adaire-header-signup-font-size'] = intval( $attributes['signUpFontSize'] ) . 'px';
}
if ( ! empty( $attributes['ctaBgColor'] ) ) {
$styles['--adaire-header-cta-bg'] = $attributes['ctaBgColor'];
}
if ( ! empty( $attributes['ctaTextColor'] ) ) {
$styles['--adaire-header-cta-text'] = $attributes['ctaTextColor'];
}
if ( ! empty( $attributes['ctaBorderColor'] ) ) {
$styles['--adaire-header-cta-border'] = $attributes['ctaBorderColor'];
}
if ( ! empty( $attributes['ctaFontSize'] ) ) {
$styles['--adaire-header-cta-font-size'] = intval( $attributes['ctaFontSize'] ) . 'px';
}
if ( 'image' === $bg_type && empty( $attributes['transparentHeader'] ) && ! empty( $attributes['bgImageUrl'] ) ) {
$styles['--adaire-header-bg-image'] = 'url(' . esc_url( $attributes['bgImageUrl'] ) . ')';
$styles['--adaire-header-bg-size'] = ! empty( $attributes['bgSize'] ) ? $attributes['bgSize'] : 'cover';
$styles['--adaire-header-bg-position'] = ! empty( $attributes['bgPosition'] ) ? $attributes['bgPosition'] : 'center center';
$styles['--adaire-header-bg-repeat'] = ! empty( $attributes['bgRepeat'] ) ? $attributes['bgRepeat'] : 'no-repeat';
$styles['--adaire-header-bg-attachment'] = ! empty( $attributes['bgAttachment'] ) ? $attributes['bgAttachment'] : 'scroll';
}
$margin_css = adaire_header_box_to_css( isset( $attributes['gutenblocksMargin'] ) ? $attributes['gutenblocksMargin'] : null );
$padding_css = adaire_header_box_to_css( isset( $attributes['gutenblocksPadding'] ) ? $attributes['gutenblocksPadding'] : null );
if ( $margin_css ) {
$styles['margin'] = $margin_css;
}
if ( $padding_css ) {
$styles['padding'] = $padding_css;
}
return $styles;
}
}
if ( ! function_exists( 'adaire_header_style_vars_to_string' ) ) {
function adaire_header_style_vars_to_string( $style_vars ) {
$pairs = array();
foreach ( $style_vars as $prop => $value ) {
if ( '' === $value || null === $value ) {
continue;
}
$pairs[] = $prop . ':' . $value;
}
return implode( ';', $pairs ) . ( $pairs ? ';' : '' );
}
}
if ( ! function_exists( 'adaire_header_icon_svg' ) ) {
/**
* PHP port of icon-utils.js HeaderIcon. Markup is static/trusted (no
* user data interpolated), so it is safe to output directly.
*/
function adaire_header_icon_svg( $name ) {
if ( empty( $name ) || 'none' === $name ) {
return '';
}
$c = 'stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
$paths = array(
'arrow-right' => ' ',
'user' => ' ',
'user-plus' => ' ',
'login' => ' ',
'home' => ' ',
'info' => ' ',
'grid' => ' ',
'mail' => ' ',
'search' => ' ',
);
$path = isset( $paths[ $name ] ) ? $paths[ $name ] : $paths['arrow-right'];
return '';
}
}
if ( ! function_exists( 'adaire_header_social_icon_svg' ) ) {
/**
* PHP port of icon-utils.js's socialIconPaths/SocialIcon — same path data,
* mirrored byte-for-byte. Falls back to the original single-letter
* placeholder for any platform name that isn't one of the six known ones
* (e.g. a custom platform typed into the "Other" option).
*/
function adaire_header_social_icon_svg( $platform ) {
$key = strtolower( (string) $platform );
$paths = array(
'facebook' => ' ',
'instagram' => ' ',
'x' => ' ',
'youtube' => ' ',
'linkedin' => ' ',
'tiktok' => ' ',
);
if ( empty( $paths[ $key ] ) ) {
$initial = '' !== $platform ? mb_substr( $platform, 0, 1 ) : '?';
return '';
}
return '';
}
}
if ( ! function_exists( 'adaire_header_cart_icon_svg' ) ) {
/**
* PHP port of icon-utils.js CartIcon() — same path data, mirrored
* byte-for-byte (ADAB-016).
*/
function adaire_header_cart_icon_svg() {
$c = 'stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"';
return '';
}
}
if ( ! function_exists( 'adaire_header_payment_icon_svg' ) ) {
/**
* PHP port of icon-utils.js's paymentIconPaths/PaymentIcon — same shapes,
* mirrored byte-for-byte (ADAB-016). Falls back to a single-letter
* placeholder for any method name that isn't one of the known ones.
*/
function adaire_header_payment_icon_svg( $method ) {
$key = strtolower( (string) $method );
$paths = array(
'visa' => 'VISA ',
'mastercard' => ' ',
'paypal' => ' ',
'american express' => 'AMEX ',
'apple pay' => 'Pay ',
'google pay' => 'GPay ',
);
if ( empty( $paths[ $key ] ) ) {
$initial = '' !== $method ? mb_substr( $method, 0, 1 ) : '?';
return '';
}
return '';
}
}
if ( ! function_exists( 'adaire_header_render_cart' ) ) {
/**
* WooCommerce cart icon (ADAB-016). Guarded behind class_exists(
* 'WooCommerce' ) so sites without WooCommerce never get a broken/fatal
* link — they get a non-functional placeholder icon instead (same
* visual slot, so layout doesn't jump if WooCommerce is later
* installed), with no count badge and no link.
*/
function adaire_header_render_cart( $attributes ) {
if ( empty( $attributes['showCartIcon'] ) ) {
return '';
}
$show_count = ! isset( $attributes['cartShowCount'] ) || $attributes['cartShowCount'];
$icon_html = adaire_header_cart_icon_svg();
if ( class_exists( 'WooCommerce' ) && function_exists( 'wc_get_cart_url' ) ) {
$count = function_exists( 'WC' ) && WC()->cart ? WC()->cart->get_cart_contents_count() : 0;
$badge = ( $show_count ) ? '' : '';
return '';
}
// WooCommerce not active — render a non-functional placeholder so the
// toggle never fatals or links somewhere broken. No count badge since
// there's no real cart to count.
return '';
}
}
if ( ! function_exists( 'adaire_header_render_payment_icons' ) ) {
/**
* Payment method trust badges (ADAB-016). Mirrors
* adaire_header_render_socials()'s structure but for the paymentIcons
* array (method name only, no per-icon URL/color — these are static
* badges, not links).
*/
function adaire_header_render_payment_icons( $attributes ) {
if ( empty( $attributes['showPaymentIcons'] ) ) {
return '';
}
$icons = ( isset( $attributes['paymentIcons'] ) && is_array( $attributes['paymentIcons'] ) ) ? $attributes['paymentIcons'] : array();
$out = '
';
return $out;
}
}
if ( ! function_exists( 'adaire_header_render_nav_dot' ) ) {
/**
* Optional menu-indicator dot. Disabled unless navShowDots is explicitly
* turned on — size/spacing/color travel via CSS vars set in
* adaire_header_get_style_vars(); position (before/after the label)
* is expressed as a class so style.scss can apply the right margin side.
*/
function adaire_header_render_nav_dot( $attributes ) {
if ( empty( $attributes['navShowDots'] ) ) {
return '';
}
$position = ( isset( $attributes['navDotPosition'] ) && 'before' === $attributes['navDotPosition'] ) ? 'before' : 'after';
return '';
}
}
if ( ! function_exists( 'adaire_header_render_logo' ) ) {
/**
* Mirrors save.js Logo().
*/
function adaire_header_render_logo( $attributes ) {
if ( 'image' === $attributes['logoType'] && ! empty( $attributes['logoImageUrl'] ) ) {
$alt = ! empty( $attributes['logoImageAlt'] ) ? $attributes['logoImageAlt'] : $attributes['logoText'];
$content = ' ';
} else {
$content = '';
}
$inner = ! empty( $attributes['linkLogoHome'] )
? ( '' )
: $content;
$tagline = '';
if ( ! empty( $attributes['showTagline'] ) ) {
$tagline = '';
}
return '';
}
}
if ( ! function_exists( 'adaire_header_register_nav_menu_locations' ) ) {
/**
* Plugin-owned nav menu location slugs used to resolve the "Primary
* Menu" / "Footer Menu" Navigation Source options. The locations
* themselves are registered on 'init' from the plugin bootstrap files
* (not here — render.php only runs when the block actually renders,
* which is too late for the locations to show up on the admin
* Appearance > Menus screen).
*/
function adaire_header_register_nav_menu_locations() {
return array(
'primary' => 'adaire-blocks-primary',
'footer' => 'adaire-blocks-footer',
);
}
}
if ( ! function_exists( 'adaire_header_resolve_menu_object' ) ) {
/**
* Resolves a WP_Term menu object for navigationSource "primary",
* "footer", or "menu". Returns null if nothing is assigned/selected yet
* so callers can gracefully fall back to the legacy navItems.
*/
function adaire_header_resolve_menu_object( $attributes ) {
$source = isset( $attributes['navigationSource'] ) ? $attributes['navigationSource'] : 'legacy';
if ( 'menu' === $source ) {
$menu_id = ! empty( $attributes['selectedMenuId'] ) ? (int) $attributes['selectedMenuId'] : 0;
if ( ! $menu_id ) {
return null;
}
$menu = wp_get_nav_menu_object( $menu_id );
return $menu ? $menu : null;
}
if ( 'primary' === $source || 'footer' === $source ) {
$locations_map = adaire_header_register_nav_menu_locations();
$location_slug = $locations_map[ $source ];
$locations = get_nav_menu_locations();
if ( empty( $locations[ $location_slug ] ) ) {
return null;
}
$menu = wp_get_nav_menu_object( $locations[ $location_slug ] );
return $menu ? $menu : null;
}
return null;
}
}
if ( ! function_exists( 'adaire_header_label_from_url' ) ) {
/**
* Derives a human-readable label from a menu item's URL, used when WP
* has nothing usable for the title (see adaire_header_friendly_menu_label()).
*/
function adaire_header_label_from_url( $url ) {
$path = trim( (string) wp_parse_url( (string) $url, PHP_URL_PATH ), '/' );
if ( '' === $path ) {
return __( 'Menu item', 'header-block' );
}
$segments = explode( '/', $path );
$slug = end( $segments );
$slug = str_replace( array( '-', '_' ), ' ', $slug );
$slug = trim( $slug );
return '' !== $slug ? ucwords( $slug ) : __( 'Menu item', 'header-block' );
}
}
if ( ! function_exists( 'adaire_header_friendly_menu_label' ) ) {
/**
* wp_get_nav_menu_items()/wp_setup_nav_menu_item() falls back to a raw
* "#123 (no title)" string when a menu item has no custom label AND its
* linked object has no title (deleted/trashed/genuinely-untitled target).
* That debug-style string (with a raw DB post ID) should never reach a
* site visitor or the editor preview, so swap it for a label derived
* from the item's URL instead. A real custom label or resolved object
* title always takes priority and passes through unchanged.
*/
function adaire_header_friendly_menu_label( $title, $url ) {
$title = trim( (string) $title );
if ( '' !== $title && ! preg_match( '/^#\d+\s*\(no title\)$/i', $title ) ) {
return $title;
}
return adaire_header_label_from_url( $url );
}
}
if ( ! function_exists( 'adaire_header_build_menu_tree' ) ) {
/**
* Assembles a flat wp_get_nav_menu_items() result into a nested tree via
* menu_item_parent, rather than using wp_nav_menu()'s default walker —
* this keeps full control over markup/classes/ARIA wiring.
*/
function adaire_header_build_menu_tree( $menu_items ) {
$by_parent = array();
foreach ( $menu_items as $item ) {
$parent = (int) $item->menu_item_parent;
if ( ! isset( $by_parent[ $parent ] ) ) {
$by_parent[ $parent ] = array();
}
$by_parent[ $parent ][] = $item;
}
$build = function ( $parent_id ) use ( &$build, $by_parent ) {
if ( empty( $by_parent[ $parent_id ] ) ) {
return array();
}
$nodes = array();
foreach ( $by_parent[ $parent_id ] as $item ) {
$nodes[] = array(
'id' => (int) $item->ID,
'label' => adaire_header_friendly_menu_label( $item->title, $item->url ),
'url' => $item->url,
'children' => $build( (int) $item->ID ),
);
}
return $nodes;
};
return $build( 0 );
}
}
if ( ! function_exists( 'adaire_header_resolve_nav' ) ) {
/**
* Single entry point used by the nav renderer: decides between the
* legacy flat navItems attribute and a live WordPress menu.
*
* IMPORTANT: once a dynamic source ("primary"/"footer"/"menu") is
* explicitly selected, this never falls back to the legacy placeholder
* items, even if nothing is assigned/resolved yet. An earlier version
* fell back to the legacy navItems in that case, which meant a stale or
* unrelated placeholder menu (e.g. carried over from another
* environment) could silently render instead of the real selected menu.
* Editor preview (see useResolvedMenuTree()/renderNav() in edit.js)
* already shows an empty/"no menu assigned" state rather than the
* placeholder, so this keeps the frontend consistent with the editor.
*
* @return array{items: array, dynamic: bool}
*/
function adaire_header_resolve_nav( $attributes ) {
$source = isset( $attributes['navigationSource'] ) ? $attributes['navigationSource'] : 'legacy';
$legacy_items = ( isset( $attributes['navItems'] ) && is_array( $attributes['navItems'] ) ) ? $attributes['navItems'] : array();
if ( 'legacy' === $source || empty( $source ) ) {
return array(
'items' => $legacy_items,
'dynamic' => false,
);
}
$menu = adaire_header_resolve_menu_object( $attributes );
if ( ! $menu ) {
return array(
'items' => array(),
'dynamic' => true,
);
}
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
if ( ! $menu_items ) {
return array(
'items' => array(),
'dynamic' => true,
);
}
return array(
'items' => adaire_header_build_menu_tree( $menu_items ),
'dynamic' => true,
);
}
}
if ( ! function_exists( 'adaire_header_render_menu_node' ) ) {
/**
* Renders one nested WP-menu node (and recursively its children) as an
* accessible disclosure: a real, always-navigable for the item
* itself, plus — only when it has children — a separate
* aria-expanded/aria-haspopup/aria-controls that reveals the
* submenu. Supports unlimited depth via recursion.
*/
function adaire_header_render_menu_node( $item, $depth, $attributes = array() ) {
$label = isset( $item['label'] ) ? $item['label'] : '';
$url = ! empty( $item['url'] ) ? $item['url'] : '#';
$children = ( isset( $item['children'] ) && is_array( $item['children'] ) ) ? $item['children'] : array();
$has_kids = ! empty( $children );
$dot_position = ( isset( $attributes['navDotPosition'] ) && 'before' === $attributes['navDotPosition'] ) ? 'before' : 'after';
$dot = adaire_header_render_nav_dot( $attributes );
$label_html = '' . esc_html( $label ) . ' ';
$label_inner = ( 'before' === $dot_position ) ? ( $dot . $label_html ) : ( $label_html . $dot );
$out = '';
return $out;
}
$submenu_id = 'adaire-submenu-' . ( ! empty( $item['id'] ) ? (int) $item['id'] : wp_unique_id( 'adaire-submenu-' ) );
$out .= '';
$out .= '';
$out .= '';
return $out;
}
}
if ( ! function_exists( 'adaire_header_render_menu_tree' ) ) {
function adaire_header_render_menu_tree( $items, $attributes = array() ) {
if ( empty( $items ) ) {
return '';
}
$out = '';
return $out;
}
}
if ( ! function_exists( 'adaire_header_render_nav' ) ) {
/**
* Mirrors save.js Nav(), with an additional branch for WP-menu-sourced
* nested trees. $items, when passed explicitly, lets the split layout
* hand in a left/right half of either a flat legacy list or a
* top-level tree-node list — both are plain numeric arrays so slicing
* behaves identically either way.
*/
function adaire_header_render_nav( $attributes, $resolved, $items = null, $nav_id = '' ) {
if ( empty( $attributes['showNav'] ) || 'minimal' === $attributes['layout'] ) {
return '';
}
$items = ( null === $items ) ? $resolved['items'] : $items;
if ( $resolved['dynamic'] ) {
$inner = adaire_header_render_menu_tree( $items, $attributes );
} else {
$show_nav_icons = ! isset( $attributes['showNavIcons'] ) || $attributes['showNavIcons'];
$dot_position = ( isset( $attributes['navDotPosition'] ) && 'before' === $attributes['navDotPosition'] ) ? 'before' : 'after';
$inner = '';
foreach ( $items as $item ) {
$label = isset( $item['label'] ) ? $item['label'] : '';
$url = ! empty( $item['url'] ) ? $item['url'] : '#';
$icon = isset( $item['icon'] ) ? $item['icon'] : '';
$icon_html = $show_nav_icons ? adaire_header_icon_svg( $icon ) : '';
$label_html = '' . esc_html( $label ) . ' ';
$dot = adaire_header_render_nav_dot( $attributes );
$content = ( 'before' === $dot_position ) ? ( $dot . $icon_html . $label_html ) : ( $icon_html . $label_html . $dot );
$inner .= '';
}
}
$id_attr = $nav_id ? ( ' id="' . esc_attr( $nav_id ) . '"' ) : '';
$close_btn = '';
if ( $nav_id && in_array( $attributes['mobileMenuStyle'] ?? 'dropdown', array( 'slide-in', 'overlay' ), true ) ) {
$close_icon = '';
$close_btn = '';
}
// Mobile-only CTA — reuses the existing "Get started" CTA settings
// (showCta/ctaText/ctaUrl/ctaStyle/etc.), which otherwise only ever
// render in .adaire-header-actions, a container hidden entirely on
// mobile (see the `.adaire-header-action, .adaire-header-socials {
// display: none }` rule in style.scss). Without this, the CTA had no
// way to reach a mobile visitor at all. Gated on $nav_id (same as
// $close_btn above) so the split layout's second nav half — called
// with $nav_id === '' — doesn't render a duplicate. Shown for every
// mobileMenuStyle (dropdown/slide-in/overlay), not just slide-in/
// overlay like the close button, since dropdown mode benefits from
// it too.
$mobile_cta = '';
if ( $nav_id && ! empty( $attributes['showCta'] ) ) {
$show_icon_cta_mobile = ! isset( $attributes['showCtaIcon'] ) || $attributes['showCtaIcon'];
$cta_html = adaire_header_render_action( $attributes['showCta'], $attributes['ctaText'], $attributes['ctaUrl'], $attributes['ctaNewTab'], $attributes['ctaStyle'], $attributes['ctaIcon'], __( 'Get started', 'header-block' ), $attributes['ctaIconPosition'], 'cta', $show_icon_cta_mobile );
$mobile_cta = '';
}
return '';
}
}
if ( ! function_exists( 'adaire_header_render_search' ) ) {
/**
* Mirrors save.js Search(). The form action is intentionally left as
* the literal "/" (matching current behaviour exactly) rather than
* home_url( '/' ) — fixing that is out of scope for this refactor.
*/
function adaire_header_render_search( $attributes ) {
if ( empty( $attributes['showSearch'] ) ) {
return '';
}
$mode = isset( $attributes['searchMode'] ) ? $attributes['searchMode'] : 'expand';
$placeholder = isset( $attributes['searchPlaceholder'] ) ? $attributes['searchPlaceholder'] : '';
$layout = isset( $attributes['searchLayoutStyle'] ) ? $attributes['searchLayoutStyle'] : 'icon-only';
$out = '';
return $out;
}
}
if ( ! function_exists( 'adaire_header_render_socials' ) ) {
/**
* Mirrors save.js Socials().
*/
function adaire_header_render_socials( $attributes ) {
if ( empty( $attributes['showSocial'] ) ) {
return '';
}
$links = ( isset( $attributes['socialLinks'] ) && is_array( $attributes['socialLinks'] ) ) ? $attributes['socialLinks'] : array();
$hover_effect = isset( $attributes['socialHoverEffect'] ) ? $attributes['socialHoverEffect'] : 'color';
$out = '';
return $out;
}
}
if ( ! function_exists( 'adaire_header_render_follow_us' ) ) {
/**
* Top bar "Follow Us" content (requirement #8) — a flexible slot, not a
* fixed template: text is fully editable, the wrapper and the icon
* are both independently optional, and the whole thing renders nothing
* unless topBarFollowEnabled is explicitly turned on. The legacy static
* "Follow us" that already lives in topBarRight is untouched and
* keeps rendering exactly as before when this stays off.
*/
function adaire_header_render_follow_us( $attributes ) {
if ( empty( $attributes['topBarFollowEnabled'] ) ) {
return '';
}
$text = isset( $attributes['topBarFollowText'] ) ? $attributes['topBarFollowText'] : '';
$icon = isset( $attributes['topBarFollowIcon'] ) ? $attributes['topBarFollowIcon'] : 'none';
$icon_position = ( isset( $attributes['topBarFollowIconPosition'] ) && 'right' === $attributes['topBarFollowIconPosition'] ) ? 'right' : 'left';
$url = isset( $attributes['topBarFollowUrl'] ) ? trim( $attributes['topBarFollowUrl'] ) : '';
$icon_html = ( 'none' !== $icon ) ? adaire_header_icon_svg( $icon ) : '';
$text_html = ( '' !== $text ) ? '' . wp_kses_post( $text ) . ' ' : '';
$inner = ( 'right' === $icon_position ) ? ( $text_html . $icon_html ) : ( $icon_html . $text_html );
if ( '' === $inner ) {
return '';
}
$classes = 'adaire-header-follow-us icon-' . $icon_position;
if ( '' !== $url ) {
$target_attr = ! empty( $attributes['topBarFollowNewTab'] ) ? ' target="_blank" rel="noopener noreferrer"' : '';
return '' . $inner . ' ';
}
return '' . $inner . ' ';
}
}
if ( ! function_exists( 'adaire_header_suppress_redundant_follow_text' ) ) {
/**
* The dedicated Follow Us widget (topBarFollowEnabled) and the plain
* topBarLeft/topBarRight text fields used to default to the exact same
* literal "Follow us" string, so a header using both defaults showed it
* twice. Once the dedicated widget is on, strip a topbar text value that
* is literally just that legacy default so only the dedicated widget's
* output remains; any text the site owner actually customized is left
* untouched.
*/
function adaire_header_suppress_redundant_follow_text( $text, $follow_enabled ) {
if ( empty( $follow_enabled ) ) {
return $text;
}
$plain = trim( wp_strip_all_tags( (string) $text ) );
if ( '' !== $plain && 0 === strcasecmp( $plain, 'follow us' ) ) {
return '';
}
return $text;
}
}
if ( ! function_exists( 'adaire_header_autolink_contact' ) ) {
/**
* Auto-converts phone numbers to tel: links and email addresses to
* mailto: links inside top-bar text (requirement: "phone numbers should
* open a phone function when clicked"). Skips entirely if the string
* already contains a manual link/markup-heavy content, so a site owner
* who already added their own tag never gets double-wrapped.
*/
function adaire_header_autolink_contact( $html ) {
if ( '' === $html || false !== stripos( $html, ' ' . esc_html( $m[0] ) . ' ';
},
$html
);
$html = preg_replace_callback(
'/\+?\d[\d\s().-]{6,}\d/',
function ( $m ) {
if ( false !== stripos( $m[0], '<' ) ) {
return $m[0]; // Inside markup already inserted above (e.g. a mailto href); leave alone.
}
$raw = $m[0];
$digits = preg_replace( '/[^\d+]/', '', $raw );
return '' . esc_html( $raw ) . ' ';
},
$html
);
return $html;
}
}
if ( ! function_exists( 'adaire_header_render_action' ) ) {
/**
* Mirrors save.js HeaderAction().
*/
function adaire_header_render_action( $show, $text, $url, $new_tab, $style, $icon, $label, $icon_position = 'left', $button_type = '', $show_icon = true ) {
if ( empty( $show ) ) {
return '';
}
$type_class = $button_type ? ( ' adaire-header-action--' . $button_type ) : '';
$icon_pos = ( 'right' === $icon_position ) ? 'right' : 'left';
$attrs = ' class="adaire-header-action' . esc_attr( $type_class ) . ' is-' . esc_attr( $style ) . ' icon-' . $icon_pos . '"';
$attrs .= ' href="' . esc_url( $url ? $url : '#' ) . '"';
if ( $new_tab ) {
$attrs .= ' target="_blank" rel="noopener noreferrer"';
}
$attrs .= ' aria-label="' . esc_attr( $label ? $label : $text ) . '"';
$icon_html = $show_icon ? adaire_header_icon_svg( $icon ) : '';
$text_html = '' . esc_html( $text ) . ' ';
$inner = ( 'right' === $icon_pos ) ? ( $text_html . $icon_html ) : ( $icon_html . $text_html );
return '' . $inner . ' ';
}
}
if ( ! function_exists( 'adaire_header_render_mobile_toggle' ) ) {
/**
* Mirrors save.js's hardcoded 3- hamburger button exactly when
* hamburgerIconStyle is "bars" (the default) so existing pages keep
* the same class attribute. Non-default icon styles add an extra class
* for style.scss to target — they never change the DOM shape, only CSS.
*/
function adaire_header_render_mobile_toggle( $attributes, $nav_id = '' ) {
$icon_style = isset( $attributes['hamburgerIconStyle'] ) ? $attributes['hamburgerIconStyle'] : 'bars';
$icon_style_class = ( 'bars' !== $icon_style ) ? ( ' icon-style-' . $icon_style ) : '';
$controls_attr = $nav_id ? ( ' aria-controls="' . esc_attr( $nav_id ) . '"' ) : '';
return '';
}
}
// ---------------------------------------------------------------------
// Render.
// ---------------------------------------------------------------------
$style_string = adaire_header_style_vars_to_string( adaire_header_get_style_vars( $attributes ) );
$box_shadow_class = ! empty( $attributes['boxShadow'] ) ? ' has-shadow' : '';
$slide_class = '';
if ( 'slide-in' === $attributes['mobileMenuStyle'] && isset( $attributes['mobileSlideDirection'] ) && 'left' === $attributes['mobileSlideDirection'] ) {
$slide_class = ' mobile-slide-left';
}
$classes = trim( 'adaire-header-block is-' . $attributes['stickyBehavior'] . ' mobile-' . $attributes['mobileMenuStyle'] . $slide_class . $box_shadow_class );
$resolved = adaire_header_resolve_nav( $attributes );
$nav_dom_id = wp_unique_id( 'adaire-header-nav-' );
$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $classes,
'style' => $style_string,
'data-sticky-behavior' => $attributes['stickyBehavior'],
'data-mobile-menu-style' => $attributes['mobileMenuStyle'],
'data-mobile-breakpoint' => isset( $attributes['mobileBreakpoint'] ) ? (int) $attributes['mobileBreakpoint'] : 782,
'data-mobile-slide-direction' => isset( $attributes['mobileSlideDirection'] ) ? $attributes['mobileSlideDirection'] : 'right',
'data-close-on-outside-click' => ( ! isset( $attributes['mobileCloseOnOutsideClick'] ) || $attributes['mobileCloseOnOutsideClick'] ) ? 'true' : 'false',
'data-close-on-escape' => ( ! isset( $attributes['mobileCloseOnEscape'] ) || $attributes['mobileCloseOnEscape'] ) ? 'true' : 'false',
)
);
// Icon-toggle gates (req #4) — all default to true so untouched blocks keep
// showing icons exactly as before.
$show_icon_signin = ! isset( $attributes['showSignInIcon'] ) || $attributes['showSignInIcon'];
$show_icon_signup = ! isset( $attributes['showSignUpIcon'] ) || $attributes['showSignUpIcon'];
$show_icon_cta = ! isset( $attributes['showCtaIcon'] ) || $attributes['showCtaIcon'];
// Social placement (req #7) — rendered once, then dropped into exactly one
// slot. Falls back to the original 'actions' slot if a topbar-dependent
// placement is chosen but the topbar itself is off, so socials never just
// disappear.
$social_html = adaire_header_render_socials( $attributes );
$social_placement = isset( $attributes['socialPlacement'] ) ? $attributes['socialPlacement'] : 'actions';
if ( in_array( $social_placement, array( 'topbar-left', 'topbar-right' ), true ) && empty( $attributes['showTopBar'] ) ) {
$social_placement = 'actions';
}
// Cart icon / payment icons (ADAB-016) — same four-zone placement system as
// socials above, with the same topbar-dependent fallback to 'actions'.
$cart_html = adaire_header_render_cart( $attributes );
$cart_placement = isset( $attributes['cartIconPlacement'] ) ? $attributes['cartIconPlacement'] : 'actions';
if ( in_array( $cart_placement, array( 'topbar-left', 'topbar-right' ), true ) && empty( $attributes['showTopBar'] ) ) {
$cart_placement = 'actions';
}
$payment_html = adaire_header_render_payment_icons( $attributes );
$payment_placement = isset( $attributes['paymentIconPlacement'] ) ? $attributes['paymentIconPlacement'] : 'actions';
if ( in_array( $payment_placement, array( 'topbar-left', 'topbar-right' ), true ) && empty( $attributes['showTopBar'] ) ) {
$payment_placement = 'actions';
}
// Top bar "Follow Us" (req #8).
$follow_html = adaire_header_render_follow_us( $attributes );
$follow_position = ( isset( $attributes['topBarFollowPosition'] ) && 'left' === $attributes['topBarFollowPosition'] ) ? 'left' : 'right';
// Search placement (req #6) — 'start'/'end' keep rendering inside
// .adaire-header-actions exactly as before; 'center' and 'floating' are new
// slots elsewhere in the markup.
$search_position = isset( $attributes['searchPosition'] ) ? $attributes['searchPosition'] : 'start';
$search_html = adaire_header_render_search( $attributes );
$html = '';
if ( ! empty( $attributes['showTopBar'] ) ) {
$follow_enabled = ! empty( $attributes['topBarFollowEnabled'] );
$topbar_left_text = adaire_header_suppress_redundant_follow_text( $attributes['topBarLeft'], $follow_enabled );
$topbar_right_text = adaire_header_suppress_redundant_follow_text( $attributes['topBarRight'], $follow_enabled );
$topbar_left = '' . adaire_header_autolink_contact( wp_kses_post( $topbar_left_text ) ) . ' ';
$topbar_right = '' . adaire_header_autolink_contact( wp_kses_post( $topbar_right_text ) ) . ' ';
if ( $follow_html ) {
if ( 'left' === $follow_position ) {
$topbar_left .= $follow_html;
} else {
$topbar_right .= $follow_html;
}
}
if ( 'topbar-left' === $social_placement ) {
$topbar_left .= $social_html;
} elseif ( 'topbar-right' === $social_placement ) {
$topbar_right .= $social_html;
}
if ( 'topbar-left' === $payment_placement ) {
$topbar_left .= $payment_html;
} elseif ( 'topbar-right' === $payment_placement ) {
$topbar_right .= $payment_html;
}
if ( 'topbar-left' === $cart_placement ) {
$topbar_left .= $cart_html;
} elseif ( 'topbar-right' === $cart_placement ) {
$topbar_right .= $cart_html;
}
$html .= '';
}
$html .= ''; // .adaire-header-inner
if ( 'floating' === $search_position ) {
$html .= '';
}
$html .= ' ';
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- every dynamic value above is escaped at the point of interpolation.