<?php
/**
 * chic-lifestyle functions and definitions
 *
 * @package chic-lifestyle
 */

if ( ! function_exists( 'chic_lifestyle_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 chic_lifestyle_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on chic-lifestyle, use a find and replace
		 * to change 'chic-lifestyle' to the name of your theme in all the template files
		 */
		load_theme_textdomain( 'chic-lifestyle', 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 http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
		 */
		add_theme_support( 'post-thumbnails' );


		add_theme_support( 'post-templates' );
		
		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'top' => esc_html__( 'Top Menu', 'chic-lifestyle' ),
			'primary' => esc_html__( 'Primary Menu', 'chic-lifestyle' ),
		) );

		/*
		 * 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 http://codex.wordpress.org/Post_Formats
		 */
		add_theme_support( 'custom-logo', array(
		   'height'      => 90,
		   'width'       => 400,
		   'flex-width' => true,
		));

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'chic_lifestyle_custom_background_args', array(
			'default-color' => 'ffffff',
			'default-image' => '',
		) ) );

		add_theme_support( "custom-header", array(
			'default-color' => 'ffffff',		
		) );
		
		add_editor_style() ;

		// Define Image Sizes:
		add_image_size( 'chic_lifestyle_slider', 717, 401, true );
	}	// chic_lifestyle_setup
endif; 
add_action( 'after_setup_theme', 'chic_lifestyle_setup' );




/**
 * Enqueue scripts and styles.
 */
function chic_lifestyle_scripts() {
	$font_family = get_theme_mod( 'font_family', 'Raleway' );
	$heading_font_family = get_theme_mod( 'heading_font_family', 'Raleway' );
	wp_enqueue_style( 'bootstrap', get_template_directory_uri().'/css/bootstrap.css' );	
	wp_enqueue_style( 'fontawesome', get_template_directory_uri().'/css/font-awesome.css' );
	wp_enqueue_style( 'animate', get_template_directory_uri().'/css/animate.css' );
	wp_enqueue_style( 'owl', get_template_directory_uri().'/css/owl.carousel.css' );
	wp_enqueue_style( 'chic-lifestyle-googlefonts', '//fonts.googleapis.com/css?family='. esc_attr( $font_family ) . ':200,300,400,500,600,700,800,900|' . $heading_font_family . ':200,300,400,500,600,700,800,900' );
	wp_enqueue_style( 'chic-lifestyle-style', get_stylesheet_uri() );


	if ( is_rtl() ) {
		wp_enqueue_style( 'chic-lifestyle-style', get_stylesheet_uri() );
		wp_style_add_data( 'chic-lifestyle-style', 'rtl', 'replace' );
		wp_enqueue_style( 'chic-lifestyle-css-rtl', get_template_directory_uri().'/css/bootstrap-rtl.css' );
		wp_enqueue_script( 'chic-lifestyle-js-rtl', get_template_directory_uri() . '/js/bootstrap.rtl.js', array('jquery'), '1.0.0', true );
	}
	

	wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'), '1.0.0', true );
	wp_enqueue_script( 'wow', get_template_directory_uri() . '/js/wow.js', array('jquery'), '1.0.0', true );
	wp_enqueue_script( 'owl', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), '1.0.0', true );
	wp_enqueue_script( 'chic-lifestyle-scripts', get_template_directory_uri() . '/js/script.js', array('jquery'), '1.0.0', true );


	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
}
add_action( 'wp_enqueue_scripts', 'chic_lifestyle_scripts' );





/**
 * 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 ( ! isset( $content_width ) ) $content_width = 900;
function chic_lifestyle_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'chic_lifestyle_content_width', 640 );

}
add_action( 'after_setup_theme', 'chic_lifestyle_content_width', 0 );


function chic_lifestyle_filter_front_page_template( $template ) {
    return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'chic_lifestyle_filter_front_page_template' );


/**
* Call Widget page
**/
require get_template_directory() . '/inc/widgets/widgets.php';


/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/class.php';


/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';

/**
 * Custom functions that act independently of the theme templates.
 */
require get_template_directory() . '/inc/extras.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer/customizer.php';

/**
 * Load Jetpack compatibility file.
 */
require get_template_directory() . '/inc/jetpack.php';

// Register Custom Navigation Walker
require get_template_directory() . '/inc/wp_bootstrap_navwalker.php';

/**
 * Demo Content Section
 */
require get_template_directory() . '/inc/demo-content.php';


/**
* If Kirki is not already installed, use the included version
*/
if ( ! class_exists( 'Kirki' ) ) {    
    require get_template_directory() . '/inc/kirki/kirki.php';
}


/**
 * Recommended Plugins
 */
require get_template_directory() . '/inc/tgmpa/recommended-plugins.php';


/**
 * Add theme compatibility function for woocommerce if active
*/
if( class_exists( 'woocommerce' ) ) {
    require get_template_directory() . '/inc/woocommerce-functions.php';
}


require get_template_directory() . '/inc/dynamic-css.php';


// Remove default "Category or Tags" from title
add_filter( 'get_the_archive_title', 'remove_default_tax_title');
function remove_default_tax_title( $title ) {
	if ( is_category() ) {
	        $title = single_cat_title( '', false );
	} elseif ( is_tag() ) {
	    $title = single_tag_title( '', false );
	}
	return $title;
}


// add classes for post_class function
add_filter( 'post_class', 'chic_lifestyle_sticky_classes', 10, 3 ); 
function chic_lifestyle_sticky_classes( $classes, $class, $post_id ) {   

    $classes[] = 'col-sm-12';

    return $classes;
}