<?php
/**
 * Best Hotel functions and definitions.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package bestel
 */
if ( ! defined( 'BESTEL_THEME_URI' ) ) {
	define( 'BESTEL_THEME_URI', get_template_directory_uri() );
}
define( 'BESTEL_THEME_DIR', get_template_directory() );
define( 'BESTEL_CSS_URL', get_template_directory_uri() . '/css' );
define( 'BESTEL_JS_URL', get_template_directory_uri() . '/js' );
define( 'BESTEL_FONTS_URL', get_template_directory_uri() . '/fonts/font-awesome/css' );
define( 'BESTEL_IMG_URL', BESTEL_THEME_URI . '/images/' );
define( 'BESTEL_FREAMWORK_DIRECTORY', BESTEL_THEME_DIR . '/framework/' );
define( 'BESTEL_INC_DIRECTORY', BESTEL_THEME_DIR . '/inc/' );
define( 'BESTEL_VC_MAP', BESTEL_THEME_DIR . '/vc_element/' );

require_once BESTEL_FREAMWORK_DIRECTORY . 'plugin-list.php';

/*
 * Enable support TGM features.
 */

require_once BESTEL_FREAMWORK_DIRECTORY . 'class-tgm-plugin-activation.php';
/*
 * Enable support TGM configuration.
 */
require_once BESTEL_FREAMWORK_DIRECTORY . 'config.tgm.php';
/*
 * Redux framework configuration
 */
require_once BESTEL_FREAMWORK_DIRECTORY . 'redux.fallback.php';
require_once BESTEL_FREAMWORK_DIRECTORY . 'redux.config.php';
require_once BESTEL_FREAMWORK_DIRECTORY . 'Bastel_Comment_Walker.php';


require_once BESTEL_FREAMWORK_DIRECTORY . '/dashboard/class-bestel-dashboard.php';

/**
 * 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
 */
if ( ! function_exists( 'bestel_content_width' ) ) :

	function bestel_content_width() {
		$GLOBALS['content_width'] = apply_filters( 'bestel_content_width', 640 );
	}

endif;

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


/*
  default config variable
 */
$fonts_areas = array(
	'bestel-body_typography',
	'bestel-heading-1-typography',
	'bestel-heading-2-typography',
	'bestel-heading-3-typography',
	'bestel-heading-4-typography',
	'bestel-heading-5-typography',
	'bestel-heading-6-typography',
	'bestel-widget_title_typography',
);

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


/*
 * plugin.php has to load to know which plugin is active
 */
require_once ABSPATH . 'wp-admin/includes/plugin.php';

/*
 * Load Menu Walker
 */
require_once BESTEL_FREAMWORK_DIRECTORY . 'nav_menu_walker.php';


if ( ! function_exists( 'BESTEL_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.
	 */
	function bestel_setup() {
		/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on Pool Services, use a find and replace
		* to change 'best_hotel' to the name of your theme in all the template files.
		*/
		load_theme_textdomain( 'bestel', get_template_directory() . '/languages' );

		add_editor_style( BESTEL_CSS_URL . '/editor-style.css' );

		// 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 Post Thumbnails on posts and pages.
		*
		* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		*/
		add_theme_support( 'post-thumbnails' );

		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'primary'     => esc_html__( 'Primary', 'bestel' ),
				'footer-menu' => esc_html__( 'Footer Menu', 'bestel' ),
			)
		);
		/*
		* Enable support for custom-background.
		*/
		$defaults = array(
			'default-image'          => '',
			'width'                  => 0,
			'height'                 => 0,
			'flex-height'            => false,
			'flex-width'             => false,
			'uploads'                => true,
			'random-default'         => false,
			'header-text'            => true,
			'default-text-color'     => '',
			'wp-head-callback'       => '',
			'admin-head-callback'    => '',
			'admin-preview-callback' => '',
		);

		add_theme_support( 'custom-header', $defaults );

		$defaults = array(
			'default-color'          => '',
			'default-image'          => '',
			'default-repeat'         => '',
			'default-position-x'     => '',
			'default-attachment'     => '',
			'wp-head-callback'       => '_custom_background_cb',
			'admin-head-callback'    => '',
			'admin-preview-callback' => '',
		);
		add_theme_support( 'custom-background', $defaults );

		/*
		* Enable support for Post Formats.
		*/
		add_theme_support(
			'post-formats',
			array(
				'aside',
				'image',
				'gallery',
				'audio',
				'video',
				'link',
				'quote',
			)
		);

		/*
		* 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',
			)
		);

		// Add support for Block Styles.
		add_theme_support( 'wp-block-styles' );

		// Add support for full and wide align images.
		add_theme_support( 'align-wide' );

		// Add support for editor styles.
		add_theme_support( 'editor-styles' );

		// Add custom editor font sizes.
		add_theme_support(
			'editor-font-sizes',
			array(
				array(
					'name'      => esc_html__( 'Small', 'bestel' ),
					'shortName' => esc_html__( 'S', 'bestel' ),
					'size'      => 19.5,
					'slug'      => 'small',
				),
				array(
					'name'      => esc_html__( 'Normal', 'bestel' ),
					'shortName' => esc_html__( 'M', 'bestel' ),
					'size'      => 22,
					'slug'      => 'normal',
				),
				array(
					'name'      => esc_html__( 'Large', 'bestel' ),
					'shortName' => esc_html__( 'L', 'bestel' ),
					'size'      => 36.5,
					'slug'      => 'large',
				),
				array(
					'name'      => esc_html__( 'Huge', 'bestel' ),
					'shortName' => esc_html__( 'XL', 'bestel' ),
					'size'      => 49.5,
					'slug'      => 'huge',
				),
			)
		);

		// Editor color palette.
		add_theme_support(
			'editor-color-palette',
			array(
				array(
					'name'  => esc_html__( 'strong yellow', 'bestel' ),
					'slug'  => 'strong-yellow',
					'color' => '#f7bd00',
				),
				array(
					'name'  => esc_html__( 'strong white', 'bestel' ),
					'slug'  => 'strong-white',
					'color' => '#fff',
				),
				array(
					'name'  => esc_html__( 'light black', 'bestel' ),
					'slug'  => 'light-black',
					'color' => '#242424',
				),
				array(
					'name'  => esc_html__( 'very light gray', 'bestel' ),
					'slug'  => 'very-light-gray',
					'color' => '#797979',
				),
				array(
					'name'  => esc_html__( 'very dark black', 'bestel' ),
					'slug'  => 'very-dark-black',
					'color' => '#000000',
				),
			)
		);
		// Add support for responsive embedded content.
		add_theme_support( 'responsive-embeds' );

		// Add custom thumb size
		set_post_thumbnail_size( 1170, 563, false );
		add_image_size( 'bestel-gallery-thumb', 370, 310 );
		add_image_size( 'bestel-rooms-thumb', 370, 239 );
		add_image_size( 'bestel-rooms-slide', 270, 169 );
		add_image_size( 'bestel-rooms-slide-2', 472, 472 );
		add_image_size( 'bestel-rooms-big', 570, 445 );
		add_image_size( 'bestel-rooms-gallery', 145, 105 );
		add_image_size( 'bestel-rooms-gallery-full', 1170, 563 );
		add_image_size( 'bestel-blog-post-grid', 372, 264 );

	}

endif;


add_action( 'after_setup_theme', 'BESTEL_setup' );

function bestel_excerpt_more( $more ) {
	 return '';
}

add_filter( 'excerpt_more', 'bestel_excerpt_more' );
/**
 * Enqueue scripts and styles.
 */

add_action( 'init', 'bastel_default_google_font' );

function bastel_default_google_font() {
	 $protocol  = is_ssl() ? 'https' : 'http';
	$subsets    = 'latin,cyrillic-ext,latin-ext,cyrillic,greek-ext,greek,vietnamese';
	$variants   = ':300,400,400i,500,500i,600,600i,700,700i,800,800i';
	$query_args = array(
		'family' => 'Open+Sans/Suravaram' . $variants,
		'family' => 'Open+Sans' . $variants . '%7CSuravaram' . $variants . '%7CCormorant+Garamond' . $variants,
		'subset' => $subsets,
	);
	$font_url   = add_query_arg( $query_args, $protocol . '://fonts.googleapis.com/css' );
	wp_enqueue_style( 'bestel-default-google-fonts', $font_url, array(), null );

}

function bastel_add_google_font() {
	 wp_enqueue_style( 'bestel-google-fonts', bastel_build_google_font(), array(), null );
}

add_action( 'wp_enqueue_scripts', 'bastel_add_google_font' );

function bastel_build_google_font() {
	$BESTEL_opt = BESTEL_options();
	global $fonts_areas;
	if ( ! class_exists( 'ReduxFrameworkPlugin' ) ) {
		$protocol   = is_ssl() ? 'https:' : 'http:';
		$subsets    = 'latin,cyrillic-ext,latin-ext,cyrillic,greek-ext,greek,vietnamese';
		$variants   = ':100,100i,200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i';
		$query_args = array(
			'family' => urlencode( 'Muli' . $variants ),
			'subset' => urlencode( $subsets ),
		);
		$font_url   = add_query_arg( $query_args, $protocol . '//fonts.googleapis.com/css' );
		return $font_url;
	}
	$font_families = array();
	foreach ( $fonts_areas as $option ) {
		if ( isset( $BESTEL_opt[ $option ]['font-family'] ) && $BESTEL_opt[ $option ]['font-family'] ) {
			$font_families[] = $BESTEL_opt[ $option ]['font-family'];
			if ( isset( $BESTEL_opt[ $option ]['subsets'] ) && $BESTEL_opt[ $option ]['subsets'] != '' ) {
				$font_subsets[] = $BESTEL_opt[ $option ]['subsets'];
			}
			if ( isset( $BESTEL_opt[ $option ]['font-weight'] ) && $BESTEL_opt[ $option ]['font-weight'] != '' ) {
				$font_variants[] = $BESTEL_opt[ $option ]['font-weight'];
			}
		}
	}
	$font_families = array_unique( $font_families );
	if ( ! empty( $font_families ) ) {
		$protocol = is_ssl() ? 'https' : 'http';
		if ( ! empty( $font_variants ) ) {
			$font_variants = array_unique( $font_variants );
			$variants      = ':' . implode( ',', $font_variants );
		} else {
			$variants = '';
		}
		if ( ! empty( $font_subsets ) ) {
			$subsets = implode( ',', $font_subsets );
		} else {
			$subsets = '';
		}
		if ( ! empty( $font_families ) ) {
			$font_families = implode( '|', $font_families );
		}
		if ( $subsets != '' ) {
			$query_args = array(
				'family' => urlencode( $font_families . $variants ),
				'subset' => urlencode( $subsets ),
			);
		} else {
			$query_args = array(
				'family' => urlencode( $font_families . $variants ),
			);
		}
		$font_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
		return $font_url;
	}
}


add_action( 'wp_enqueue_scripts', 'bestel_scripts' );


function bestel_scripts() {
	 /*
	===============================================================
	* CSS Files
	* --------------------------------------------------------------- */
	wp_enqueue_style( 'bootstrap', BESTEL_JS_URL . '/vendor/bootstrap/bootstrap.min.css', '', time() );
	wp_enqueue_style( 'animate', BESTEL_JS_URL . '/vendor/animate/animate.min.css', '', time() );
	wp_enqueue_style( 'jquery-ui', BESTEL_JS_URL . '/vendor/jquery-ui/jquery-ui.css', '', time() );
	wp_enqueue_style( 'slick', BESTEL_JS_URL . '/vendor/slick/slick.css', '', time() );
	wp_enqueue_style( 'nouislider', BESTEL_JS_URL . '/vendor/nouislider/nouislider.css', '', null );
	wp_enqueue_style( 'mCustomScrollbar', BESTEL_JS_URL . '/vendor/mCustomScrollbar/jquery.mCustomScrollbar.css', '', null );
	wp_enqueue_style( 'magnific-popup', BESTEL_JS_URL . '/vendor/magnific-popup/magnific-popup.css', '', null );

	wp_enqueue_style( 'bestel-style', get_stylesheet_uri(), '', time() );
	wp_enqueue_style( 'iconfont-style', BESTEL_THEME_URI . '/icons/style.css', '', time() );

	wp_enqueue_style( 'wp-default-style', BESTEL_CSS_URL . '/wp-default-norm.css' );
	include_once BESTEL_THEME_DIR . '/css/custom_style.php';
	$bestel_custom_inline_style = '';
	if ( function_exists( 'bestel_get_custom_styles' ) ) {
		$bestel_custom_inline_style = bestel_get_custom_styles();
	}
	wp_add_inline_style( 'bestel-style', $bestel_custom_inline_style );

	if ( bestel_get_option( 'bestel_use_predefined_color' ) ) {
		$color_css_file = bestel_get_option( 'bestel_main_color' );
		wp_enqueue_style( 'bestel-color', BESTEL_CSS_URL . '/colors/' . $color_css_file . '.css', '', null );
	} else {

		$bestel_custom_inline_style = '';
		include_once BESTEL_THEME_DIR . '/css/colors/stylecss.php';
		if ( function_exists( 'bestel_custom_primary_color' ) ) {
			$bestel_custom_primary_color = bestel_custom_primary_color();
			wp_add_inline_style( 'bestel-style', $bestel_custom_primary_color );
		}
	}

	/*
	===============================================================
	* JS Files
	* --------------------------------------------------------------- */
	// <!-- Vendors -->

	if ( class_exists( 'WooCommerce' ) ) {

		$cartUrl = get_permalink( wc_get_page_id( 'cart' ) );
	} else {
		$cartUrl = '';
	}
	wp_enqueue_script( 'jquery-ui-core' );
	wp_enqueue_script( 'jquery-ui-datepicker' );
	wp_enqueue_script( 'popper', BESTEL_JS_URL . '/vendor/popper/popper.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'mCustomScrollbar', BESTEL_JS_URL . '/vendor/mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'bootstrap', BESTEL_JS_URL . '/vendor/bootstrap/bootstrap.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'jquery-waypoints', BESTEL_JS_URL . '/vendor/waypoints/jquery.waypoints.min.js', array( 'jquery' ), time(), true );
	wp_enqueue_script( 'waypoints-sticky', BESTEL_JS_URL . '/vendor/waypoints/sticky.min.js', array( 'jquery' ), time(), true );
	wp_enqueue_script( 'trunk8', BESTEL_JS_URL . '/vendor/trunk8/trunk8.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'imagesloaded', BESTEL_JS_URL . '/vendor/imagesloaded/imagesloaded.pkgd.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'slick', BESTEL_JS_URL . '/vendor/slick/slick.min.js', array( 'jquery' ), '', true );
	// wp_enqueue_script( 'instafeed', BESTEL_JS_URL . '/vendor/instafeed/instafeed.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'instagramFeed', BESTEL_JS_URL . '/vendor/instafeed/jquery.instagramFeed.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'nouislider', BESTEL_JS_URL . '/vendor/nouislider/nouislider.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'isotope', BESTEL_JS_URL . '/vendor/isotope/isotope.pkgd.min.js', array( 'jquery', 'imagesloaded' ), '', true );
	wp_enqueue_script( 'magnific-popup', BESTEL_JS_URL . '/vendor/magnific-popup/jquery.magnific-popup.min.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'cookie', BESTEL_JS_URL . '/vendor/cookie/jquery.cookie.js', array( 'jquery' ), '', true );
	wp_enqueue_script( 'bestel-custom', BESTEL_JS_URL . '/app.js', array( 'jquery', 'jquery-ui-spinner', 'imagesloaded', 'jquery-waypoints', 'waypoints-sticky' ), time(), true );
	wp_localize_script(
		'bestel-custom',
		'bestel_js_object',
		array(
			'ajax_url'         => esc_url( admin_url( 'admin-ajax.php' ) ),
			'loader_img'       => BESTEL_IMG_URL . 'ajax-loader.gif',
			'BESTEL_IMG_URL'   => BESTEL_IMG_URL,
			'Bestel_cart_url'  => $cartUrl,
			'Bestel_cart_text' => apply_filters(
				'booking_search_page_view_cart_text',
				'View Cart'
			),
		)
	);
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}

function bestel_theme_slug_scripts_styles() {
	wp_enqueue_style( 'bestel-default-google-fonts-admin', bastel_default_google_font_admin(), array(), null );
}

add_action( 'admin_enqueue_scripts', 'bestel_theme_slug_scripts_styles' );

function bastel_default_google_font_admin() {
	$protocol   = is_ssl() ? 'https:' : 'http:';
	$query_args = array(
		'family' => urlencode( 'Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800|Suravaram|Cormorant+Garamond:400,400i,500,500i,600,600i' ),
	);
	$font_url   = add_query_arg( $query_args, $protocol . '//fonts.googleapis.com/css' );
	return $font_url;
}


function bestel_add_editor_styles() {
	add_editor_style( 'editor-style.css' );
}

add_action( 'admin_init', 'bestel_add_editor_styles' );

function bestel_block_editor_styles() {
	 wp_enqueue_style( '  bestel-block-styles', get_theme_file_uri( 'css/all-blocks.css' ), false, '1.0', 'all' );
}

add_action( 'admin_enqueue_scripts', 'bestel_block_editor_styles' );


/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
if ( ! function_exists( 'bestel_widgets_init' ) ) {

	function bestel_widgets_init() {

		register_sidebar(
			array(
				'name'          => esc_html__( 'Blog Sidebar', 'bestel' ),
				'id'            => 'blog_sideber',
				'description'   => esc_html__( 'Blog sidebar area', 'bestel' ),
				'before_widget' => '<div class="%2$s side-block widget" id="%1$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h3 class="tt-title">',
				'after_title'   => '</h3>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Contact Us', 'bestel' ),
				'id'            => 'contact_us',
				'description'   => esc_html__( 'Contact Us', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="contact-us-widget  %2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside mb-1">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Footer Our Services', 'bestel' ),
				'id'            => 'footer_our_sevices',
				'description'   => esc_html__( 'Footer Our Services', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="footer-widget4  %2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Useful Links', 'bestel' ),
				'id'            => 'footer_useful_links',
				'description'   => esc_html__( 'Footer Useful Links', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="footer-widget4  %2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Rooms Reservations', 'bestel' ),
				'id'            => 'rooms_sevices',
				'description'   => esc_html__( 'Rooms Reservations', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="%2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Hotel Services', 'bestel' ),
				'id'            => 'hotel_sevices',
				'description'   => esc_html__( 'Hotel Services', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="%2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Language', 'bestel' ),
				'id'            => 'language_sevices',
				'description'   => esc_html__( 'Select Language', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="%2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

		register_sidebar(
			array(
				'name'          => esc_html__( 'Mobile Language', 'bestel' ),
				'id'            => 'mo_language_sevices',
				'description'   => esc_html__( 'Select Language', 'bestel' ),
				'before_widget' => '<div id="%1$s" class="%2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h4 class="title-aside">',
				'after_title'   => '</h4>',
			)
		);

	}
}

add_action( 'widgets_init', 'bestel_widgets_init' );


if ( ! function_exists( 'bestel_options' ) ) :

	function bestel_options() {
		global $bestel_opt;
		return $bestel_opt;
	}

endif;

if ( ! function_exists( 'bestel_get_option' ) ) {

	function bestel_get_option( $id ) {
		global $bestel_opt;
		if ( isset( $bestel_opt[ $id ] ) ) {
			return $bestel_opt[ $id ];
		}
		return '';
	}
}
if ( ! function_exists( 'bestel_move_comment_field_to_bottom' ) ) :

	function bestel_move_comment_field_to_bottom( $fields ) {
		$comment_field = $fields['comment'];
		unset( $fields['comment'] );
		$fields['comment'] = $comment_field;
		return $fields;
	}

endif;


add_filter( 'comment_form_fields', 'bestel_move_comment_field_to_bottom' );

if ( ! function_exists( 'bestel_get_svg' ) ) :

	function bestel_get_svg( $args = array() ) {
		// Make sure $args are an array.
		if ( empty( $args ) ) {
			return __( 'Please define default parameters in the form of an array.', 'bestel' );
		}
		// Define an icon.
		if ( false === array_key_exists( 'icon', $args ) ) {
			return __( 'Please define an SVG icon filename.', 'bestel' );
		}
		// Set defaults.
		$defaults = array(
			'icon'     => '',
			'title'    => '',
			'desc'     => '',
			'fallback' => false,
		);
		// Parse args.
		$args = wp_parse_args( $args, $defaults );
		// Set aria hidden.
		$aria_hidden = ' aria-hidden="true"';
		// Set ARIA.
		$aria_labelledby = '';
		if ( $args['title'] ) {
			$aria_hidden     = '';
			$unique_id       = uniqid();
			$aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"';
			if ( $args['desc'] ) {
				$aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"';
			}
		}
		// Begin SVG markup.
		$svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">';
		// Display the title.
		if ( $args['title'] ) {
			$svg .= '<title id="title-' . $unique_id . '">' . esc_html( $args['title'] ) . '</title>';
			// Display the desc only if the title is already set.
			if ( $args['desc'] ) {
				$svg .= '<desc id="desc-' . $unique_id . '">' . esc_html( $args['desc'] ) . '</desc>';
			}
		}
		$svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> ';
		if ( $args['fallback'] ) {
			$svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>';
		}
		$svg .= '</svg>';
		return $svg;
	}

endif;

if ( ! function_exists( 'bestel_more_link' ) ) :

	function bestel_more_link( $more_link, $more_link_text ) {
		return str_replace( $more_link, '<div class="post-read-more rss"><i class="icon-information"></i><a href="' . esc_url( get_the_permalink() ) . '" class=" know_more_button">' . esc_html__( 'Know more', 'bestel' ) . '</a></div>', $more_link );
	}

endif;

add_filter( 'the_content_more_link', 'bestel_more_link', 10, 2 );

if ( ! function_exists( 'bestel_conver_Currency_To_Symble' ) ) :

	function bestel_conver_Currency_To_Symble( $currency ) {
		switch ( $currency ) {
			case '1':
				echo '$';
				break;
			case '2':
				echo '&euro;';
				break;
			case '3':
				echo '&#8369';
				break;
			case '4':
				echo 'RM';
				break;
			case '5':
				echo '&#108;&#101;&#105;';
				break;

		}
	}

endif;

if ( ! function_exists( 'bestel_limit_post_types_in_search' ) ) :

	function bestel_limit_post_types_in_search( $query ) {
		if ( $query->is_search ) {
			$query->set( 'post_type', array( 'post' ) );
		}
		return $query;
	}

endif;

add_filter( 'pre_get_posts', 'bestel_limit_post_types_in_search' );


function bestel_mime_types( $mimes ) {
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}
add_filter( 'upload_mimes', 'bestel_mime_types' );


add_action( 'init', 'bestel_remove_single_add_button' );
function bestel_remove_single_add_button() {
	if ( class_exists( 'WP_Hotel_Booking' ) ) {
		global $WP_Hotel_Booking_Room;
		remove_action( 'hotel_booking_single_room_title', array( $WP_Hotel_Booking_Room->booking, 'single_add_button' ), 9 );
		add_filter( 'hb_extra_get_template', 'bestel_plugin_override_templates', 10, 4 );
	}
}


function bestel_plugin_override_templates( $template_name, $args, $template_path, $default_path ) {
	if ( $args == 'loop/extra-search-room.php' ) {
		return BESTEL_THEME_DIR . '/wp-hotel-booking-extra/' . $args;
	} else {
		return $template_name;
	}

}
// ABR

add_action( 'woocommerce_before_checkout_form', 'bestel_show_cart_summary', 9 );

// gets the cart template and outputs it before the form
function bestel_show_cart_summary() {   ?>

<div class="checkout-page-cart-form">
	<?php
	wc_get_template_part( 'cart/cart' );
	wc_get_template_part( 'cart/cart-totals' );
	?>
</div>
	<?php
}

remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );

remove_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );


add_filter( 'woocommerce_checkout_fields', 'bestel_woocommerce_checkout_fields', 10 );
/**
 * Change Order Notes Placeholder Text - WooCommerce
 */
function bestel_woocommerce_checkout_fields( $fields ) {
	foreach ( $fields as &$fieldset ) {
		foreach ( $fieldset as &$field ) {
			$field['input_class'][] = 'form-control';
		}
	}

	unset( $fields['billing']['billing_company'] );
	unset( $fields['billing']['billing_address_2'] );

	$fields['billing']['billing_first_name']['placeholder'] = 'First name*';
	$fields['billing']['billing_last_name']['placeholder']  = 'Last name*';
	$fields['billing']['billing_address_1']['placeholder']  = 'Address*';
	$fields['billing']['billing_city']['placeholder']       = 'City*';
	$fields['billing']['billing_state']['placeholder']      = 'State*';
	$fields['billing']['billing_country']['placeholder']    = 'Country*';
	$fields['billing']['billing_postcode']['placeholder']   = 'Postal Code*';
	$fields['billing']['billing_phone']['placeholder']      = 'Phone*';
	$fields['billing']['billing_email']['placeholder']      = 'Email*';
	$fields['order']['order_comments']['placeholder']       = 'Enter your additional information';
	$fields['account']['account_password']['placeholder']   = 'Password*';
	$fields['account']['account_password']['type']          = 'password';
	$fields['account']['account_password']['label']         = 1;
	$fields['account']['account_password']['label']         = 'Password';
	$fields['account']['account_password']['required']      = 1;
	$fields['account']['account_password']['input_class'][] = 'form-control';

	return $fields;
}

// \ABR

function wp_hotel_booking_wc_plugin_activation() {
	if ( ! get_option( 'tp_hotel_booking_wc_enable' ) ) {
		update_option( 'tp_hotel_booking_wc_enable', 'yes', 'yes' );
	}
}

add_action( 'activate_wp-hotel-booking-woocommerce/wp-hotel-booking-woocommerce.php', 'wp_hotel_booking_wc_plugin_activation', 10, 2 );


function wp_hotel_booking__room_plugin_activation() {
	if ( ! get_option( 'tp_hotel_booking_enable_single_book' ) ) {
		update_option( 'tp_hotel_booking_enable_single_book', 1, 'yes' );
	}
}

add_action( 'activate_wp-hotel-booking-booking-room/wp-hotel-booking-room.php', 'wp_hotel_booking__room_plugin_activation', 10, 2 );


function wp_hotel_booking_plugin_activation() {
	if ( ! get_option( 'tp_hotel_booking_custom_process' ) ) {
		update_option( 'tp_hotel_booking_custom_process', 0, 'yes' );
	}
	if ( ! get_option( 'tp_hotel_booking_single_purchase' ) ) {
		update_option( 'tp_hotel_booking_single_purchase', 0, 'yes' );
	}
}
add_action( 'activate_wp-hotel-booking/wp-hotel-booking.php', 'wp_hotel_booking_plugin_activation', 10, 2 );


add_filter( 'hotel_booking_admin_setting_fields_room', 'hotel_booking_admin_setting_fields_room_function', 10 );
function hotel_booking_admin_setting_fields_room_function() {
	return array(
		array(
			'type'  => 'section_start',
			'id'    => 'catalog_room_setting',
			'title' => esc_html__( 'Catalog Options', 'bestel' ),
			'desc'  => esc_html__( 'Catalog settings display column number and image size used in room list ( archive page, related room ).', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_catalog_number_column',
			'type'    => 'number',
			'default' => 4,
			'title'   => esc_html__( 'Number of column display catalog page', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_posts_per_page',
			'type'    => 'number',
			'default' => 8,
			'title'   => esc_html__( 'Number of post display in page', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_catalog_image',
			'type'    => 'image_size',
			'default' => array(
				'width'  => 270,
				'height' => 270,
			),
			'options' => array(
				'width'  => 270,
				'height' => 270,
			),
			'title'   => esc_html__( 'Catalog images size', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_catalog_display_rating',
			'title'   => esc_html__( 'Display rating', 'bestel' ),
			'type'    => 'checkbox',
			'default' => 1,
		),
		array(
			'type' => 'section_end',
			'id'   => 'catalog_room_setting',
		),
		array(
			'type'  => 'section_start',
			'id'    => 'room_setting',
			'title' => esc_html__( 'Room Options', 'bestel' ),
			'desc'  => esc_html__( 'Room settings display column number and image size used in gallery single page', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_room_image_gallery',
			'type'    => 'image_size',
			'default' => array(
				'width'  => 1170,
				'height' => 563,
			),
			'options' => array(
				'width'  => 1170,
				'height' => 563,
			),
			'title'   => esc_html__( 'Room images size gallery', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_room_thumbnail',
			'type'    => 'image_size',
			'default' => array(
				'width'  => 145,
				'height' => 105,
			),
			'options' => array(
				'width'  => 145,
				'height' => 105,
			),
			'title'   => esc_html__( 'Room images thumbnail', 'bestel' ),
		),
		array(
			'id'      => 'tp_hotel_booking_display_pricing_plans',
			'title'   => esc_html__( 'Display pricing plans', 'bestel' ),
			'type'    => 'checkbox',
			'default' => 1,
		),
		array(
			'id'      => 'tp_hotel_booking_enable_review_rating',
			'title'   => esc_html__( 'Enable ratings on reviews', 'bestel' ),
			'type'    => 'checkbox',
			'default' => 1,
			'atts'    => array(
				'onchange' => "jQuery('.enable_ratings_on_reviews').toggleClass( 'hide-if-js', ! this.checked );",
			),
		),
		array(
			'id'      => 'tp_hotel_booking_review_rating_required',
			'title'   => esc_html__( 'Ratings are required to leave a review', 'bestel' ),
			'type'    => 'checkbox',
			'default' => 1,
			'trclass' => array( 'enable_ratings_on_reviews' ),
		),
		array(
			'id'      => 'tp_hotel_booking_enable_gallery_lightbox',
			'title'   => esc_html__( 'Enable gallery lightbox', 'bestel' ),
			'type'    => 'checkbox',
			'default' => 1,
		),
		array(
			'type' => 'section_end',
			'id'   => 'room_setting',
		),
	);
}


	add_filter( 'hotel_booking_admin_setting_fields_general', 'hotel_booking_admin_setting_fields_general_function', 10 );
function hotel_booking_admin_setting_fields_general_function() {
	return array(
		array(
			'type'  => 'section_start',
			'id'    => 'general_settings',
			'title' => esc_html__( 'General Options', 'bestel' ),
			'desc'  => esc_html__( 'General options for system.', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_rooms_page_id',
			'title' => esc_html__( 'Rooms Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_search_page_id',
			'title' => esc_html__( 'Search Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_checkout_page_id',
			'title' => esc_html__( 'Checkout Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_cart_page_id',
			'title' => esc_html__( 'Cart Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_account_page_id',
			'title' => esc_html__( 'Account Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_terms_page_id',
			'title' => esc_html__( 'Terms And Conditions Page', 'bestel' ),
		),
		array(
			'type'  => 'select_page',
			'id'    => 'tp_hotel_booking_thankyou_page_id',
			'title' => esc_html__( 'Thank You Page', 'bestel' ),
		),
		array(
			'type'    => 'checkbox',
			'id'      => 'tp_hotel_booking_single_purchase',
			'title'   => esc_html__( 'Single Purchase', 'bestel' ),
			'desc'    => esc_html__( 'Disable select quantity in Hotel Search page (default: one at a time)', 'bestel' ),
			'default' => 0,
		),
		array(
			'type'    => 'checkbox',
			'id'      => 'tp_hotel_booking_custom_process',
			'title'   => __( 'Custom Process', 'bestel' ),
			'desc'    => __( 'Choose extra options after select room in search page', 'bestel' ),
			'default' => 0,
		),
		array(
			'type'    => 'select',
			'id'      => 'tp_hotel_booking_currency',
			'title'   => esc_html__( 'Currency', 'bestel' ),
			'options' => hb_payment_currencies(),
			'default' => 'USD',
		),
		array(
			'type'    => 'select',
			'id'      => 'tp_hotel_booking_price_currency_position',
			'title'   => esc_html__( 'Currency Position', 'bestel' ),
			'options' => array(
				'left'             => esc_html__( 'Left ( $69.99 )', 'bestel' ),
				'right'            => esc_html__( 'Right ( 69.99$ )', 'bestel' ),
				'left_with_space'  => esc_html__( 'Left with space ( $ 69.99 )', 'bestel' ),
				'right_with_space' => esc_html__( 'Right with space ( 69.99 $ )', 'bestel' ),
			),
			'default' => 'left',
		),
		array(
			'type'    => 'text',
			'id'      => 'tp_hotel_booking_price_thousands_separator',
			'title'   => esc_html__( 'Thousands Separator', 'bestel' ),
			'default' => ',',
		),
		array(
			'type'    => 'text',
			'id'      => 'tp_hotel_booking_price_decimals_separator',
			'title'   => esc_html__( 'Decimals Separator', 'bestel' ),
			'default' => '.',
		),
		array(
			'type'    => 'number',
			'id'      => 'tp_hotel_booking_price_number_of_decimal',
			'title'   => esc_html__( 'Number of decimal', 'bestel' ),
			'default' => 1,
			'min'     => 0,
			'max'     => 3,
		),
		array(
			'type'    => 'number',
			'id'      => 'tp_hotel_booking_minimum_booking_day',
			'title'   => esc_html__( 'Minimum booking nights', 'bestel' ),
			'default' => 1,
			'min'     => 0,
			'step'    => 'any',
		),
		array(
			'type'    => 'number',
			'id'      => 'tp_hotel_booking_tax',
			'title'   => esc_html__( 'Tax', 'bestel' ),
			'default' => 10,
			'min'     => 0,
			'step'    => 'any',
		),
		array(
			'type'    => 'checkbox',
			'id'      => 'tp_hotel_booking_price_including_tax',
			'title'   => esc_html__( 'Price including tax', 'bestel' ),
			'default' => 1,
		),
		array(
			'type'    => 'select',
			'id'      => 'tp_hotel_booking_price_display',
			'title'   => esc_html__( 'Price display', 'bestel' ),
			'options' => array(
				'min'        => esc_html__( 'Min', 'bestel' ),
				'max'        => esc_html__( 'Max', 'bestel' ),
				'min_to_max' => esc_html__( 'Min to Max', 'bestel' ),
			),
			'default' => 1,
		),
		array(
			'type'    => 'number',
			'id'      => 'tp_hotel_booking_advance_payment',
			'title'   => esc_html__( 'Advance Payment', 'bestel' ),
			'desc'    => esc_html__( 'Advance payment, eg: 50%', 'bestel' ),
			'default' => 50,
			'min'     => 0,
			'max'     => 100,
		),
		array(
			'type' => 'section_end',
			'id'   => 'general_settings',
		),
	);
}


function bestel_add_query_vars_filter( $vars ) {
	$vars[] = 'header_type';
	return $vars;
}
add_filter( 'query_vars', 'bestel_add_query_vars_filter' );

function my_wp_is_mobile() {
	static $is_mobile;

	if ( isset( $is_mobile ) ) {
		return $is_mobile;
	}

	if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
		$is_mobile = false;
	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Android' ) !== false
		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Silk/' ) !== false
		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Kindle' ) !== false
		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'BlackBerry' ) !== false
		|| strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera Mini' ) !== false
	) {
		$is_mobile = true;
	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Mobile' ) !== false && strpos( $_SERVER['HTTP_USER_AGENT'], 'iPad' ) == false ) {
		$is_mobile = true;
	} elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'iPad' ) !== false ) {
		$is_mobile = false;
	} else {
		$is_mobile = false;
	}

	return $is_mobile;
}
