is_primary_nav_menu_active()` * * `kadence()->display_primary_nav_menu( array $args = [] )` * * `kadence()->display_fallback_menu( array $args = [] )` * * `kadence()->is_mobile_nav_menu_active( array $args = [] )` * * `kadence()->display_mobile_nav_menu( array $args = [] )` */ class Component implements Component_Interface, Templating_Component_Interface { const PRIMARY_NAV_MENU_SLUG = 'primary'; const MOBILE_NAV_MENU_SLUG = 'mobile'; const SECONDARY_NAV_MENU_SLUG = 'secondary'; const FOOTER_NAV_MENU_SLUG = 'footer'; /** * Gets the unique identifier for the theme component. * * @return string Component slug. */ public function get_slug() : string { return 'nav_menus'; } /** * Adds the action and filter hooks to integrate with WordPress. */ public function initialize() { add_action( 'after_setup_theme', array( $this, 'action_register_nav_menus' ) ); add_filter( 'nav_menu_item_title', array( $this, 'filter_primary_nav_menu_dropdown_symbol' ), 10, 4 ); add_filter( 'walker_nav_menu_start_el', array( $this, 'filter_mobile_nav_menu_dropdown_symbol' ), 10, 4 ); require_once get_template_directory() . '/inc/components/nav_menus/nav-widget-settings.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude.FileIncludeFound } /** * Gets template tags to expose as methods on the Template_Tags class instance, accessible through `kadence()`. * * @return array Associative array of $method_name => $callback_info pairs. Each $callback_info must either be * a callable or an array with key 'callable'. This approach is used to reserve the possibility of * adding support for further arguments in the future. */ public function template_tags() : array { return array( 'is_primary_nav_menu_active' => array( $this, 'is_primary_nav_menu_active' ), 'display_primary_nav_menu' => array( $this, 'display_primary_nav_menu' ), 'is_secondary_nav_menu_active' => array( $this, 'is_secondary_nav_menu_active' ), 'display_secondary_nav_menu' => array( $this, 'display_secondary_nav_menu' ), 'is_footer_nav_menu_active' => array( $this, 'is_footer_nav_menu_active' ), 'display_footer_nav_menu' => array( $this, 'display_footer_nav_menu' ), 'display_fallback_menu' => array( $this, 'display_fallback_menu' ), 'is_mobile_nav_menu_active' => array( $this, 'is_mobile_nav_menu_active' ), 'display_mobile_nav_menu' => array( $this, 'display_mobile_nav_menu' ), ); } /** * Registers the navigation menus. */ public function action_register_nav_menus() { register_nav_menus( array( static::PRIMARY_NAV_MENU_SLUG => esc_html__( 'Primary', 'kadence' ), static::SECONDARY_NAV_MENU_SLUG => esc_html__( 'Secondary', 'kadence' ), static::MOBILE_NAV_MENU_SLUG => esc_html__( 'Mobile', 'kadence' ), static::FOOTER_NAV_MENU_SLUG => esc_html__( 'Footer', 'kadence' ), ) ); } /** * Adds a dropdown symbol to nav menu items with children. * * @param string $title The menu item's title. * @param object $item The current menu item usually a post object. * @param stdClass $args An object of wp_nav_menu arguments. * @param int $depth Depth of menu item. Used for padding. */ public function filter_primary_nav_menu_dropdown_symbol( $title, $item, $args, $depth ) { // // Only for our primary and secondary menu location. // if ( empty( $args->theme_location ) || ( static::PRIMARY_NAV_MENU_SLUG !== $args->theme_location && static::SECONDARY_NAV_MENU_SLUG !== $args->theme_location ) ) { // return $title; // } // // This can still get called because menu location isn't always correct. // if ( ! empty( $args->menu_id ) && 'mobile-menu' === $args->menu_id ) { // return $title; // } if ( ! isset( $args->sub_arrows ) || empty( $args->sub_arrows ) ) { return $title; } // Add the dropdown for items that have children. if ( ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) { $title = '
'; } //aria-label="' . esc_attr__( 'Expand child menu', 'kadence' ) . '" return $title; } /** * Adds a dropdown symbol to nav menu items with children. * * @param string $item_output The menu item's starting HTML output. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param object $args An object of wp_nav_menu. * @return string Modified nav menu HTML. */ public function filter_mobile_nav_menu_dropdown_symbol( $item_output, $item, $depth, $args ) { // Only for our Mobile menu location. if ( ! isset( $args->show_toggles ) || empty( $args->show_toggles ) ) { return $item_output; } // Add the dropdown for items that have children. if ( ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) { if ( kadence()->is_amp() ) { return $item_output; } $menu_id = ( isset( $args->menu_id ) && ! empty( $args->menu_id ) ? '#' . $args->menu_id : '.menu' ); $toggle_target_string = $menu_id . ' .menu-item-' . $item->ID . ' > .sub-menu'; $output = '