ml__( 'Sub Item Vertical Spacing', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 1,
'max' => 30,
],
],
'default' => [
'size' => 5,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-nav-menu .wpr-mobile-sub-menu-item' => 'padding-top: {{SIZE}}{{UNIT}}; padding-bottom: {{SIZE}}{{UNIT}};',
]
]
);
$this->add_responsive_control(
'mobile_menu_offset',
[
'label' => esc_html__( 'Dropdown Offset', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'px' => [
'min' => 1,
'min' => 50,
],
'default' => [
'size' => 10,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-nav-menu' => 'margin-top: {{SIZE}}{{UNIT}};',
],
'separator' => 'before',
]
);
$this->end_controls_section(); // End Controls Section
// Section: Toggle Button ----
$this->start_controls_section(
'section_style_toggle_button',
[
'label' => esc_html__( 'Toggle Button', 'wpr-addons' ),
'tab' => Controls_Manager::TAB_STYLE,
'condition' => [
'mob_menu_display!' => 'none',
],
]
);
$this->start_controls_tabs( 'tabs_toggle_style' );
$this->start_controls_tab(
'tab_toggle_btn_style_normal',
[
'label' => esc_html__( 'Normal', 'wpr-addons' ),
]
);
$this->add_control(
'toggle_btn_color',
[
'label' => esc_html__( 'Color', 'wpr-addons' ),
'type' => Controls_Manager::COLOR,
'default' => '#333333',
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'border-color: {{VALUE}};',
'{{WRAPPER}} .wpr-mobile-toggle-text' => 'color: {{VALUE}};',
'{{WRAPPER}} .wpr-mobile-toggle-line' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'toggle_btn_bg_color',
[
'label' => esc_html__( 'Background Color', 'wpr-addons' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'background-color: {{VALUE}};',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab(
'tab_toggle_btn_style_hover',
[
'label' => esc_html__( 'Hover', 'wpr-addons' ),
]
);
$this->add_control(
'toggle_btn_color_hover',
[
'label' => esc_html__( 'Color', 'wpr-addons' ),
'type' => Controls_Manager::COLOR,
'default' => '#605BE5',
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle:hover' => 'border-color: {{VALUE}};',
'{{WRAPPER}} .wpr-mobile-toggle:hover .wpr-mobile-toggle-text' => 'color: {{VALUE}};',
'{{WRAPPER}} .wpr-mobile-toggle:hover .wpr-mobile-toggle-line' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'toggle_btn_bg_color_hover',
[
'label' => esc_html__( 'Background Color', 'wpr-addons' ),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle:hover' => 'background-color: {{VALUE}};',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_control(
'toggle_btn_lines_height',
[
'label' => esc_html__( 'Lines Height', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 1,
'max' => 10,
],
],
'default' => [
'size' => 4,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle-line' => 'height: {{SIZE}}{{UNIT}};',
],
'separator' => 'before',
'condition' => [
'toggle_btn_style' => ['hamburger', 'pro-tx'],
],
]
);
$this->add_control(
'toggle_btn_line_space',
[
'label' => esc_html__( 'Space Between Lines', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 1,
'max' => 20,
],
],
'default' => [
'size' => 6,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle-line' => 'margin-bottom: {{SIZE}}{{UNIT}};',
],
'condition' => [
'toggle_btn_style' => ['hamburger', 'pro-tx'],
],
]
);
$this->add_control(
'toggle_btn_width',
[
'label' => esc_html__( 'Button Width', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 20,
'max' => 150,
],
],
'default' => [
'size' => 50,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'width: {{SIZE}}{{UNIT}};',
],
'separator' => 'before',
]
);
$this->add_control(
'toggle_btn_padding',
[
'label' => esc_html__( 'Button Padding', 'wpr-addons' ),
'type' => Controls_Manager::DIMENSIONS,
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'toggle_btn_border_width',
[
'label' => esc_html__( 'Button Border Width', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 10,
],
],
'default' => [
'size' => 0,
],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'border-width: {{SIZE}}{{UNIT}};',
]
]
);
$this->add_control(
'toggle_btn_border_radius',
[
'label' => esc_html__( 'Button Border Radius', 'wpr-addons' ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .wpr-mobile-toggle' => 'border-radius: {{SIZE}}{{UNIT}};',
],
]
);
$this->end_controls_section(); // End Controls Section
}
public function custom_menu_item_classes( $atts, $item, $args, $depth ) {
$settings = $this->get_active_settings();
// Main or Mobile
if ( strpos( $args->menu_id, 'mobile-menu' ) === false ) {
$main = 'wpr-menu-item wpr-pointer-item';
$sub = 'wpr-sub-menu-item';
$active = $settings['menu_item_highlight'] === 'yes' ? ' wpr-active-menu-item' : '';
} else {
$main = 'wpr-mobile-menu-item';
$sub = 'wpr-mobile-sub-menu-item';
$active = $settings['mobile_menu_highlight'] === 'yes' ? ' wpr-active-menu-item' : '';
}
$classes = $depth ? $sub : $main;
if ( in_array( 'current-menu-item', $item->classes ) ) {
$classes .= $active;
}
if ( empty( $atts['class'] ) ) {
$atts['class'] = $classes;
} else {
$atts['class'] .= ' '. $classes;
}
return $atts;
}
public function custom_sub_menu_class( $classes ) {
$classes[] = 'wpr-sub-menu';
return $classes;
}
public function custom_menu_items( $output, $item, $depth, $args ) {
$settings = $this->get_active_settings();
if ( strpos( $args->menu_class, 'wpr-nav-menu' ) !== false ) {
if ( in_array( 'menu-item-has-children', $item->classes ) ) {
$item_class = 'wpr-menu-item wpr-pointer-item';
if ( in_array( 'current-menu-item', $item->classes ) || in_array( 'current-menu-ancestor', $item->classes ) ) {
$item_class .= ' wpr-active-menu-item';
}
// Sub Menu Classes
if ( $depth > 0 ) {
$item_class = 'wpr-sub-menu-item';
if ( in_array( 'current-menu-item', $item->classes ) || in_array( 'current-menu-ancestor', $item->classes ) ) {
$item_class .= ' wpr-active-menu-item';
}
}
// Add Sub Menu Icon
$output ='
'. esc_html($item->title);
// GOGA: render language switcher correctly
$output = ''
. wp_kses($item->title, array(
'span' => array('class' => array()), // Allow tags with class attribute
'a' => array( // Allow tags with specified attributes
'href' => array(),
'title' => array(),
'class' => array(),
),
'img' => array( // Allow
tags with specified attributes
'src' => array(),
'alt' => array(),
'title' => array(),
'width' => array(),
'height' => array(),
'class' => array(),
),
'i' => array('class' => array()), // Allow tags with class attribute for icons
));
if ( $depth > 0 ) {
if ( 'inline' === $settings['menu_items_submenu_position'] ) {
$output .='';
} else {
$output .='';
}
} else {
if ( 'absolute' === $settings['menu_items_submenu_position'] ) {
$output .='';
} else {
$output .='';
}
}
$output .='';
}
}
return $output;
}
protected function render() {
$available_menus = $this->get_available_menus();
if ( ! $available_menus ) {
return;
}
// Get Settings
$settings = $this->get_active_settings();
$args = [
'echo' => false,
'menu' => $settings['menu_select'],
'menu_class' => 'wpr-nav-menu',
'menu_id' => 'menu-'. $this->get_nav_menu_index() .'-'. $this->get_id(),
'container' => '',
'fallback_cb' => '__return_empty_string',
];
// Custom Menu Items
add_filter( 'walker_nav_menu_start_el', [ $this, 'custom_menu_items' ], 10, 4 );
// Add Custom Filters
add_filter( 'nav_menu_link_attributes', [ $this, 'custom_menu_item_classes' ], 10, 4 );
add_filter( 'nav_menu_submenu_css_class', [ $this, 'custom_sub_menu_class' ] );
add_filter( 'nav_menu_item_id', '__return_empty_string' );
// Generate Menu HTML
$menu_html = wp_nav_menu( $args );
// Generate Mobile Menu HTML
$args['menu_id'] = 'mobile-menu-'. $this->get_nav_menu_index() .'-'. $this->get_id();
$args['menu_class'] = 'wpr-mobile-nav-menu';
$moible_menu_html = wp_nav_menu( $args );
// Remove Custom Filters
remove_filter( 'nav_menu_link_attributes', [ $this, 'custom_menu_item_classes' ] );
remove_filter( 'nav_menu_submenu_css_class', [ $this, 'custom_sub_menu_class' ] );
remove_filter( 'walker_nav_menu_start_el', [ $this, 'custom_menu_items' ] );
remove_filter( 'nav_menu_item_id', '__return_empty_string' );
if ( empty( $menu_html ) ) {
return;
}
if ( ! wpr_fs()->can_use_premium_code() ) {
$settings['menu_layout'] = 'horizontal';
$settings['toggle_btn_style'] = 'hamburger';
}
// Main Menu
echo '';
// Mobile Menu
echo '';
}
}