' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
add_action( 'wp_head', 'flatsome_viewport_meta', 1 );
/**
* Header Navigation.
*
* @param string $nav Navigation menu position.
* @param bool $walker Navigation Class.
*
* @return void
*/
function flatsome_header_nav( $nav, $walker = false ) {
$admin_url = get_admin_url() . 'customize.php?url=' . get_permalink() . '&autofocus%5Bsection%5D=menu_locations';
// Check if has Custom mobile menu.
if ($nav == 'primary' && $walker == 'FlatsomeNavSidebar' && has_nav_menu( 'primary_mobile' )) $nav = 'primary_mobile';
// If single page.
$page_template = get_post_meta( get_the_ID(), '_wp_page_template', true );
$default_template = get_theme_mod( 'pages_template', 'default' );
$is_single_nav_template = ! empty( $page_template ) && strpos( $page_template, 'single-page-nav' ) !== false;
$is_single_nav_default_template = ( empty( $page_template ) || $page_template == 'default' ) && strpos( $default_template, 'single-page-nav' ) !== false;
$is_woo_page = is_woocommerce_activated() ? is_cart() || is_checkout() || is_account_page() : false;
$needs_single_nav_helper = ( $is_single_nav_template || $is_single_nav_default_template ) && $nav == 'primary' && is_page() && ! $is_woo_page;
// Add single page nav helper.
if ( $needs_single_nav_helper ) { ?>
$nav,
'container' => false,
'items_wrap' => '%3$s',
'depth' => 0,
'walker' => new $walker(),
));
} else {
echo 'Assign a menu in Theme Options > Menus'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* Navigation Builder.
*
* @param string $options Theme options.
* @param string $type Navigation type.
*
* @return void
*/
function flatsome_header_elements( $options, $type = '' ) {
// Get options.
$get_options = get_theme_mod( $options );
$walker = 'FlatsomeNavDropdown';
if ($type == 'sidebar') $walker = 'FlatsomeNavSidebar';
// Set options.
if ( is_array( $get_options ) ) {
foreach ( $get_options as $key => $value ) {
if ( $value == 'divider' || $value == 'divider_2' || $value == 'divider_3' || $value == 'divider_4' || $value == 'divider_5' ) {
echo '';
} elseif ( $value == 'html' || $value == 'html-2' || $value == 'html-3' || $value == 'html-4' || $value == 'html-5' ) {
flatsome_get_header_html_element( $value );
} elseif ( $value == 'block-1' || $value == 'block-2' ) {
echo do_shortcode( '' );
} elseif ( $value == 'nav-top' ) {
flatsome_header_nav( 'top_bar_nav', $walker );
} elseif ( $value == 'nav' ) {
flatsome_header_nav( 'primary', $walker );
} elseif ( $value == 'nav-vertical' && $type === 'sidebar' ) {
flatsome_header_nav( 'vertical', $walker );
} elseif ( $value == 'wpml' ) {
get_template_part( 'template-parts/header/partials/element-languages', $type );
} else {
get_template_part( 'template-parts/header/partials/element-' . $value, $type );
}
// Hooked Elements.
do_action( 'flatsome_header_elements', $value );
}
}
}
/**
* Get Header HTML Elements.
*
* @param string $value Header HTML elements.
*
* @return void
*/
function flatsome_get_header_html_element( $value ) {
$mod = array(
'name' => '',
'default' => '',
);
if ( $value == 'html' ) {
$mod['name'] = 'topbar_left';
$mod['default'] = 'Add anything here or just remove it...';
}
if ( $value == 'html-2' ) $mod['name'] = 'topbar_right';
if ( $value == 'html-3' ) $mod['name'] = 'top_right_text';
if ( $value == 'html-4' ) $mod['name'] = 'nav_position_text_top';
if ( $value == 'html-5' ) $mod['name'] = 'nav_position_text';
if ( get_theme_mod( $mod['name'], $mod['default'] ) ) {
echo '' . do_shortcode( get_theme_mod( $mod['name'], $mod['default'] ) ) . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* FlatsomeNavDropdown Class.
*
* Extends Walker_Nav_Menu Class.
*/
class FlatsomeNavDropdown extends Walker_Nav_Menu {
/**
* Starts the list before the elements are added.
*
* @since 3.0.0
*
* @see Walker::start_lvl()
*
* @param string $output Used to append additional content (passed by reference).
* @param int $depth Depth of menu item. Used for padding.
* @param stdClass $args An object of wp_nav_menu() arguments.
*/
public function start_lvl( &$output, $depth = 0, $args = null ) {
if ( isset( $args->item_spacing ) && 'discard' === $args->item_spacing ) {
$t = '';
$n = '';
} else {
$t = "\t";
$n = "\n";
}
$indent = str_repeat( $t, $depth );
// Default class.
$classes = array( 'sub-menu' );
$display_depth = $depth + 1;
if ( $display_depth == '1' ) {
$classes[] = 'nav-dropdown';
} else {
$classes[] = 'nav-column';
}
$classes = $this->ux_add_dropdown_classes( $classes );
/**
* Filters the CSS class(es) applied to a menu list element.
*
* @since 4.8.0
*
* @param string[] $classes Array of the CSS classes that are applied to the menu `` element.
* @param stdClass $args An object of `wp_nav_menu()` arguments.
* @param int $depth Depth of menu item. Used for padding.
*/
$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
$output .= "{$n}{$indent}