header_options = get_option('dnxte_header_navigation_options', array());
$menu_badge = isset($this->header_options['menu_item_badge']) ? $this->header_options['menu_item_badge'] : 0;
$is_cta_btn = isset($this->header_options['cta_menu_button']) ? $this->header_options['cta_menu_button'] : 0;
add_action('admin_menu', array($this, 'add_submenu_page'), 21);
if ($is_cta_btn) {
add_action('et_header_top', [$this, 'cta_btn_callback'], 10);
}
add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_styles_and_scripts']);
add_action('wp_enqueue_scripts', [$this, 'enqueue_styles_and_scripts']);
add_action('wp_ajax_dnxte_header_navigation', [$this, 'dnxte_save_header_navigation_options']);
if ($menu_badge) {
add_action('wp_nav_menu_item_custom_fields', [$this, 'dnxte_custom_menu_field'], 10, 4);
add_action('wp_update_nav_menu_item', [$this, 'save_dnxte_custom_menu_field'], 10, 3);
add_filter('nav_menu_css_class', [$this, 'dnxte_add_custom_li_class'], 10, 4);
add_filter('walker_nav_menu_start_el', [$this, 'dnxte_custom_menu_field_frontend'], 10, 4);
}
add_action('customize_register', [$this, 'dnxte_get_customizer_settings']);
add_action('customize_controls_print_styles', [$this, 'dnxte_customizer_styles']);
add_action('customize_preview_init', [$this, 'dnxte_customizer_preview_script']);
add_filter('body_class', [$this, 'add_hover_effect_body_class']);
if (isset($this->header_options['change_logo_onscroll']) && $this->header_options['change_logo_onscroll'] === 1) {
add_filter('et_html_logo_container', [$this, 'modify_divi_logo_with_span']);
}
}
public function modify_divi_logo_with_span($logo_html)
{
// Check if we're dealing with the main logo
$dnxte_on_scroll_logo = isset($this->header_options['on_scroll_logo']) ? $this->header_options['on_scroll_logo'] : '';
if (!empty($dnxte_on_scroll_logo) && strpos($logo_html, 'id="logo"') !== false) {
$logo_html = preg_replace(
'/(
]*>)/',
'$1
',
$logo_html
);
} else {
return $logo_html;
}
return $logo_html;
}
public function add_hover_effect_body_class($classes)
{
if (!empty($this->header_options['group_of_effects'])) {
$classes[] = 'dnxte-menu-hover-animation dnxte-hover-' . sanitize_html_class($this->header_options['group_of_effects']);
}
return $classes;
}
/**
* Enqueue customizer preview script
*/
public function dnxte_customizer_preview_script()
{
wp_enqueue_script(
'dnxte-customizer-preview',
DIVI_ESSENTIAL_ASSETS . 'js/header-navigation-customizer.js',
array('customize-preview'),
DIVI_ESSENTIAL_VERSION,
true
);
}
/**
* Customizer panel and section styles =================
*
* @param [type] $wp_customize
* @return void
*/
public function dnxte_customizer_styles($wp_customize)
{
$option_id_selectors = $this->dnxte_customizer_key_as_selector();
$dnxte_option_li_id = $this->dnxte_customizer_key_as_selector_li();
?>
ID, '_dnxte_custom_menu_field', true);
if (! empty($badge_class)) {
// Add custom class to
$classes[] = 'dnxte-has-badge';
}
return $classes;
}
/**
* Save custom menu field value
*/
public function dnxte_custom_menu_field_frontend($item_output, $item, $depth, $args)
{
$custom_value = get_post_meta($item->ID, '_dnxte_custom_menu_field', true);
$badge_class = get_post_meta($item->ID, '_dnxte_custom_menu_field_type', true);
$customize_badge_style = get_option('dnxte_menu_badge_style', 'default');
if (! empty($custom_value)) {
$item_output .= '';
}
return $item_output;
}
/**
* Admin Enqueue styles and scripts
*/
public function enqueue_admin_styles_and_scripts()
{
if (!is_admin()) {
return;
}
wp_enqueue_media();
wp_enqueue_script('dnxte-onscroll-logo-upload', DIVI_ESSENTIAL_ASSETS . 'admin/js/onscroll-logo-upload.js', array('jquery'), null, true);
}
/**
* Enqueue styles and scripts for the header navigation
*
* @return void
*/
public function enqueue_styles_and_scripts()
{
if (is_admin()) {
return;
}
$font_url = $this->get_header_navigation_fonts();
if (!empty($font_url)) {
wp_enqueue_style('header-navigation-fonts', esc_url_raw($font_url), array(), null);
}
wp_enqueue_style('dnxte-header-navigation', DIVI_ESSENTIAL_ASSETS . 'css/header-navigation.css', array(), DIVI_ESSENTIAL_VERSION);
wp_enqueue_style('dashicons');
if (! is_admin()) {
wp_enqueue_style(
'dnxte-customizer-preview-style',
$this->render_style(),
array(),
DIVI_ESSENTIAL_VERSION
);
}
wp_enqueue_script('dnext_scripts-public');
}
/**
* Add custom menu field
*/
public function add_submenu_page()
{
add_submenu_page(
'dnxte-essential',
esc_html__('Header & Navigation', 'dnxte-divi-essential'),
esc_html__('Header & Navigation', 'dnxte-divi-essential'),
'manage_options',
'dnxte-header-navigation',
array($this, 'render_header_navigation_page'),
2
);
}
/**
* Custom menu field
*/
public function cta_btn_callback()
{
$cta_text = isset($this->header_options['button_text']) && !empty($this->header_options['button_text']) ? $this->header_options['button_text'] : __('Click Here', 'dnxte-divi-essential');
$cta_url = isset($this->header_options['button_url']) ? $this->header_options['button_url'] : '#';
$btn_target = isset($this->header_options['button_link_target']) ? $this->header_options['button_link_target'] : '_self';
$btn_css_class = isset($this->header_options['button_css_class']) ? $this->header_options['button_css_class'] : '';
$hide_on_desktop = isset($this->header_options['hide_on_desktop']) && $this->header_options['hide_on_desktop'] === 1 ? 'hide_on_desktop' : '';
$hide_on_tablet = isset($this->header_options['hide_on_tablet']) && $this->header_options['hide_on_tablet'] === 1 ? 'hide_on_tablet' : '';
$hide_on_mobile = isset($this->header_options['hide_on_mobile']) && $this->header_options['hide_on_mobile'] === 1 ? 'hide_on_mobile' : '';
$btn_css_class .= ' ' . $hide_on_desktop . ' ' . $hide_on_tablet . ' ' . $hide_on_mobile;
$btn_css_class = trim($btn_css_class);
$btn_order = isset($this->header_options['btn_order']) ? $this->header_options['btn_order'] : 5;
$icon_position = isset($this->header_options['icon_position']) ? $this->header_options['icon_position'] : 'after_text';
$btn_target = $btn_target === '_blank' ? ' target="_blank"' : '';
$button_icon = !empty(get_option('dnxte_icon_setting')) ? get_option('dnxte_icon_setting') : '';
if ($button_icon) {
$btn_css_class .= ' dnxte-has-icon';
if ($icon_position === 'before_text') {
$cta_text = '' . $button_icon . '' . wp_kses_post($cta_text);
} else {
$cta_text .= '' . $button_icon . '';
}
}
$theme_mode_cta_class = get_theme_mod('dnxte_button_hover_effect_select');
if (!empty($cta_text)) {
echo '';
}
}
/**
* Tooltip markup function
*/
public function tooltip_markup($text)
{
return '';
}
/**
* Render the header navigation page
*/
public function render_header_navigation_page()
{
$dnxte_header_navigation_options = $this->header_options;
$toggle_options = array(
'hover_animation' => array(
'title' => __('Add Hover Animation', 'dnxte-divi-essential'),
'info' => __('Choose a hover animation effect for the header menu items.', 'dnxte-divi-essential'),
'children' => array(
'hover_effect_none' => array(
'title' => __('None', 'dnxte-divi-essential'),
'info' => __('None', 'dnxte-divi-essential'),
),
'hover_effect_fill_slide_down' => array(
'title' => __('Fill Slide Down', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_fill_slide_up' => array(
'title' => __('Fill Slide Up', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_fill_slide_left' => array(
'title' => __('Fill Slide Left', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_fill_slide_right' => array(
'title' => __('Fill Slide right', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_slide_down' => array(
'title' => __('Slide Down', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_slide_up' => array(
'title' => __('Slide Up', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_slide_left' => array(
'title' => __('Slide Left', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_slide_right' => array(
'title' => __('Slide right', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_border_lr' => array(
'title' => __('Border Left/Right Corners', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_border_rl' => array(
'title' => __('Border Right/Left Corners', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_revel_border' => array(
'title' => __('Revel Border', 'dnxte-divi-essential'),
'info' => __('Background fills on hover.', 'dnxte-divi-essential'),
),
'hover_effect_glow' => array(
'title' => __('Soft Glow', 'dnxte-divi-essential'),
'info' => __('Glowing background effect.', 'dnxte-divi-essential'),
),
'hover_effect_borderbr' => array(
'title' => __('Border Bottom Radius', 'dnxte-divi-essential'),
'info' => __('Border bottom radius on hover.', 'dnxte-divi-essential'),
),
'hover_effect_corner_in' => array(
'title' => __('Corner Slide In', 'dnxte-divi-essential'),
'info' => __('Corners slide in on hover.', 'dnxte-divi-essential'),
),
'hover_effect_underline' => array(
'title' => __('Underline Slide', 'dnxte-divi-essential'),
'info' => __('Animated underline on hover.', 'dnxte-divi-essential'),
),
'hover_effect_border_oval' => array(
'title' => __('Rounded Border', 'dnxte-divi-essential'),
'info' => __('Oval border appears on hover.', 'dnxte-divi-essential'),
),
'hover_effect_brackets' => array(
'title' => __('Brackets', 'dnxte-divi-essential'),
'info' => __('Brackets animate around text.', 'dnxte-divi-essential'),
),
'hover_effect_simple_underline' => array(
'title' => __('Simple Underline', 'dnxte-divi-essential'),
'info' => __('Basic underline on hover.', 'dnxte-divi-essential'),
)
),
),
'cta_menu_button' => array(
'title' => __('Add CTA Menu Button', 'dnxte-divi-essential'),
'info' => __('Enable Call to Action button in the Header.', 'dnxte-divi-essential'),
),
'custom_dropdown' => array(
'title' => __('Custom Menu Dropdown', 'dnxte-divi-essential'),
'info' => __('Enable this option to add custom dropdown menu functionality.', 'dnxte-divi-essential'),
),
'change_logo_onscroll' => array(
'title' => __('Change Logo on Scroll', 'dnxte-divi-essential'),
'info' => __('Upload your logo that will be displayed when scrolling down.', 'dnxte-divi-essential'),
'on_scroll_logo' => array(
'title' => __('Upload On Scroll Logo', 'dnxte-divi-essential'),
),
),
'menu_item_badge' => array(
'title' => __('Add Badge On Main Menu', 'dnxte-divi-essential'),
'info' => __('Add menu item badge from the Appearance > Menus > Items > Badge', 'dnxte-divi-essential'),
),
'customize_header' => array(
'title' => __('Header Format', 'dnxte-divi-essential'),
'info' => __('Style the header format option from the customizer.', 'dnxte-divi-essential'),
),
); ?>
'Settings saved successfully!',
)
);
}
/**
* File Upload function
*/
public static function upload_image($file)
{
// this function will be update just note
if (!isset($file) && !is_array($file) && empty($file['name'])) {
return;
}
// Security: Check user capabilities (optional)
if (!current_user_can('upload_files')) {
wp_die('You are not allowed to upload files.');
}
require_once ABSPATH . 'wp-admin/includes/file.php';
$allowed_mimes = [
'jpg|jpeg|jpe' => 'image/jpeg',
'png' => 'image/png',
'gif' => 'image/gif',
'svg' => 'image/svg+xml',
];
$upload_overrides = [
'test_form' => false,
'mimes' => $allowed_mimes,
];
$uploaded = wp_handle_upload($file, $upload_overrides);
if (!isset($uploaded['error'])) {
return $uploaded['url'];
} else {
// Handle the error
wp_send_json_error(array('message' => $uploaded['error']));
}
}
// Add custom field in menu item
public function dnxte_custom_menu_field($item_id, $item, $depth, $args)
{
static $nonce_output = false;
if (!$nonce_output) {
wp_nonce_field('dnxte_menu_nonce_action', 'dnxte_menu_nonce');
$nonce_output = true;
}
// Get existing value
$value = get_post_meta($item_id, '_dnxte_custom_menu_field', true); ?>