<?php
/**
 * ultimate_hotel_booking functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package ultimate_hotel_booking
 */

if ( ! defined( 'ultimate_hotel_booking_VERSION' ) ) {
	// Replace the version number of the theme on each release.
	define( 'ultimate_hotel_booking_VERSION', '1.1.3' );
}

/**
 * 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 ultimate_hotel_booking_setup() {
	/*
		* Make theme available for translation.
		* Translations can be filed in the /languages/ directory.
		* If you're building a theme based on ultimate_hotel_booking, use a find and replace
		* to change 'ultimate-hotel-booking' to the name of your theme in all the template files.
		*/
	load_theme_textdomain( 'ultimate-hotel-booking', 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 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_menu' => esc_html__( 'Primary', 'ultimate-hotel-booking' ),
			'secondary_menu' => esc_html__( 'Secondary Menu', 'ultimate-hotel-booking' ),
			'footer_menu'  => esc_html__( 'Footer Menu', 'ultimate-hotel-booking' ),
		)
	);
	/*
		* 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',
			'style',
			'script',
		)
	);
	// Set up the WordPress core custom background feature.
	add_theme_support(
		'custom-background',
		apply_filters(
			'ultimate_hotel_booking_custom_background_args',
			array(
				'default-color' => 'ffffff',
				'default-image' => '',
			)
		)
	);
	// Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );
	/**
	 * Add support for core custom logo.
	 *
	 * @link https://codex.wordpress.org/Theme_Logo
	 */
	add_theme_support(
		'custom-logo',
		array(
			'height'      => 250,
			'width'       => 250,
			'flex-width'  => true,
			'flex-height' => true,
		)
	);

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

	// Add support for responsive embeds.
	add_theme_support( 'responsive-embeds' );

	// Add support for editor style
	add_editor_style( 'assets/css/editor-style.css' );

	// Add support for block style
	add_theme_support( "wp-block-styles" );
}
add_action( 'after_setup_theme', 'ultimate_hotel_booking_setup' );

/**
 * 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 ultimate_hotel_booking_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'ultimate_hotel_booking_content_width', 640 );
}
add_action( 'after_setup_theme', 'ultimate_hotel_booking_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function ultimate_hotel_booking_widgets_init() {
	register_sidebar(
		array(
			'name'          => esc_html__( 'Sidebar', 'ultimate-hotel-booking' ),
			'id'            => 'ultimate-hotel-booking-sidebar',
			'description'   => esc_html__( 'Add widgets here.', 'ultimate-hotel-booking' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="ultimate-hotel-booking-widget-title">',
			'after_title'   => '</h2>',
		)
	);

	register_sidebar(
		array(
			'name'          => esc_html__( 'Footer Widgets', 'ultimate-hotel-booking' ),
			'id'            => 'footer_sideabr',
			'description'   => esc_html__( 'Add widgets here.', 'ultimate-hotel-booking' ),
			'before_widget' => '<div id="%1$s" class="tft-footer-section %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h2 class="ultimate-hotel-booking-widget-title">',
			'after_title'   => '</h2>',
		)
	);
}
add_action( 'widgets_init', 'ultimate_hotel_booking_widgets_init' );

/**
 * Include webfont-loader
 */
require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' );

/**
 * Enqueue scripts and styles.
 */
function ultimate_hotel_booking_scripts() {
	// Enqueue Style
	wp_enqueue_style( 'ultimate-hotel-booking-google-fonts', wptt_get_webfont_url( 'https://fonts.googleapis.com/css2?family=Nunito:wght@200;300;400;500;600;700;800;900&display=swap' ), array(), ultimate_hotel_booking_VERSION, 'all' );

	wp_enqueue_style( 'ultimate-hotel-booking-style', get_stylesheet_uri(), array(), ultimate_hotel_booking_VERSION, 'all' );
	//Font Awesome Library
	wp_enqueue_style( 'ultimate-hotel-booking-font-awesome', get_template_directory_uri() . '/assets/css/all.css', array(), ultimate_hotel_booking_VERSION );
	wp_enqueue_style( 'ultimate-hotel-booking-custom-style', get_template_directory_uri() . '/assets/css/ultimate-hotel-booking-style.css', array(), ultimate_hotel_booking_VERSION );
	wp_enqueue_script( 'ultimate-hotel-booking-script', get_template_directory_uri() . '/assets/js/active.js', array('jquery'), ultimate_hotel_booking_VERSION, true );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

}
add_action( 'wp_enqueue_scripts', 'ultimate_hotel_booking_scripts', 9999999 );


function ultimate_hotel_booking_admin_scripts( $screen ) {
    wp_enqueue_style( 'ultimate-hotel-booking-style', get_template_directory_uri() . '/assets/admin/css/admin-style.css', array(), ultimate_hotel_booking_VERSION );
	wp_enqueue_script( 'ultimate-hotel-booking-script', get_template_directory_uri() . '/assets/admin/js/admin-script.js', array('jquery'), ultimate_hotel_booking_VERSION );
    wp_localize_script( 'ultimate-hotel-booking-script', 'ultimate_hotel_booking_script_params',
        array(
            'ultimate_hotel_booking_theme_nonce'   => wp_create_nonce( 'updates' ),
            'ajax_url'       => admin_url( 'admin-ajax.php' ),
            'installing'     => esc_html__( 'Installing...', 'ultimate-hotel-booking' ),
            'activating'     => esc_html__( 'Activating...', 'ultimate-hotel-booking' ),
            'installed'      => esc_html__( 'Installed', 'ultimate-hotel-booking' ),
            'activated'      => esc_html__( 'Activated', 'ultimate-hotel-booking' ),
            'install_failed' => esc_html__( 'Install failed', 'ultimate-hotel-booking' ),
            'redirect_url'   => admin_url('admin.php?page=travelfic-template-list'),
        )
    );
}
add_action( 'admin_enqueue_scripts', 'ultimate_hotel_booking_admin_scripts' );

/**
 * Fix skip link focus in IE11.
 *
 * This does not enqueue the script because it is tiny and because it is only for IE11,
 * thus it does not warrant having an entire dedicated blocking script being loaded.
 *
 * @link https://git.io/vWdr2
 */
function ultimate_hotel_booking_skip_link_focus_fix() {
	// The following is minified via `terser --compress --mangle -- js/skip-link-focus-fix.js`.
	?>
	<script>
	/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
	</script>
	<?php
}
add_action( 'wp_print_footer_scripts', 'ultimate_hotel_booking_skip_link_focus_fix' );



/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';

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

/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';

/**
 * Starter Template Notice Functions
 */
require get_template_directory() . '/inc/template-notice.php';

/**
 * ultimate_hotel_booking Typography Functions
 */
require get_template_directory() . '/inc/ultimate-hotel-booking-fonts-functions.php';

/**
 * Functions Walker Nav Menu
 */
require get_template_directory() . '/inc/class-ultimate-hotel-booking-walker-menu.php';


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

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/sanitize-functions.php';
/**
 * Meta boxes.
 */
require get_template_directory() . '/inc/meta-boxes/ultimate-hotel-booking-meta-boxes.php';

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

/**
 * Theme Functions
*/
require get_template_directory() . '/inc/ultimate-hotel-booking-functions.php';

/**
 * TGM init
*/
require get_template_directory() . '/inc/tgm/tgm-init.php';

/*
* custom Widgets
*/

require get_template_directory() . '/inc/theme-widgets/widgets/ultimate-hotel-booking-footer-info.php';
require get_template_directory() . '/inc/theme-widgets/widgets/ultimate-hotel-booking-recent-posts.php';

// ultimate_hotel_booking Header

add_filter('ultimate_hotel_booking_header', 'ultimate_hotel_booking_header_callback');
function ultimate_hotel_booking_header_callback($ultimate_hotel_booking_header){
	$ultimate_hotel_booking_prefix = 'travelfic_customizer_settings_';
    $ultimate_hotel_booking_transparentHeader = get_theme_mod($ultimate_hotel_booking_prefix.'transparent_header', 'disabled');
    $ultimate_hotel_booking_archive_transparentHeader = get_theme_mod($ultimate_hotel_booking_prefix.'archive_transparent_header', 'disabled');
    if(is_archive()  || is_single() || is_404() || is_search()){
        $ultimate_hotel_booking_transparentHeader = $ultimate_hotel_booking_archive_transparentHeader;
    }

    $ultimate_hotel_booking_banner = get_theme_mod($ultimate_hotel_booking_prefix . 'page_banner', 'banner');
    $ultimate_hotel_booking_transparent_logo = get_theme_mod($ultimate_hotel_booking_prefix . 'trasnparent_logo');
    $ultimate_hotel_booking_disable_banner = get_post_meta( get_the_ID(), 'ultimate-hotel-booking-pmb-banner', true );
    $ultimate_hotel_booking_stiky = get_theme_mod($ultimate_hotel_booking_prefix.'stiky_header', 'disabled');
    $ultimate_hotel_booking_header_bg = get_theme_mod($ultimate_hotel_booking_prefix.'header_bg_color');
    if( isset( $ultimate_hotel_booking_stiky ) ){
        if( $ultimate_hotel_booking_stiky != 'disabled' ){
            $ultimate_hotel_booking_stiky_class = 'has_stiky';
        }else{
            $ultimate_hotel_booking_stiky_class = '';
        }
    }

    if (is_page()) {
        $disable_single_page = get_post_meta( get_the_ID(), 'ultimate-hotel-booking-pmb-transfar-header', true );
        if(!empty($disable_single_page)){
            $ultimate_hotel_booking_transparentHeader = 'disabled';
        }
    }
    if (is_page('tf-search')) {
        $ultimate_hotel_booking_transparentHeader = 'disabled';
    }
	ob_start();
	?>
	<header class="tft-site-header ultimate-hotel-booking-customizer-typography <?php echo !empty($ultimate_hotel_booking_transparentHeader) && $ultimate_hotel_booking_transparentHeader == 'enabled' ? 'tft-theme-transparent-header' : ''; ?>" style="background: <?php echo $ultimate_hotel_booking_transparentHeader != 'enabled' && !empty($ultimate_hotel_booking_header_bg) ? esc_attr($ultimate_hotel_booking_header_bg) : '' ?>">
    <div class="ultimate-hotel-booking-header-inner <?php echo esc_attr( $ultimate_hotel_booking_stiky_class ); ?>">
        <div class="tft-header-desktop">
            <div class="ultimate-hotel-booking-main-header-wrapper <?php echo esc_attr( apply_filters( 'ultimate_hotel_booking_header_tftcontainer', $ultimate_hotel_booking_container = '') ); ?> ultimate-hotel-booking-container-grid align-center justify-sp-between">

                <!-- Site Branding/Logo -->
                <div class="ultimate-hotel-booking-header-left site-header-section justify-content-start">
                    <div class="site--brand-logo">
                        <?php
                        if($ultimate_hotel_booking_transparentHeader == 'enabled'){
                            if(!empty($ultimate_hotel_booking_transparent_logo)){ ?>
                            <a href="<?php echo esc_url(home_url('/')) ?>">
                                <img src="<?php echo esc_url($ultimate_hotel_booking_transparent_logo); ?>" alt="<?php _e("Logo", "ultimate-hotel-booking"); ?>">
                            </a>
                           <?php }else{ ?>
                            <div class="logo-text">
                                <a href="<?php echo esc_url(home_url('/')) ?>">
                                    <?php bloginfo('name'); ?>
                                </a>
                            </div>
                            <?php
                            }
                        }else{
                        if (has_custom_logo()) {
                            if (function_exists('the_custom_logo')) {
                                the_custom_logo();
                            }
                        } else {
                        ?>
                        <div class="logo-text">
                            <a href="<?php echo esc_url(home_url('/')) ?>">
                                <?php bloginfo('name'); ?>
                            </a>
                        </div>
                        <?php
                        } }
                        ?>
                    </div>
                </div>

                <!-- Site Navigation Menu -->
                <div class="tft-header-center site-header-section justify-content-center">
                    <nav class="tft-site-navigation">
                        <?php
                            wp_nav_menu(array(
                                'theme_location' => 'primary_menu',
                                'menu_id'        => 'navigation',
                                'container'      => 'ul',
                                'menu_class'     => 'main--header-menu tft-flex'
                            ));
                        ?>
                    </nav>
                </div>
            </div>
        </div>
        <div class="tft-header-mobile">
            <div class="ultimate-hotel-booking-main-header-wrapper <?php echo esc_attr( apply_filters( 'ultimate_hotel_booking_header_tftcontainer', $ultimate_hotel_booking_container = '') ); ?> tft-container-flexalign-center justify-sp-between">
                <!-- Site Branding/Logo -->
                <div class="ultimate-hotel-booking-header-left site-header-section">
                    <div class="site--brand-logo">
                        <?php
                        if (has_custom_logo()) {
                            the_custom_logo();
                        } else { ?>
                        <div class="logo-text">
                            <a href="<?php echo esc_url(home_url('/')) ?>">
                                <?php bloginfo('name'); ?>
                            </a>
                        </div>
                        <?php  } ?>
                    </div>
                </div>
                <!-- Site Search Bar -->
                <div class="tft-header-center site-header-section">
                    <a href="#" class="tft-mobile_menubar">
                        <div class="tft-menubar-active">
                            <i class="fas fa-bars"></i>
                        </div>
                        <div class="tft-menubar-close">
                            <i class="fas fa-times"></i>
                        </div>
                    </a>
                </div>
            </div>

            <div class="<?php echo esc_attr( apply_filters( 'ultimate_hotel_booking_header_tftcontainer', $ultimate_hotel_booking_container = '') ); ?> site-header-section tft-mobile-main-menu">
                <nav class="tft-site-navigation">
                    <?php
                    wp_nav_menu(array(
                        'theme_location' => 'primary_menu',
                        'menu_id'        => 'navigation',
                        'container' => 'ul',
                        'menu_class' => 'main--header-menu tft-flex',
                        'walker' => has_nav_menu('primary_menu') ? new Ultimate_hotel_booking_Custom_Nav_Walker() : '',
                    ));
                    ?>
                </nav>
                <a href="#" class="ultimate-hotel-booking-back-to-top"><?php echo esc_html__('Back to Top', 'ultimate-hotel-booking'); ?></a>
            </div>
        </div>
    </div>
    <?php
    if( isset( $ultimate_hotel_booking_stiky ) ){
        if( $ultimate_hotel_booking_stiky != 'disabled' ){
           ?>
           <div class="ultimate-hotel-booking-stiky-header-cover"></div>
           <?php
        }
    }
    ?>
</header>
<?php
$ultimate_hotel_booking_header_data = ob_get_clean();
return $ultimate_hotel_booking_header_data;
}

// ultimate_hotel_booking Footer

add_filter('ultimate_hotel_booking_footer', 'ultimate_hotel_booking_footer_callback');
function ultimate_hotel_booking_footer_callback($ultimate_hotel_booking_footer){
	ob_start();
?>
<footer class="ultimate-hotel-booking-site-footer ultimate-hotel-booking-customizer-typography">
    <?php if ( is_active_sidebar( 'footer_sideabr' ) ) { ?>
        <div class="ultimate-hotel-booking-footer-inner <?php echo esc_attr( apply_filters( 'ultimate_hotel_booking_footer_tftcontainer', $ultimate_hotel_booking_container = '') ); ?> ultimate-hotel-booking-container-grid tft-grid-clmn-4">
            <?php dynamic_sidebar( 'footer_sideabr' ); ?>
        </div>
    <?php } ?>

    <div class="ultimate-hotel-booking-footer-copyright">
        <div class="ultimate-hotel-booking-copyrgith-inner <?php echo esc_attr( apply_filters( 'ultimate_hotel_booking_footer_tftcontainer', $ultimate_hotel_booking_container = '') ); ?>">
            <p class="ultimate-hotel-booking-center">
            <?php
            $ultimate_hotel_booking_copyright = get_theme_mod('travelfic_customizer_settings_copyright_text', '© Copyright 2024 Tourfic Development Site by Themefic All Rights Reserved.');
                printf( esc_html__('%s', 'ultimate-hotel-booking'), $ultimate_hotel_booking_copyright);
            ?>
            </p>
        </div>
    </div>
</footer>
<?php
	$ultimate_hotel_booking_footer_data = ob_get_clean();
	return $ultimate_hotel_booking_footer_data;
}

// ultimate_hotel_booking Header ultimate-hotel-booking-container Controller

add_filter('ultimate_hotel_booking_header_tftcontainer', 'ultimate_hotel_booking_header_tftcontainer_callback');
function ultimate_hotel_booking_header_tftcontainer_callback($ultimate_hotel_booking_container){
    return 'ultimate-hotel-booking-container';
}


// ultimate_hotel_booking Footer ultimate-hotel-booking-container Controller

add_filter('ultimate_hotel_booking_footer_tftcontainer', 'ultimate_hotel_booking_footer_tftcontainer_callback');
function ultimate_hotel_booking_footer_tftcontainer_callback($ultimate_hotel_booking_container){
    return 'ultimate-hotel-booking-container';
}

// ultimate_hotel_booking Page ultimate-hotel-booking-container Controller

add_filter('ultimate_hotel_booking_page_tftcontainer', 'ultimate_hotel_booking_page_tftcontainer_callback');
function ultimate_hotel_booking_page_tftcontainer_callback($ultimate_hotel_booking_container){
    return 'ultimate-hotel-booking-container';
}
