get_elementor_templates(); ?>

ID, self::META_KEY, true ); if ( $template_id ) { $title .= ''; } } return $title; } /** * Add CSS class to top-level menu items that have a mega menu. * * @param array $classes * @param \WP_Post $item * @param \stdClass $args * @param int $depth * @return array */ public function add_mega_menu_class( $classes, $item, $args, $depth ) { if ( 0 === $depth ) { $template_id = get_post_meta( $item->ID, self::META_KEY, true ); if ( $template_id ) { $classes[] = 'aafe-mega-menu-item'; $classes[] = 'menu-item-has-children'; } } return $classes; } /** * Inject the Elementor-built mega menu panel after the tag. * * @param string $item_output * @param \WP_Post $item * @param int $depth * @param \stdClass $args * @return string */ public function inject_mega_menu_panel( $item_output, $item, $depth, $args ) { if ( 0 !== $depth ) { return $item_output; } $template_id = get_post_meta( $item->ID, self::META_KEY, true ); if ( ! $template_id || ! class_exists( '\Elementor\Plugin' ) ) { return $item_output; } $width = get_post_meta( $item->ID, self::META_WIDTH, true ); $custom_width = get_post_meta( $item->ID, self::META_CUSTOM_W, true ); $align = get_post_meta( $item->ID, self::META_ALIGN, true ); $offset = get_post_meta( $item->ID, self::META_OFFSET, true ); $width = empty( $width ) ? 'full' : $width; $align = empty( $align ) ? 'center' : $align; // AAFE FIX: guard against infinite recursion when a mega menu template itself contains // a menu that points back to a mega menu template, and skip unpublished templates. static $rendering = []; $template_id = absint( $template_id ); if ( isset( $rendering[ $template_id ] ) || 'publish' !== get_post_status( $template_id ) ) { return $item_output; } $rendering[ $template_id ] = true; $content = \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $template_id, true ); unset( $rendering[ $template_id ] ); $panel = sprintf( '', esc_attr__( 'Mega Menu', 'addronix-addons-for-elementor' ), esc_attr( $width ), esc_attr( $custom_width ), esc_attr( $align ), esc_attr( $offset ), $content ); return $item_output . $panel; } /** * Get available Elementor templates (all published pages with Elementor data). * * @return array id => title */ private function get_elementor_templates() { $options = []; // Show Mega Menu type templates from the unified CPT at the top. $mega_posts = \AddronixAddons\AAFE_Template::get_templates_by_type( \AddronixAddons\AAFE_Template::TYPE_MEGA_MENU ); foreach ( $mega_posts as $post ) { $options[ $post->ID ] = '🚀 ' . $post->post_title . ' (#' . $post->ID . ')'; } return $options; } /** * Enqueue admin assets for the nav menu editor. * * @param string $hook */ public function enqueue_admin_assets( $hook ) { if ( 'nav-menus.php' !== $hook ) { return; } // Inline style to make the custom field look clean wp_add_inline_style( 'nav-menus', ' .field-aafe-mega-menu { padding: 10px 0; border-top: 1px solid #eee; margin-top:8px; } .field-aafe-mega-menu label strong { color: #6e42c1; } ' ); } public function admin_footer_js() { $screen = get_current_screen(); if ( ! $screen || 'nav-menus' !== $screen->id ) { return; } // Use wp_add_inline_script instead of raw