<?php

/**

 * Functions which enhance the theme by hooking into WordPress

 *

 * @package Glowify WP

 */



/**

 * Adds custom classes to the array of body classes.

 *

 * @param array $classes Classes for the body element.s

 * @return array

 */

function glowify_wp_body_classes( $classes ) {
	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	// Adds a class of no-sidebar when there is no sidebar present.
	if ( ! is_active_sidebar( 'glowify-blog-sidebar' ) ) {
		$classes[] = 'no-sidebar';
	}


	return $classes;

}

add_filter( 'body_class', 'glowify_wp_body_classes' );



function custom_body_open() {
    $enable_preloader = glowify_wp_option('enable_preloader') ?? true;
    $enable_scroll_up = glowify_wp_option('enable_scroll_up') ?? true;
    

    if ($enable_preloader == true) : ?>
        <!-- Start Preloader -->
        <div class="cs_preloader">
            <div class="cs_preloader_in">
                <span></span>
                <span></span>
            </div>
            <?php if(!empty($preloader_shape_src[0]) ) :?>
                <div class="cs_preloader_shape"><img src="<?php echo esc_url($preloader_shape_src[0]);?>"></div>
            <?php endif;?>
            <?php if(!empty($preloader_shape_src2[0]) ) :?>
                <div class="cs_preloader_shape_2"><img src="<?php echo esc_url($preloader_shape_src2[0]);?>"></div>
            <?php endif;?>
        </div>
        <!-- End Preloader -->
    <?php endif;


    if ($enable_scroll_up == true) : ?>
    <div class="cs_scrollup">
        <svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 16 16"><path fill="currentColor" d="M7.5 13.022V14.5a.5.5 0 0 0 1 0v-1.478a4.886 4.886 0 0 0 2.775-8.486l-2.437-2.2a1.25 1.25 0 0 0-1.676 0l-2.437 2.2A4.886 4.886 0 0 0 7.5 13.022Zm3.105-7.744A3.886 3.886 0 0 1 8.5 12.015V7.501a.5.5 0 0 0-1 0v4.514a3.886 3.886 0 0 1-2.105-6.737l2.437-2.2a.25.25 0 0 1 .336 0l2.437 2.2Z"></path></svg>
    </div>
    <?php endif;
}
add_action('wp_body_open', 'custom_body_open');



/**

 * Set the content width in pixels, based on the theme's design and stylesheet.

 *

 * Priority 0 to make it available to lower priority callbacks.

 *

 * @global int $content_width

 */

function glowify_wp_content_width() {

	// This variable is intended to be overruled from themes.

	// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.

	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound

	$GLOBALS['content_width'] = apply_filters( 'bizwheel_content_width', 640 );

}

add_action( 'after_setup_theme', 'glowify_wp_content_width', 0 );



/**

 * Current Page .active class.

 */

add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);

function special_nav_class($classes, $item){

     if( in_array('current-menu-item', $classes) ){

             $classes[] = 'active ';

     }

     return $classes;

}



add_filter('nav_menu_css_class' , 'special_nav_classs' , 10 , 2);

function special_nav_classs($classes, $item){

     if( in_array('menu-item-has-children', $classes) ){

             $classes[] = 'dropdown ';

     }

     return $classes;

}



/**

 * Add a pingback url auto-discovery header for single posts, pages, or attachments.

 */

function glowify_wp_pingback_header() {

	if ( is_singular() && pings_open() ) {

		printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );

	}

}

add_action( 'wp_head', 'glowify_wp_pingback_header' );



// Remove related products from the single product page
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_filter( 'wcdp_only_one_form_allowed', '__return_false' );



