%s
', get_block_wrapper_attributes( [ 'class' => 'rooster-mega' ] ), esc_html__( 'The mega menu prints the navigation menu named in its settings; none is published under that slug.', 'ai-eshop-optimizer' ) ) ); } return; } $version = AIEO_Engine_Mega_Menu::version(); $slugs = array_values( array_filter( array_map( 'sanitize_title', explode( ',', (string) ( $attributes['menus'] ?? '' ) ) ) ) ); $families = AIEO_Engine_Mega_Menu::families( $slugs ); $intent = in_array( (string) ( $attributes['intent'] ?? '' ), [ 'hover', 'focus', 'click' ], true ) ? (string) $attributes['intent'] : 'hover'; $label = '' !== trim( (string) ( $attributes['label'] ?? '' ) ) ? trim( (string) $attributes['label'] ) : __( 'Products', 'ai-eshop-optimizer' ); $panel_id = wp_unique_id( 'rooster-mega-panel-' ); $front = is_front_page(); $page_family = ! $front && class_exists( '\Rooster\Core\Design' ) && method_exists( '\Rooster\Core\Design', 'page_accent' ) ? \Rooster\Core\Design::page_accent() : ''; $request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( (string) $_SERVER['REQUEST_URI'] ) ) : ''; $here = trim( (string) wp_parse_url( $request, PHP_URL_PATH ), '/' ); $home_host = (string) wp_parse_url( home_url( '/' ), PHP_URL_HOST ); $entries = []; $pages = []; $items = AIEO_Engine_Mega_Menu::items( $nav ); $subkeys = AIEO_Engine_Mega_Menu::submenu_keys( $nav, $items ); foreach ( $items as $i => $item ) { $text = trim( (string) ( $item['attrs']['label'] ?? '' ) ); $url = (string) ( $item['attrs']['url'] ?? '' ); if ( '' === $text ) { continue; } $accent = sanitize_key( (string) ( $item['attrs']['roosterAccent'] ?? '' ) ); $key = ''; if ( '' !== $accent && isset( $families[ $accent ] ) ) { $key = $families[ $accent ]->post_name; } elseif ( isset( $subkeys[ $i ] ) ) { $key = $subkeys[ $i ]; } $entry = [ 'label' => $text, 'url' => $url, 'key' => $key, 'accent' => $accent ]; if ( 'before' === (string) ( $item['attrs']['roosterSeparator'] ?? '' ) ) { $entry['separator'] = true; $group = trim( (string) ( $item['attrs']['roosterGroup'] ?? '' ) ); if ( '' !== $group ) { $entry['group'] = $group; } } $host = (string) wp_parse_url( $url, PHP_URL_HOST ); $path = trim( (string) wp_parse_url( $url, PHP_URL_PATH ), '/' ); $local = '' === $host || $host === $home_host; if ( ! $front && ( '' !== $page_family ? $accent === $page_family : ( $local && '' !== $path && ( $here === $path || 0 === strpos( $here . '/', $path . '/' ) ) ) ) ) { $entry['current'] = true; } $pages[ count( $entries ) ] = $local && $path === $here; $entries[] = $entry; } if ( ! $entries ) { return; } $context = [ 'version' => $version, 'url' => AIEO_Engine_Mega_Menu::file_url( $version ), 'intent' => $intent, 'entries' => $entries, ]; $mobile = 'mobile' === ( function_exists( 'rooster_device_class' ) ? rooster_device_class() : \Rooster\Core\DeviceClass::current() ); if ( $mobile ) { $finder = class_exists( 'AIEO_DMM_Settings' ) && method_exists( 'AIEO_DMM_Settings', 'is_module_enabled' ) && AIEO_DMM_Settings::is_module_enabled( 'navigator' ) ? __( 'Find the right product', 'ai-eshop-optimizer' ) : ''; $finder = (string) apply_filters( 'rooster/menu/finder', $finder ); $actions = [ 'find' => $finder ]; if ( function_exists( 'wc_get_page_permalink' ) ) { $actions['shop'] = [ 'url' => wc_get_page_permalink( 'shop' ), 'label' => __( 'Shop', 'ai-eshop-optimizer' ) ]; } $actions['account'] = is_user_logged_in() ? [ 'url' => function_exists( 'wc_get_page_permalink' ) ? wc_get_page_permalink( 'myaccount' ) : admin_url( 'profile.php' ), 'label' => __( 'Your account', 'ai-eshop-optimizer' ) ] : [ 'url' => wp_login_url( home_url( '' !== $request ? $request : '/' ) ), 'label' => __( 'Sign in', 'ai-eshop-optimizer' ) ]; $context['actions'] = (array) apply_filters( 'rooster/menu/drawer_actions', $actions ); if ( 'levels' === (string) ( $attributes['drawer'] ?? '' ) ) { $context['drawer'] = 'levels'; $context['strings'] = [ 'back' => __( 'Back', 'ai-eshop-optimizer' ), 'show' => __( 'Show %s', 'ai-eshop-optimizer' ), ]; } } $wrapper = get_block_wrapper_attributes( [ 'class' => 'rooster-mega' . ( $mobile ? ' rooster-mega--phone' : '' ), 'aria-label' => $label, 'data-rooster-ui' => 'rooster-one/mega-menu', 'data-rooster-menu' => (string) $version, 'data-wp-interactive' => 'rooster/mega-menu', 'data-wp-context' => wp_json_encode( $context ), 'data-wp-init' => 'callbacks.init', 'data-wp-on--keydown' => 'actions.key', 'data-wp-on--pointerenter' => 'actions.prefetch', 'data-wp-on--pointerleave' => 'actions.leave', 'data-wp-on--focusout' => 'actions.focusout', ] ); $classes = static function ( array $entry, string $more = '' ): string { return 'rooster-mega__top' . $more . ( '' !== $entry['accent'] ? ' is-style-accent-' . esc_attr( $entry['accent'] ) : '' ) . ( ! empty( $entry['current'] ) ? ' is-current' : '' ) . ( ! empty( $entry['separator'] ) ? ' has-separator' : '' ); }; $current = static function ( int $i ) use ( $pages ): string { return ! empty( $pages[ $i ] ) ? ' aria-current="page"' : ''; }; $name = static function ( array $entry ): string { return '' . esc_html( $entry['label'] ) . ''; }; $plain = static function ( array $entry, int $i ) use ( $classes, $current, $name ): string { return '