<?php

add_action('after_setup_theme', 'sh_theme_setup');

function sh_theme_setup()
{
	
	global $wp_version;
	if(!defined('SH_VERSION')) define('SH_VERSION', '1.0');
	if( !defined( 'SH_NAME' ) ) define( 'SH_NAME', 'wp_tlazya' );
	if( !defined( 'SH_ROOT' ) ) define('SH_ROOT', get_template_directory().'/');
	if( !defined( 'SH_URL' ) ) define('SH_URL', get_template_directory_uri().'/');	
	include_once( 'includes/loader.php' );
	
	load_theme_textdomain(SH_NAME, get_template_directory() . '/languages');
	add_editor_style();
	//ADD THUMBNAIL SUPPORT
	add_theme_support('post-thumbnails');
	add_theme_support( 'post-formats', array( 'gallery', 'image', 'quote', 'video', 'audio' ) );
	add_theme_support('menus'); //Add menu support
	add_theme_support('automatic-feed-links'); //Enables post and comment RSS feed links to head.
	add_theme_support('widgets'); //Add widgets and sidebar support
	add_theme_support( "title-tag" );
	
	// Custom Header and Background
	add_theme_support('custom-header', array(
		// Header image default
		'default-image' => get_template_directory_uri().'/images/logo.png'
	));
	add_theme_support('custom-background', array(
		// Background color default
		'default-color' => '000',
		// Background image default
		'default-image' => ''
	));
    /*
     * 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 featured content.
    add_theme_support('featured-content', array(
        'featured_content_filter' => 'evential_get_featured_posts',
        'max_posts' => 6,
    ));

    // This theme uses its own gallery styles.
    add_filter('use_default_gallery_style', '__return_false');

	
	/** Register wp_nav_menus */
	if(function_exists('register_nav_menu'))
	{
		register_nav_menus(
			array(
				/** Register Main Menu location header */
				'main_menu' => esc_html__('Main Menu', SH_NAME),
			)
		);
	}
	if ( ! isset( $content_width ) ) $content_width = 960;
	add_image_size( '370x370', 370, 370, true );
	add_image_size( '800x400', 800, 400, true );

	if(sh_set(_WSH()->option(), 'compress_js_css') && !class_exists('Minit')){
		include_once 'includes/helpers/minit.php';
	}
}


function sh_widget_init()
{
	global $wp_registered_sidebars;
	$theme_options = _WSH()->option();
	//if( class_exists( 'SH_About_Us' ) )register_widget( 'SH_About_Us' );
    
	
	if( class_exists( 'SH_Contact_Info' ) ) register_widget( 'SH_Contact_Info' );
	if( class_exists( 'SH_Contact_Form' ) ) register_widget( 'SH_Contact_Form' );

	register_sidebar(array(
	  'name' => esc_html__( 'Default Sidebar', SH_NAME ),
	  'id' => 'default-sidebar',
	  'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', SH_NAME ),
	  'class'=>'',
	  'before_widget'=>'<div id="%1$s" class="widget clearfix %2$s">',
	  'after_widget'=>'</div>',
	  'before_title' => '<div class="widget-title clearfix"><h3>',
	  'after_title' => '</h3></div>'
	));

	register_sidebar(array(
	  'name' => esc_html__( 'Footer Sidebar', SH_NAME ),
	  'id' => 'footer-sidebar',
	  'description' => esc_html__( 'Widgets in this area will be shown on the footer.', SH_NAME ),
	  'class'=>'',
	  'before_widget'=>'<div id="%1$s" class="clearfix %2$s">',
	  'after_widget'=>'</div>',
	  'before_title' => '<h4>',
	  'after_title' => '</h4>'
	));
	
	if( !is_object( _WSH() )  )  return;
	$sidebars = sh_set(sh_set( $theme_options, 'dynamic_sidebar' ) , 'dynamic_sidebar' ); 
	foreach( array_filter((array)$sidebars) as $sidebar)
	{
		if(sh_set($sidebar , 'topcopy')) continue ;
		
		$name = sh_set( $sidebar, 'sidebar_name' );
		
		if( ! $name ) continue;
		$slug = sh_slug( $name ) ;
		
		register_sidebar( array(
			'name' => $name,
			'id' =>  $slug ,
		    'before_widget' => '<div class="widget">',
	        'after_widget' => "</div>",
	        'before_title' => '<div class="widget-title"><h3><span class="divider"></span>',
	        'after_title' => '</h3></div>',
		) );		
	}
	
	update_option('wp_registered_sidebars' , $wp_registered_sidebars) ;
}

add_action( 'widgets_init', 'sh_widget_init' );



if( function_exists('vc_map')) {
	vc_set_shortcodes_templates_dir( get_template_directory().'/includes/modules/shortcodes' );
	vc_disable_frontend();
	
	add_action( 'vc_before_init', '_sh_prefix_vcSetAsTheme' );
	function _sh_prefix_vcSetAsTheme() {
	    vc_set_as_theme();
	}
}
