<?php
/**
 * vw-book-store-pro functions and definitions
 *
 * @package vw-book-store-pro
 */

if ( ! function_exists( 'vw_book_store_pro_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 post thumbnails.
 */
function vw_book_store_pro_setup() {
	$GLOBALS['content_width'] = apply_filters( 'vw_book_store_pro_content_width', 640 );
	if ( ! isset( $content_width ) ) $content_width = 640;
	load_theme_textdomain( 'vw-book-store-pro', get_template_directory() . '/languages' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'custom-header' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'wc-product-gallery-zoom' ); 
	add_theme_support( 'wc-product-gallery-lightbox' );
	add_theme_support( 'wc-product-gallery-slider' );

	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );
	add_image_size('vw-book-store-pro-homepage-thumb',240,145,true);
	register_nav_menus( array(
		'primary'   => __( 'Primary Menu', 'vw-book-store-pro' ),
		'footer1'   => __( 'Footer Menu1', 'vw-book-store-pro' ),
		'footer2'   => __( 'Footer Menu2', 'vw-book-store-pro' ),
) );
	add_theme_support( 'custom-background', array(
		'default-color' => 'f1f1f1'
	) );
	add_editor_style( array( 'assets/css/editor-style.css') );
}
endif;
add_action( 'after_setup_theme', 'vw_book_store_pro_setup' );

/* Theme Widgets Setup */
function vw_book_store_pro_widgets_init() {
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on blog page sidebar', 'vw-book-store-pro' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array(
		'name'          => __( 'Page Sidebar', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on page sidebar', 'vw-book-store-pro' ),
		'id'            => 'sidebar-2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Column 1', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on footer', 'vw-book-store-pro' ),
		'id'            => 'footer-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Column 2', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on footer', 'vw-book-store-pro' ),
		'id'            => 'footer-2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Column 3', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on footer', 'vw-book-store-pro' ),
		'id'            => 'footer-3',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Column 4', 'vw-book-store-pro' ),
		'description'   => __( 'Appears on footer', 'vw-book-store-pro' ),
		'id'            => 'footer-4',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'vw_book_store_pro_widgets_init' );

/* Theme Font URL */
function vw_book_store_pro_font_url() {
	$font_url = '';
	$font_family = array();
	$font_family[] = 'PT Sans:300,400,600,700,800,900';
	$font_family[] = 'Roboto:400,700';
	$font_family[] = 'Roboto Condensed:400,700';
	$font_family[] = 'Open Sans';
	$font_family[] = 'Overpass';
	$font_family[] = 'Montserrat:300,400,600,700,800,900';
	$font_family[] = 'Playball:300,400,600,700,800,900';
	$font_family[] = 'Alegreya:300,400,600,700,800,900';
	$font_family[] = 'Julius Sans One';
	$font_family[] = 'Arsenal';
	$font_family[] = 'Slabo';
	$font_family[] = 'Lato';
	$font_family[] = 'Overpass Mono';
	$font_family[] = 'Source Sans Pro';
	$font_family[] = 'Raleway:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
	$font_family[] = 'Merriweather';
	$font_family[] = 'Rubik';
	$font_family[] = 'Lora';
	$font_family[] = 'Ubuntu';
	$font_family[] = 'Cabin';
	$font_family[] = 'Arimo';
	$font_family[] = 'Playfair Display';
	$font_family[] = 'Quicksand';
	$font_family[] = 'Padauk';
	$font_family[] = 'Muli';
	$font_family[] = 'Inconsolata';
	$font_family[] = 'Bitter';
	$font_family[] = 'Pacifico';
	$font_family[] = 'Indie Flower';
	$font_family[] = 'VT323';
	$font_family[] = 'Dosis';
	$font_family[] = 'Frank Ruhl Libre';
	$font_family[] = 'Fjalla One';
	$font_family[] = 'Oxygen';
	$font_family[] = 'Arvo';
	$font_family[] = 'Noto Serif';
	$font_family[] = 'Lobster';
	$font_family[] = 'Crimson Text';
	$font_family[] = 'Yanone Kaffeesatz';
	$font_family[] = 'Anton';
	$font_family[] = 'Libre Baskerville';
	$font_family[] = 'Bree Serif';
	$font_family[] = 'Gloria Hallelujah';
	$font_family[] = 'Josefin Sans';
	$font_family[] = 'Abril Fatface';
	$font_family[] = 'Varela Round';
	$font_family[] = 'Vampiro One';
	$font_family[] = 'Shadows Into Light';
	$font_family[] = 'Cuprum';
	$font_family[] = 'Rokkitt';
	$font_family[] = 'Vollkorn';
	$font_family[] = 'Francois One';
	$font_family[] = 'Orbitron';
	$font_family[] = 'Patua One';
	$font_family[] = 'Acme';
	$font_family[] = 'Satisfy';
	$font_family[] = 'Josefin Slab';
	$font_family[] = 'Quattrocento Sans';
	$font_family[] = 'Architects Daughter';
	$font_family[] = 'Russo One';
	$font_family[] = 'Monda';
	$font_family[] = 'Righteous';
	$font_family[] = 'Lobster Two';
	$font_family[] = 'Hammersmith One';
	$font_family[] = 'Courgette';
	$font_family[] = 'Permanent Marker';
	$font_family[] = 'Cherry Swash';
	$font_family[] = 'Cormorant Garamond';
	$font_family[] = 'Poiret One';
	$font_family[] = 'BenchNine';
	$font_family[] = 'Economica';
	$font_family[] = 'Handlee';
	$font_family[] = 'Cardo';
	$font_family[] = 'Alfa Slab One';
	$font_family[] = 'Averia Serif Libre';
	$font_family[] = 'Cookie';
	$font_family[] = 'Chewy';
	$font_family[] = 'Great Vibes';
	$font_family[] = 'Coming Soon';
	$font_family[] = 'Philosopher';
	$font_family[] = 'Days One';
	$font_family[] = 'Kanit';
	$font_family[] = 'Shrikhand';
	$font_family[] = 'Tangerine';
	$font_family[] = 'IM Fell English SC';
	$font_family[] = 'Boogaloo';
	$font_family[] = 'Bangers';
	$font_family[] = 'Fredoka One';
	$font_family[] = 'Bad Script';
	$font_family[] = 'Volkhov';
	$font_family[] = 'Shadows Into Light Two';
	$font_family[] = 'Marck Script';
	$font_family[] = 'Sacramento';
	$font_family[] = 'Poppins';
	$font_family[] = 'PT Serif';
	$font_family[] = 'Work Sans';
	$query_args = array(
		'family'	=> urlencode(implode('|',$font_family)),
	);
	$font_url = add_query_arg($query_args,'//fonts.googleapis.com/css');
	return $font_url;
}

/* Theme enqueue scripts */
function vw_book_store_pro_scripts() {
	wp_enqueue_style( 'vw-book-store-pro-font', vw_book_store_pro_font_url(), array() );
	wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/assets/css/bootstrap.min.css' );
	wp_enqueue_style( 'vw-book-store-pro-basic-style', get_stylesheet_uri() );
	wp_style_add_data( 'vw-book-store-pro-style', 'rtl', 'replace' );

	/* Inline style sheet */
	require get_parent_theme_file_path( '/inline_style.php' );
	wp_add_inline_style( 'vw-book-store-pro-basic-style',$custom_css );

	if(is_rtl()){
	    wp_enqueue_style( 'rtl-style', get_template_directory_uri().'/rtl-style.css',true, null,'all');
	    wp_add_inline_style( 'rtl-style',$custom_css );
	    wp_enqueue_script( 'vw-book-store-pro-customscripts-rtl', get_template_directory_uri() . '/assets/js/custom-rtl.js', array('jquery'),'', true );
  	}

  	else{
	    // ---------- CSS Enqueue -----------
	    if(is_front_page() || is_home()){
	      wp_enqueue_style( 'home-page-style', get_template_directory_uri().'/assets/css/main-css/home-page.css',true, null,'all');
	      wp_add_inline_style( 'home-page-style',$custom_css );
	    }else{
	      wp_enqueue_style( 'other-page-style', get_template_directory_uri() . '/assets/css/main-css/other-pages.css',true, null,'all');
	      wp_add_inline_style( 'other-page-style',$custom_css );
	    }
	    if('post' == get_post_type() && is_home()){
	      wp_enqueue_style( 'other-page-style', get_template_directory_uri() . '/assets/css/main-css/other-pages.css',true, null,'all');
	      wp_add_inline_style( 'other-page-style',$custom_css );
	    }
	    wp_enqueue_style( 'header-footer-style', get_template_directory_uri().'/assets/css/main-css/header-footer.css',true, null,'all' );
	     wp_enqueue_style( 'vw-book-store-pro', get_template_directory_uri().'/assets/css/vw-book-store-pro.css',true, null,'all' );
	    wp_enqueue_style( 'responsive-style', get_template_directory_uri().'/assets/css/main-css/mobile-main.css',true, null,'screen and (max-width: 1200px) and (min-width: 320px)' );
	     
	    wp_add_inline_style( 'header-footer-style',$custom_css );
	    wp_add_inline_style( 'responsive-media-style',$custom_css );
  	}

  	if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
	    wp_enqueue_style( 'amp-style', get_template_directory_uri().'/assets/css/main-css/amp-style.css',true, null,'all' );
	}else{
		wp_enqueue_style( 'animation-wow', get_template_directory_uri().'/assets/css/animate.css' );
		wp_enqueue_style( 'owl-carousel-style', get_template_directory_uri().'/assets/css/owl.carousel.css' );
	}
	
	// wp_enqueue_style( 'animation-wow', get_template_directory_uri().'/assets/css/animate.css' );
	wp_enqueue_style( 'font-awesome', get_template_directory_uri().'/assets/css/fontawesome-all.min.css' );
	wp_enqueue_style( 'effect', get_template_directory_uri().'/assets/css/effect.css' );
	
	wp_enqueue_script( 'jquery', get_template_directory_uri() . '/assets/js/jquery.min.js', array('jquery'), true);
	wp_enqueue_script( 'tether', get_template_directory_uri() . '/assets/js/tether.js', array('jquery'), '',true);
	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js',array('jquery'),'',true);
	 wp_enqueue_script( 'bootstrap-notify-js', get_template_directory_uri() . '/assets/js/bootstrap-notify.min.js', array( 'bootstrap' ) );
	wp_enqueue_script( 'superfsh', get_template_directory_uri() . '/assets/js/jquery.superfish.js',array('jquery'),'',true);
	wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/assets/js/owl.carousel.js',array('jquery'),'',true);
	wp_enqueue_script( 'smooth-scroll', get_template_directory_uri() . '/assets/js/SmoothScroll.js',array('jquery'),'',true);
	 wp_register_script( 'vw-book-store-pro-customscripts', get_template_directory_uri() . '/assets/js/custom.js' );
    wp_localize_script(
      'vw-book-store-pro-customscripts',
      'vw_book_store_pro_customscripts_obj',
      array(
        'is_home' =>  ( is_home() || is_front_page() )
      )
    );
     wp_enqueue_script( 'vw-book-store-pro-customscripts' );
	wp_enqueue_script( 'vw-book-store-pro-customscripts', get_template_directory_uri() . '/assets/js/custom.js', array('jquery'),'', true );
	 wp_enqueue_script( 'animation-wow', get_template_directory_uri() . '/assets/js/wow.min.js', array( 'jquery' ) );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	wp_enqueue_style('vw-book-store-pro-ie', get_template_directory_uri().'/assets/css/ie.css', array('vw-book-store-pro-basic-style'));
	wp_style_add_data( 'vw-book-store-pro-ie', 'conditional', 'IE' );
}
add_action( 'wp_enqueue_scripts', 'vw_book_store_pro_scripts' );

/* Implement the Custom Header feature. */
require get_parent_theme_file_path( '/inc/custom-header.php' );
/* Custom template tags for this theme. */
require get_parent_theme_file_path( '/inc/template-tags.php' );
/* Customizer additions. */
require get_parent_theme_file_path( '/inc/customize/customizer.php' );

 //about us
require get_template_directory() . '/inc/widget/about-us-widget.php';
// Contact-Widgets
require get_parent_theme_file_path( 'inc/widget/contact-widget.php');
// social-widgets
require get_parent_theme_file_path( 'inc/widget/socail-widget.php');

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

require get_template_directory().'/inc/verify_theme_version.php';
/* Theme Wizard */
require get_template_directory() . '/theme-wizard/config.php';
require get_parent_theme_file_path('/theme-wizard/plugin-activation.php' );
/* URL DEFINES */
define('vw_book_store_pro_SITE_URL','https://www.vwthemes.com/');
/* Theme Credit link */
function vw_book_store_pro_credit_link() {
	echo esc_html_e(' Design & Developed by','vw-book-store-pro'). "<a href=".esc_url(vw_book_store_pro_SITE_URL)." target='_blank'> VW Themes</a>";
}
/*Radio Button sanitization*/
function vw_book_store_pro_sanitize_choices( $input, $setting ) {
	global $wp_customize;
	$control = $wp_customize->get_control( $setting->id );
	if ( array_key_exists( $input, $control->choices ) ) {
		return $input;
	} else {
		return $setting->default;
	}
}



/* Excerpt Read more overwrite */
function vw_book_store_pro_excerpt_more( $link ) {
	if ( is_admin() ) {
		return $link;
	}
	$link = sprintf( '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
		esc_url( get_permalink( get_the_ID() ) ),
		/* translators: %s: Name of current post */
		sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'vw-book-store-pro' ), get_the_title( get_the_ID() ) )
	);
	return ' &hellip; ' . $link;
}
add_filter( 'excerpt_more', 'vw_book_store_pro_excerpt_more' );

define('vw_book_store_pro_THEME_DOC','https://www.vwthemesdemo.com/docs/vw-book-store-pro/');
define('vw_book_store_pro_SUPPORT','https://www.vwthemes.com/support/vw-theme/');
define('vw_book_store_pro_FAQ','https://www.vwthemes.com/faqs/');
define('vw_book_store_pro_CONTACT','https://www.vwthemes.com/contact/');
define('vw_book_store_pro_REVIEW','https://www.vwthemes.com/topic/reviews-and-testimonials/');

define('vw_book_store_pro_banner_link','https://www.vwthemes.com/premium-plugin/vw-title-banner-plugin/');
define('vw_book_store_pro_social_media_plugin','https://www.vwthemes.com/free-plugin/vw-social-media/');
define('vw_book_store_pro_preloader_plugin','https://www.vwthemes.com/free-plugin/vw-preloader/');
define('vw_book_store_pro_accordion_plugin','https://www.vwthemes.com/free-plugin/vw-accordion/');
define('vw_book_store_pro_gallery_link','https://www.vwthemes.com/premium-plugin/vw-gallery-plugin/');
define('vw_book_store_pro_footer_link','https://www.youtube.com/watch?v=7BvTpLh-RB8');

define( 'IBTANA_THEME_LICENCE_ENDPOINT', 'https://preview.vwthemesdemo.com/old_website/wp-json/ibtana-licence/v2/' );
define( 'SHOPIFY_THEME_LICENCE_ENDPOINT', 'https://license.vwthemes.com/api/public/' );

//-------- Bundle Notice ---------
add_action( 'admin_notices', 'vw_theme_bundle_admin_notice' );
function vw_theme_bundle_admin_notice() {
       ?>
    <div class="notice bundle-notice is-dismissible">
      <div class="theme_box">
        <h3><?php echo esc_html('Thank You For Purchasing VW Book Store Pro Theme','vw-book-store-pro'); ?></h3>
        <p><?php echo esc_html('Get our all','sirat-pro'); ?>
        <strong><?php echo esc_html('120+ Premium Themes','vw-book-store-pro'); ?></strong>
        <?php echo esc_html('worth $7021 With Our','vw-book-store-pro'); ?>
        <strong><?php echo esc_html('WP Theme Bundle','vw-book-store-pro'); ?></strong>
        <?php echo esc_html('in just $89.','vw-book-store-pro'); ?></p>

      </div>
      <div class="bubdle_button">
        <a href="https://www.vwthemes.com/premium/all-themes/" class="button button-primary button-hero" target="_blank" rel="noopener"><?php echo esc_html('Get Bundle at $89','vw-book-store-pro'); ?></a>
      </div>
    </div>
   <?php
}

add_action('switch_theme', 'vw_book_store_pro_deactivate');
function vw_book_store_pro_deactivate() {
  ThemeWhizzie::remove_the_theme_key();
  ThemeWhizzie::set_the_validation_status('false');
}

define('CUSTOM_TEXT_DOMAIN', 'vw-book-store');
add_filter( 'woocommerce_add_to_cart_fragments', 'vw_book_store_pro_wc_refresh_mini_cart_count');
function vw_book_store_pro_wc_refresh_mini_cart_count( $fragments ) {
  ob_start();
  $items_count = WC()->cart->get_cart_contents_count();
  ?>
    <span class="cart-value"><?php echo $items_count ? $items_count : '0'; ?></span>
  <?php
  $fragments['.cart-value'] = ob_get_clean();
  return $fragments;
}

add_filter('loop_shop_columns', 'loop_columns', 999);
if (!function_exists('loop_columns')) {
  function loop_columns() {
    return 3; // 3 products per row
  }
}


