<?php
/**
 * menda functions and definitions
 *
 * Set up the theme and provides some helper functions, which are used in the
 * theme as custom template tags. Others are attached to action and filter
 * hooks in WordPress to change core functionality.
 *
 * When using a child theme you can override certain functions (those wrapped
 * in a function_exists() call) by defining them first in your child theme's
 * functions.php file. The child theme's functions.php file is included before
 * the parent theme's file, so the child theme functions would be used.
 *
 * @link https://codex.wordpress.org/Theme_Development
 * @link https://codex.wordpress.org/Child_Themes
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are
 * instead attached to a filter or action hook.
 *
 * For more information on hooks, actions, and filters,
 * {@link https://codex.wordpress.org/Plugin_API}
 *
 * @package WordPress
 * @subpackage menda
 * @since bid 1.0
 */

/*
 * Loads the Options Panel
 *
 * If you're loading from a child theme use stylesheet_directory
 * instead of template_directory
 */
 
 /* automatic theme update codes */
 // Check for theme updates
// Check for theme updates
function my_custom_theme_check_for_updates( $transient ) {
    if ( empty( $transient->checked ) ) {
        return $transient;
    }

    // Your theme slug
    $theme_slug = 'menda';

    // Get the theme data
    $theme_data = wp_get_theme( $theme_slug );

    // Current version of the installed theme
    $current_version = $theme_data->get( 'Version' );

    // URL of the update JSON file  https://tmdwordpress.com/menda/theme-update.json
    $remote_url = 'https://tmdwordpress.com/menda/theme-update.json'; // Replace with your URL

    // Fetch the update data from the remote server
    $remote_response = wp_remote_get( $remote_url );

    // Check for errors in the remote response
    if ( is_wp_error( $remote_response ) ) {
        error_log( "Failed to fetch update data: " . $remote_response->get_error_message() );
        return $transient; // Return early if the request failed
    }

    // Get the response body and decode it
    $remote_body = wp_remote_retrieve_body( $remote_response );
    $remote_data = json_decode( $remote_body );

    // Check if remote_data is null or doesn't contain the 'version' field
    if ( is_null( $remote_data ) || ! isset( $remote_data->version ) ) {
        error_log( "Invalid update data or missing version in the response." );
        return $transient; // Return early if the response is not as expected
    }

    // Check if the remote version is greater than the current version
    if ( version_compare( $current_version, $remote_data->version, '<' ) ) {
        $transient->response[ $theme_slug ] = array(
            'new_version' => $remote_data->version,
            'package'     => $remote_data->download_url,
            'url'         => 'https://tmdwordpress.com/menda/', // URL to theme info or changelog
        );
    }

    return $transient;
}
add_filter( 'site_transient_update_themes', 'my_custom_theme_check_for_updates' );


// Show theme update details
function my_custom_theme_update_details( $response, $theme_slug ) {
    if ( 'my-custom-theme' === $theme_slug ) {
        $response['sections'] = array(
            'description' => 'This is an update for My Custom Theme.',
            'changelog'   => 'Version 1.1.0 includes bug fixes and improvements.',
        );
    }
    return $response;
}
add_filter( 'themes_api', 'my_custom_theme_update_details', 10, 3 );
 /* automatic theme update codes */
 

define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/' );

/**
 * Options-framework for this theme.
 */
 //add_theme_support( 'woocommerce' );
 
 
require_once get_template_directory() . '/admin/options-framework.php';

/**
 * Options for this theme.
 */
require_once get_template_directory() . '/options.php';

/**
 * Tgm-Plugin-Activation for this theme.
 */
require_once get_template_directory() . '/tgm-plugin-activation/class-tgm-plugin-activation.php';

/**
 * Plugin Options for this theme.
 */
require_once get_template_directory() . '/tgm-plugin-activation/plugin-options.php';

/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * include demo importer.
 */
require_once get_template_directory() . '/demo-import/demo-import.php';

/*
 * This is an example of how to add custom scripts to the options panel.
 * This one shows/hides the an option when a checkbox is clicked.
 */
require get_template_directory() .'/admin/admin-custome.php';


/**
 * version compare
 */ 
if ( version_compare( $GLOBALS['wp_version'], '4.4-alpha', '<' ) ) {
	require get_template_directory() . '/inc/back-compat.php';
}


if ( ! function_exists( 'menda_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 *
	 * Create your own menda_setup() function to override in a child theme.
	 *
	 */
	add_action( 'after_setup_theme', 'menda_setup' );
	function menda_setup() {
		/*

		 * Make theme available for translation.

		 * Translations can be filed in the /languages/ directory.

		 * If you're building a theme based on menda Theme, use a find and replace

		 * to change 'menda' to the name of your theme in all the template files

		 */
		// load_theme_textdomain( 'menda', get_template_directory() . '/languages' );
		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );
		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */
		add_theme_support( 'title-tag' );
		/*
		 * Enable support for custom logo.
		 *
		 *  @since menda Theme 1.2
		 */
		add_theme_support( 'custom-logo', array(
			'height'      => 240,
			'width'       => 240,
			'flex-height' => true,
		) );
		/*
		 * Enable support for Post Thumbnails on posts and pages.
		 *
		 * @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
		 */
		add_theme_support( 'post-thumbnails' );
		set_post_thumbnail_size( 1200, 9999 );
		// This theme uses wp_nav_menu() in two locations.
		register_nav_menus( array(
			'primary'          => esc_html__( 'Primary Menu', 'menda' ),
			'top_header'       => esc_html__( 'Top Header Menu', 'menda' ),
			'information'      => esc_html__( 'Footer Information', 'menda' ),
			'customer_service' => esc_html__( 'Footer Customer Service', 'menda' ),
			'my_account'       => esc_html__( 'footer My Account', 'menda' ),
		) );
		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support( 'html5', array(
			'search-form',
			'comment-form',
			'comment-list',
			'gallery',
			'caption',
		) );
		/*
		 * Enable support for Post Formats.
		 *
		 * See: https://codex.wordpress.org/Post_Formats
		 */
		add_theme_support( 'post-formats', array(
			'aside',
			'image',
			'video',
			'quote',
			'link',
			'gallery',
			'status',
			'audio',
			'chat',
		) );
		/*
		 * This theme styles the visual editor to resemble the theme style,
		 * specifically font, colors, icons, and column width.
		 */
		// Indicate widget sidebars can use selective refresh in the Customizer.
		add_theme_support( 'customize-selective-refresh-widgets' );
	}
endif; // menda_setup

// woocommerce support theme
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
	add_theme_support( 'woocommerce' );
	add_theme_support( 'wc-product-gallery-zoom' );
	add_theme_support( 'wc-product-gallery-lightbox' );
	add_theme_support( 'wc-product-gallery-slider' );
}

/**
 * Sets 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
 *
 * @since menda Theme 1.0
 */
add_action( 'after_setup_theme', 'menda_content_width', 0 );
function menda_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'menda_content_width', 840 );
}

/**
 * Registers a widget area.
 *
 * @link https://developer.wordpress.org/reference/functions/register_sidebar/
 *
 * @since menda Theme 1.0
 */
add_action( 'widgets_init', 'menda_widgets_init' );
function menda_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'menda' ),
		'id'            => 'sidebar-1',
		'description'   => esc_html__( 'Add widgets here to appear in your sidebar.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
    register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 1', 'menda' ),
		'id'            => 'footer-1',
		'description'   => esc_html__( 'Add widgets to apper in footer column.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
    register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 2', 'menda' ),
		'id'            => 'footer-2',
		'description'   => esc_html__( 'Add widgets to apper in footer column 2.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 3', 'menda' ),
		'id'            => 'footer-3',
		'description'   => esc_html__( 'Add widgets to apper in footer column 3.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 4', 'menda' ),
		'id'            => 'footer-4',
		'description'   => esc_html__( 'Add widgets to apper in footer column 4.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );

	register_sidebar( array(
		'name'          => esc_html__( 'Footer Column 5', 'menda' ),
		'id'            => 'footer-5',
		'description'   => esc_html__( 'Add widgets to apper in footer column 5.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
	register_sidebar( array(
		'name'          => esc_html__( 'woocommerce Sidebar', 'menda' ),
		'id'            => 'woocommercecustome_sidebar',
		'description'   => esc_html__( 'Add widgets to apper in woocommerce pages.', 'menda' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_hr'  	=> '<hr>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
}

/**
 * Registers a widget area.
 *
 * @link https://developer.wordpress.org/reference/functions/register_sidebar/
 *
 * @since menda Theme 1.0
 */
add_action( 'admin_init', 'menda_primerymenu_init' );
function menda_primerymenu_init() {
	$menuname = 'primary';
	$menu_exists = wp_get_nav_menu_object( $menuname );

	if( !$menu_exists){
	$menu_id = wp_create_nav_menu($menuname);

		wp_update_nav_menu_item($menu_id, 0, array(
		    'menu-item-title'   =>  __('Sample Page', 'menda'),
		    'menu-item-classes' => 'samplepage',
		    'menu-item-url'     => home_url( '/sample-page/' ), 
		    'menu-item-status'  => 'publish')
		);
	}

	if ($menu_exists && $menu_exists->term_id) {
		$term_id_of_menu   = $menu_exists->term_id;
		$locations         = get_theme_mod('nav_menu_locations');
		$locations['primary'] = $term_id_of_menu;
		set_theme_mod( 'nav_menu_locations', $locations );
	}
}

if ( ! function_exists( 'ebid_fonts_url' ) ) :
/**
 * Register Google fonts for menda Theme.
 *
 * Create your own menda_fonts_url() function to override in a child theme.
 *
 * @since menda Theme 1.0
 *
 * @return string Google fonts URL for the theme.
 */
function ebid_fonts_url() {
	$fonts_url = '';
	$fonts     = array();
	$subsets   = 'latin,latin-ext';
	/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'menda' ) ) {
		$fonts[] = 'Merriweather:400,700,900,400italic,700italic,900italic';
	}
	/* translators: If there are characters in your language that are not supported by Montserrat, translate this to 'off'. Do not translate into your own language. */
	if ( 'off' !== _x( 'on', 'Montserrat font: on or off', 'menda' ) ) {
		$fonts[] = 'Montserrat:400,700';
	}
	/* translators: If there are characters in your language that are not supported by Inconsolata, translate this to 'off'. Do not translate into your own language. */

	if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'menda' ) ) {

		$fonts[] = 'Inconsolata:400';

	}

	if ( $fonts ) {

		$fonts_url = add_query_arg( array(

			'family' => urlencode( implode( '|', $fonts ) ),

			'subset' => urlencode( $subsets ),

		), 'https://fonts.googleapis.com/css' );

	}

	return $fonts_url;
}
endif;

/**
 * Handles JavaScript detection.
 *
 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
 *
 * @since menda Theme 1.0
 */
add_action( 'wp_head', 'menda_javascript_detection', 0 );
function menda_javascript_detection() {
	echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
}

/**
 * Adds custom classes to the array of body classes.
 *
 * @since menda Theme 1.0
 *
 * @param array $classes Classes for the body element.
 * @return array (Maybe) filtered body classes.
 */
add_filter( 'body_class', 'menda_body_classes' );
function menda_body_classes( $classes ) {
	// Adds a class of custom-background-image to sites with a custom background image.
	if ( get_background_image() ) {
		$classes[] = 'custom-background-image';
	}
	// Adds a class of group-blog to sites with more than 1 published author.
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}
	// Adds a class of no-sidebar to sites without active sidebar.
	if ( ! is_active_sidebar( 'sidebar-1' ) ) {
		$classes[] = 'no-sidebar';
	}
	// Adds a class of hfeed to non-singular pages.
	if ( ! is_singular() ) {
		$classes[] = 'hfeed';
	}
	return $classes;
}
/**
 * Converts a HEX value to RGB.
 *
 * @since menda Theme 1.0
 *
 * @param string $color The original color, in 3- or 6-digit hexadecimal form.
 * @return array Array containing RGB (red, green, and blue) values for the given
 *               HEX code, empty array otherwise.
 */
function ebid_hex2rgb( $color ) {

	$color = trim( $color, '#' );
	if ( strlen( $color ) === 3 ) {
		$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
		$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
		$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
	} else if ( strlen( $color ) === 6 ) {
		$r = hexdec( substr( $color, 0, 2 ) );
		$g = hexdec( substr( $color, 2, 2 ) );
		$b = hexdec( substr( $color, 4, 2 ) );
	} else {
		return array();
	}
	return array( 'red' => $r, 'green' => $g, 'blue' => $b );
}



/**
 * Add custom image sizes attribute to enhance responsive image functionality
 * for content images
 *
 * @since menda Theme 1.0
 *
 * @param string $sizes A source size value for use in a 'sizes' attribute.
 * @param array  $size  Image size. Accepts an array of width and height
 *                      values in pixels (in that order).
 * @return string A source size value for use in a content image 'sizes' attribute.
 */
add_filter( 'wp_calculate_image_sizes', 'menda_content_image_sizes_attr', 10 , 2 );
function menda_content_image_sizes_attr( $sizes, $size ) {
	$width = $size[0];
	840 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px';
	if ( 'page' === get_post_type() ) {
		840 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
	} else {
		840 > $width && 600 <= $width && $sizes = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px';
		600 > $width && $sizes = '(max-width: ' . $width . 'px) 85vw, ' . $width . 'px';
	}
 return $sizes;
}

/**
 * Add custom image sizes attribute to enhance responsive image functionality
 * for post thumbnails
 *
 * @since menda Theme 1.0
 *
 * @param array $attr Attributes for the image markup.
 * @param int   $attachment Image attachment ID.
 * @param array $size Registered image size or flat array of height and width dimensions.
 * @return string A source size value for use in a post thumbnail 'sizes' attribute.
 */
// add_filter( 'wp_get_attachment_image_attributes', 'menda_post_thumbnail_sizes_attr', 10 , 3 );
function menda_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
	if ( 'post-thumbnail' === $size ) {
		is_active_sidebar( 'sidebar-1' ) && $attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 60vw, (max-width: 1362px) 62vw, 840px';
		! is_active_sidebar( 'sidebar-1' ) && $attr['sizes'] = '(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 88vw, 1200px';
	}
	return $attr;
}

/**
 * Modifies tag cloud widget arguments to have all tags in the widget same font size.
 *
 * @since menda Theme 1.1
 *
 * @param array $args Arguments for tag cloud widget.
 * @return array A new modified arguments.
 */
add_filter( 'widget_tag_cloud_args', 'menda_widget_tag_cloud_args' );
function menda_widget_tag_cloud_args( $args ) {
	$args['largest'] = 1;
	$args['smallest'] = 1;
	$args['unit'] = 'em';
	return $args;
}

/* add to cart function  */	
// Display or Count how many times a post has been viewed. //
function ebid_post_counter($postID) {
    $count_key =  esc_html__('views', 'menda');
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
    return $count; 
}

/***************************  PAGINATION START  **********************/
function post_ebid_navi_pagination() {
    if( is_singular() )
        return;
    global $wp_query;
    /** Stop execution if there's only 1 page */
    if( $wp_query->max_num_pages <= 1 )
        return;
    $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
    $max   = intval( $wp_query->max_num_pages );
    /** Add current page to the array */
    if ( $paged >= 1 )
        $links[] = $paged;
    /** Add the pages around the current page to the array */
    if ( $paged >= 3 ) {
        $links[] = $paged - 1;
        $links[] = $paged - 2;
    }
    if ( ( $paged + 2 ) <= $max ) {
        $links[] = $paged + 2;
        $links[] = $paged + 1;
    }
    echo '<div class="navigation"><ul>' . "\n";
    /** Previous Post Link */
    if ( get_previous_posts_link() )
        printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
    /** Link to first page, plus ellipses if necessary */
    if ( ! in_array( 1, $links ) ) {
        $class = 1 == $paged ? ' class="active"' : '';
        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
        if ( ! in_array( 2, $links ) )
            echo '<li></li>';
    }
    /** Link to current page, plus 2 pages in either direction if necessary */
    sort( $links );
    foreach ( (array) $links as $link ) {
        $class = $paged == $link ? ' class="active"' : '';
        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
    }
    /** Link to last page, plus ellipses if necessary */
    if ( ! in_array( $max, $links ) ) {
        if ( ! in_array( $max - 1, $links ) )
            echo '<li>...</li>' . "\n";
        $class = $paged == $max ? ' class="active"' : '';
        printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
    }

    /** Next Post Link */
    if ( get_next_posts_link() )
        printf( '<li>%s</li>' . "\n", get_next_posts_link() );
    echo '</ul></div>' . "\n";
}

/***************************  PAGINATION END  **********************/

/**************************** BREADCRUMBS START *********************/
// Breadcrumbs
function ebid_breadcrumbs() {
    // Settings
    $separator          = '/';
    $breadcrums_id      = esc_html__('breadcrumbs', 'menda');
    $breadcrums_class   = esc_html__('breadcrumbs', 'menda');
    $home_title         = esc_html__('Home', 'menda');
	$prefix             = '';
	$category           = '';
	$get_term_id        = '';
	$get_term_slug      = '';
    $get_term_name      = '';
	$parents            = '';   
    // If you have any custom post types with custom taxonomies, put the taxonomy name below (e.g. product_cat)
    $custom_taxonomy    = 'product_cat';
    // Get the query & post information
    global $post,$wp_query;
    // Do not display on the homepage
    if ( !is_front_page() ) {
        // Build the breadcrums
        echo '<ul id="' . $breadcrums_id . '" class="' . $breadcrums_class . '">';
        // Home page
        echo '<li class="item-home"><a class="bread-link bread-home" href="' . get_home_url() . '" title="' . $home_title . '"><i class="fa fa-home"></i>' . $home_title . '</a></li>';
        echo '<li class="separator separator-home"> ' . $separator . ' </li>';
        if ( is_archive() && !is_tax() && !is_category() && !is_tag() ) {
            echo '<li class="item-current item-archive"><span class="bread-current bread-archive">' . post_type_archive_title($prefix, false) . '</span></li>';
        } else if ( is_archive() && is_tax() && !is_category() && !is_tag() ) {
            // If post is a custom post type
            $post_type = get_post_type();
            // If it is a custom post type display name and link
            if($post_type != 'post') {
                $post_type_object = get_post_type_object($post_type);
                $post_type_archive = get_post_type_archive_link($post_type);
                echo '<li class="item-cat item-custom-post-type-' . $post_type . '"><a class="bread-cat bread-custom-post-type-' . $post_type . '" href="' . $post_type_archive . '" title="' . $post_type_object->labels->name . '">' . $post_type_object->labels->name . '</a></li>';
                echo '<li class="separator"> ' . $separator . ' </li>';
            }
            $custom_tax_name = get_queried_object()->name;
            echo '<li class="item-current item-archive"><span class="bread-current bread-archive">' . $custom_tax_name . '</span></li>';
        } else if ( is_single() ) {
            // If post is a custom post type
            $post_type = get_post_type();
            // If it is a custom post type display name and link
            if($post_type != 'post') {
                $post_type_object = get_post_type_object($post_type);
                $post_type_archive = get_post_type_archive_link($post_type);
                echo '<li class="item-cat item-custom-post-type-' . $post_type . '"><a class="bread-cat bread-custom-post-type-' . $post_type . '" href="' . $post_type_archive . '" title="' . $post_type_object->labels->name . '">' . $post_type_object->labels->name . '</a></li>';
                echo '<li class="separator"> ' . $separator . ' </li>';
            }
            // Get post category info
            $category = get_the_category();
            if(!empty($category)) {
                // Get last category post is in
				if(isset($category[0])){
                $last_category = $category[0];
                // Get parent any categories and create array
                $get_cat_parents = rtrim(get_category_parents($last_category->term_id, true, ','),',');
                $cat_parents = explode(',',$get_cat_parents);
                // Loop through parent categories and store in variable $cat_display
                $cat_display = '';
                foreach($cat_parents as $parents) {
                    $cat_display .= '<li class="item-cat">'.$parents.'</li>';
                    $cat_display .= '<li class="separator"> ' . $separator . ' </li>';
                }
				}
            }
            // Check if the post is in a category
            if(!empty($last_category)) {
                echo esc_attr( $cat_display );
                echo '<li class="item-current item-' . $post->ID . '"><span class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</span></li>';
            // Else if post is in a custom taxonomy
            } else if(!empty($cat_id)) {
                echo '<li class="item-cat item-cat-' . $cat_id . ' item-cat-' . $cat_nicename . '"><a class="bread-cat bread-cat-' . $cat_id . ' bread-cat-' . $cat_nicename . '" href="' . $cat_link . '" title="' . $cat_name . '">' . $cat_name . '</a></li>';
               echo '<li class="separator"> ' . $separator . ' </li>';
                echo '<li class="item-current item-' . $post->ID . '"><span class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</span></li>';
            } else {
                echo '<li class="item-current item-' . $post->ID . '"><span class="bread-current bread-' . $post->ID . '" title="' . get_the_title() . '">' . get_the_title() . '</span></li>';
            }
        } else if ( is_category() ) {
            // Category page
            echo '<li class="item-current item-cat"><span class="bread-current bread-cat">' . single_cat_title('', false) . '</span></li>';
        } else if ( is_page() ) {
            // Standard page
            if( $post->post_parent ){
                // If child page, get parents 
                $anc = get_post_ancestors( $post->ID );
                // Get parents in the right order
                $anc = array_reverse($anc);
                // Parent page loop
                foreach ( $anc as $ancestor ) {
                    $parents .= '<li class="item-parent item-parent-' . $ancestor . '"><a class="bread-parent bread-parent-' . $ancestor . '" href="' . get_permalink($ancestor) . '" title="' . get_the_title($ancestor) . '">' . get_the_title($ancestor) . '</a></li>';

                    $parents .= '<li class="separator separator-' . $ancestor . '"> ' . $separator . ' </li>';
                }
                // Display parent pages
                echo esc_attr($parents);
                // Current page
                echo '<li class="item-current item-' . $post->ID . '"><span title="' . get_the_title() . '"> ' . get_the_title() . '</span></li>';
            } 
            else {
                // Just display current page if not parents
                echo '<li class="item-current item-' . $post->ID . '"><span class="bread-current bread-' . $post->ID . '"> ' . get_the_title() . '</span></li>';
  			}

        } else if ( is_tag() ) {
            // Tag page
            // Get tag information
            $term_id        = get_query_var('tag_id');
            $taxonomy       = 'post_tag';
            $args           = 'include=' . $term_id;
            $terms          = get_terms( $taxonomy, $args );
            $get_term_id    = $terms[0]->term_id;
            $get_term_slug  = $terms[0]->slug;
            $get_term_name  = $terms[0]->name;
            // Display the tag name
            echo '<li class="item-current item-tag-' . $get_term_id . ' item-tag-' . $get_term_slug . '"><span class="bread-current bread-tag-' . $get_term_id . ' bread-tag-' . $get_term_slug . '">' . $get_term_name . '</span></li>';
        } elseif ( is_day() ) {
            // Day archive
            // Year link
            echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link( get_the_time('Y') ) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
            echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
            // Month link
            echo '<li class="item-month item-month-' . get_the_time('m') . '"><a class="bread-month bread-month-' . get_the_time('m') . '" href="' . get_month_link( get_the_time('Y'), get_the_time('m') ) . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</a></li>';
            echo '<li class="separator separator-' . get_the_time('m') . '"> ' . $separator . ' </li>';
            // Day display
            echo '<li class="item-current item-' . get_the_time('j') . '"><span class="bread-current bread-' . get_the_time('j') . '"> ' . get_the_time('jS') . ' ' . get_the_time('M') . ' Archives</span></li>';
        } else if ( is_month() ) {
            // Month Archive
            // Year link
            echo '<li class="item-year item-year-' . get_the_time('Y') . '"><a class="bread-year bread-year-' . get_the_time('Y') . '" href="' . get_year_link( get_the_time('Y') ) . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</a></li>';
            echo '<li class="separator separator-' . get_the_time('Y') . '"> ' . $separator . ' </li>';
            // Month display
            echo '<li class="item-month item-month-' . get_the_time('m') . '"><span class="bread-month bread-month-' . get_the_time('m') . '" title="' . get_the_time('M') . '">' . get_the_time('M') . ' Archives</span></li>';
        } else if ( is_year() ) {

            // Display year archive
            echo '<li class="item-current item-current-' . get_the_time('Y') . '"><span class="bread-current bread-current-' . get_the_time('Y') . '" title="' . get_the_time('Y') . '">' . get_the_time('Y') . ' Archives</span></li>';
        } else if ( is_author() ) {
            // Auhor archive
            // Get the author information
            global $author;
            $userdata = get_userdata( $author );
            // Display author name
            echo '<li class="item-current item-current-' . $userdata->user_nicename . '"><span class="bread-current bread-current-' . $userdata->user_nicename . '" title="' . $userdata->display_name . '">' . 'Author: ' . $userdata->display_name . '</span></li>';
        } else if ( get_query_var('paged') ) {
            // Paginated archives
            echo '<li class="item-current item-current-' . get_query_var('paged') . '"><span class="bread-current bread-current-' . get_query_var('paged') . '" title="Page ' . get_query_var('paged') . '">'.esc_html__('Page' , 'menda') . ' ' . get_query_var('paged') . '</span></li>';
        } else if ( is_search() ) {
            // Search results page
            echo '<li class="item-current item-current-' . get_search_query() . '"><span class="bread-current bread-current-' . get_search_query() . '" title="Search results for: ' . get_search_query() . '">Search results for: ' . get_search_query() . '</span></li>';

        } elseif ( is_404() ) {
            // 404 page
            echo '<li>' . 'Error 404' . '</li>';
        }
        echo '</ul>';
    }
}
/**************************** BREADCRUMBS END *********************/



##########################################################################################
#                                                                                        #             
#                                menda Script And style                                   #             
#                                                                                        #             
##########################################################################################
/**
 * Enqueues scripts and styles front.
 *
 * @since menda Theme 1.0
 */
add_action( 'wp_enqueue_scripts', 'ebid_scripts' );
function ebid_scripts() {
	

	// check rtl header is enable or not
	if ( of_get_option( 'ebid_header_layout' ) == 'rtl_header' ){

		// bootstrap rtl css
        wp_enqueue_style( 'rtl_bootstrap', get_template_directory_uri() . '/css/rtl_bootstrap.css', array(), 'rtl_bootstrap' );

        // rtl css
		wp_enqueue_style( 'ebid-rtl', get_template_directory_uri() . '/rtl.css', array(), 'rtl' );
    }
    else{
		
		// Add stylesheet, used in the main bootstrap.
		wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.css', array(), 'bootstrap' );
		
		// Add stylesheet, used in the main stylesheet.
		wp_enqueue_style( 'ebid-stylesheet', get_template_directory_uri() . '/css/stylesheet.css?ver3', array(), 'ebid-stylesheet' ); 
		
		// Add stylesheet, used in the main responsive.
		wp_enqueue_style( 'ebid-responsive', get_template_directory_uri() . '/css/responsive.css', array(), 'ebid-responsive' );
    }

	// Load the Internet Explorer 7 specific stylesheet.
	wp_enqueue_style( 'bootstrap-select', get_template_directory_uri() . '/css/bootstrap-select.min.css', array(), 'bootstrap-select' );

	// Add custom fonts, used in the main stylesheet.
	wp_enqueue_style( 'ebid-fonts', ebid_fonts_url(), array(), null );
		
	// Add Genericons, used in the main stylesheet.
	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );

	// Theme stylesheet.
	wp_enqueue_style( 'ebid-style', get_stylesheet_uri() );

    // fontawesome css
    wp_enqueue_style('tmd_ebid_icon_picker_faws-4', get_parent_theme_file_uri( '/css/fontawesome-4.css' ), array(), 'all'); 


	// jquery for wordpress  
	//sticky header css  
	if ( of_get_option( 'ebid_sticky_header' ) == true ) {
		wp_enqueue_script( 'sticky', get_template_directory_uri() . '/js/sticky.js', array(), '2.1.3' );
	} 

	// ebid-list-grid-js.
	wp_enqueue_script( 'ebid-list-grid', get_template_directory_uri() . '/js/ebid-list-gride.js', array(), '2.1.3' );
	
	// jquery for wordpress  
  	wp_enqueue_script( 'bootstrap-select.min', get_template_directory_uri() . '/js/bootstrap-select.min.js', array(), '1.11.0' );

	// Load the bootstrap shiv.
	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array(), '3.7.2' );
	wp_script_add_data( 'bootstrap', 'conditional', 'lt IE 9' );
	
	// Load the html5 shiv.
	wp_enqueue_script( 'html5', get_template_directory_uri() . '/js/html5.js', array(), '' );
	wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );

	wp_enqueue_script( 'skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20160412', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	if ( is_singular() && wp_attachment_is_image() ) {
		wp_enqueue_script( 'keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20160412' );
	}

	// function scripts
	wp_enqueue_script( 'ebid-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20160412', true );
	wp_localize_script( 'ebid-script', 'screenReaderText', array(
		'expand'   => esc_html__( 'expand child menu', 'menda' ),
		'collapse' => esc_html__( 'collapse child menu', 'menda' ),
	) );
}

/**
 * Enqueues scripts and styles admin.
 *
 * @since ebid Theme 1.0
 */
add_action( 'admin_enqueue_scripts', 'tmd_ebid_admin_scripts' );
function tmd_ebid_admin_scripts(){	

	/*scripts*/
	// icon picker js
	wp_enqueue_script( 'tmd-ebid-iconpkr-js', get_parent_theme_file_uri( '/js/ebid-iconpicker.js' ), array( 'jquery' ), false, true );

	// admin ebid main script
	wp_enqueue_script( 'ebid-admin-script', get_parent_theme_file_uri( '/js/iconpicker-main.js' ), array( 'jquery' ), false, true );

	/*styles*/
	// icon picker css
	wp_enqueue_style( 'tmd_ebid_icon_picker_fas', get_parent_theme_file_uri( '/css/ebid-iconpicker.min.css' ), array(), 'all' );

	// font-awesome css
	wp_enqueue_style( 'tmd_ebid_icon_picker_faws', get_parent_theme_file_uri( '/css/fontawesome-4.css' ), array(),'all' );
}


##########################################################################################
#                                                                                        #             
#                                CLASS: Woocommerce Functions (START)                    #             
#                                                                                        #             
##########################################################################################
if ( !class_exists('ebid_wc_functions') ) {

	class ebid_wc_functions {
		
		function __construct(){

			remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
			
			// add icons on product for quick wiew wishlist and cart
			add_action('woocommerce_before_shop_loop_item_title', array($this, 'ebid_auction_icons' ), 30);
			
			// Short Filter Woocommerce Page
			add_filter('loop_shop_per_page', array($this, 'get_products_per_page') );

			// short filter tempalte
			add_action('woocommerce_before_shop_loop', array($this, 'woocommerce_products_per_page' ), 30);
			

		}
		/**
		 * auction icon
		 * @return html
		 */ 
		public function ebid_auction_icons(){
			global $product;
			if ( class_exists( 'WC_Quick_view_function' ) ) {
				?>
					<div class="d-flex bidding-icon-div">
						<div class="bidding-icon ebid-quick-view" data-id="<?php echo esc_attr($product->get_id() ); ?>"><span class="fa fa-eye"></span></div>

						<div class="bidding-icon ult-auc-add-wishlist" data-id="<?php echo esc_attr( $product->get_id() ); ?>"><span class="fa fa-heart"></span></div>
						<div class="bidding-icon"><span class="fa fa-search"></span></div>
					</div>
				<?php
			}
		}

		/**
	     * Fetch list of avaliable options
	     * @return array
	     */
		public function get_products_per_page_options(){
	    	$options = apply_filters( 'jc_products_per_page', 
	    		array(
		    		3  => 3,
		    		6  => 6,
		    		9  => 9,
		    		12 => 12,
		    		15 => 15,
	        	)
	        );
	    	return $options;
    	}

		/**
	     * Get current users preference
	     * @return int
	     */
    	public function get_products_per_page(){
        	global $woocommerce;
        	$default = 9;
        	$count   = $default;
        	$options = $this->get_products_per_page_options();

	        // capture form data and store in session
	        if(isset($_POST['jc-woocommerce-products-per-page'])){

	            // set products per page from dropdown
	            $products_max = intval($_POST['jc-woocommerce-products-per-page']);
	            if($products_max != 0 && $products_max >= -1){
	            	if(is_user_logged_in()){
	            		$user_id = get_current_user_id();
	    		    	$limit = get_user_meta( $user_id, '_product_per_page', true );
	    		    	if(!$limit){
	    		    		add_user_meta( $user_id, '_product_per_page', $products_max);
	    		    	}else{
	    		    		update_user_meta( $user_id, '_product_per_page', $products_max, $limit);
	    		    	}
	            	}
	                $woocommerce->session->jc_product_per_page = $products_max;
	                return $products_max;
	            }
	        }
	        // load product limit from user meta
	        if(is_user_logged_in() && !isset($woocommerce->session->jc_product_per_page)){
	            $user_id = get_current_user_id();
	            $limit = get_user_meta( $user_id, '_product_per_page', true );
	            if(array_key_exists($limit, $options)){
	                // $woocommerce->session->jc_product_per_page = $limit;
	                return $limit;
	            }
	        }
	        // load product limit from session
	        if(isset($woocommerce->session->jc_product_per_page)){
	            // set products per page from woo session
	            $products_max = intval($woocommerce->session->jc_product_per_page);
	            if($products_max != 0 && $products_max >= -1){
	                return $products_max;
	            }
	        }
	        return $count;
	    }

	    
	    /**
	     * Display dropdown form to change amount of products displayed
	     * @return void
	     */
	    public function woocommerce_products_per_page(){
	        $options = $this->get_products_per_page_options();
	        $current_value = $this->get_products_per_page();
	        ?>
		 		<form  method="POST" class="count-dropdown">
		 			
					<select class="number_select" name="jc-woocommerce-products-per-page" onchange="this.form.submit()">
						<?php foreach($options as $value => $name): ?>

							<option value="<?php echo esc_html($value); ?>" <?php selected($value, $current_value); ?>><?php echo esc_html($name); ?></option>

						<?php endforeach; ?>
					</select> &nbsp; &nbsp; 
				</form> 
	   		<?php
	    }
		
	}/*ebid_wc_functions class end*/

	new ebid_wc_functions;
}
##########################################################################################
#                                                                                        #             
#                                CLASS: Woocommerce Functions ( END )                    #             
#                                                                                        #             
##########################################################################################