<?php
/**
 * Igaa functions and definitions.
 */

if ( ! function_exists( 'igaa_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 */
function igaa_setup() {
	/*
	 * Make theme available for translation.
	 */
	load_theme_textdomain( 'igaa', 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 custom logo.
	 */
	add_theme_support( 'custom-logo', array(
		'height'      => 40,
		'width'       => 40,
		'flex-height' => true,
	) );

	/*
	 * Enable support for Post Thumbnails on posts and pages.
	 */
	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 1080, 9999 );
   
    // This theme uses wp_nav_menu() in one location.
	register_nav_menus( array(
		'primary' => esc_html__( 'Primary', 'igaa' ),
	) );

	/*
	 * 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.
	 */
	add_theme_support( 'post-formats', array(
		'aside',
		'image',
		'video',
		'quote',
		'link',
		'gallery',
		'status',
		'audio',
		'chat',
	) );
    
    // Add theme support for selective refresh for widgets.
	add_theme_support( 'customize-selective-refresh-widgets' );

}
endif;
add_action( 'after_setup_theme', 'igaa_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 */
function igaa_content_width() {
	$GLOBALS['content_width'] = apply_filters( 'igaa_content_width', 788 );
}
add_action( 'after_setup_theme', 'igaa_content_width', 0 );

/**
 * Register widget areas.
 */
function igaa_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Main Sidebar', 'igaa' ),
		'id'            => 'main-sidebar',
		'description'   => esc_html__( 'Add widgets here.', 'igaa' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s uk-panel uk-margin-large-bottom">',
		'after_widget'  => '</section>',
		'before_title'  => '<h4 class="widget-title uk-text-center-small">',
		'after_title'   => '</h4><hr class="uk-width-small-1-1">',
	) );
    register_sidebar( array(
		'name'          => esc_html__( 'Footer Sidebar', 'igaa' ),
		'id'            => 'footer-sidebar',
		'description'   => esc_html__( 'Add footer widgets here.', 'igaa' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s uk-width-medium-1-4 uk-panel uk-margin-large-bottom">',
		'after_widget'  => '</section>',
		'before_title'  => '<h4 class="widget-title uk-text-center-small">',
		'after_title'   => '</h4><hr class="uk-width-small-1-1">',
	) );
}
add_action( 'widgets_init', 'igaa_widgets_init' );

/**
 * Register Google Fonts.
 */
function igaa_fonts_url() {
$fonts_url = '';
 
/* Translators: If there are characters in your language that are not
 * supported by Source Sans Pro, translate this to 'off'. Do not translate
 * into your own language.
 */
$source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'igaa' );

/* Translators: If there are characters in your language that are not
 * supported by Roboto, translate this to 'off'. Do not translate
 * into your own language.
 */
$roboto = _x( 'on', 'Roboto font: on or off', 'igaa' );
    
if ( 'off' !== $source_sans_pro || 'off' !== $roboto ) {
$font_families = array();
 
if ( 'off' !== $source_sans_pro ) {
$font_families[] = 'Source Sans Pro:400,600,700,900';
}

if ( 'off' !== $roboto ) {
$font_families[] = 'Roboto:300,400';
}
 
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
 
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
 
return esc_url_raw( $fonts_url );
}

/**
 * Add editor styles
 */
function igaa_editor_styles() {
add_editor_style( array( 'css/editor-style.css', igaa_fonts_url() ) );
}
add_action( 'after_setup_theme', 'igaa_editor_styles' );

/**
 * Enqueue scripts and styles.
 */
function igaa_scripts() {
    
    if ( is_rtl() ) {
        wp_enqueue_style( 'igaa-uikit-rtl', get_template_directory_uri() . '/css/uikit-rtl-min.css' );
    } else {
        wp_enqueue_style( 'igaa-uikit', get_template_directory_uri() . '/css/uikit.min.css' );
    }
    
    wp_enqueue_style( 'igaa-fonts', igaa_fonts_url(), array(), null );
	
	wp_enqueue_style( 'igaa-style', get_stylesheet_uri() );
    
    wp_enqueue_script( 'igaa-uikitjs', get_template_directory_uri() . '/js/uikit.min.js', array( 'jquery' ), '20160526', true );
    
    wp_enqueue_script( 'igaa-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
    
    if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

}
add_action( 'wp_enqueue_scripts', 'igaa_scripts' );

/**
 * Include the TGM_Plugin_Activation class.
 */
require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php';

/**
 * Register the third party plugins. 
 */
require get_template_directory() . '/inc/igaa-tgmpa.php';

/**
 * Custom menu nav walker.
 */
require get_template_directory() . '/inc/nav-walker.php';

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

/**
 * All custom theme specific functions.
 */
require get_template_directory() . '/inc/igaa-functions.php';

/**
 * Load wrapper class for Kirki
 */
require get_template_directory() . '/inc/igaa-kirki.php';

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

// Disable Layer Slider auto-updates
add_action('layerslider_ready', 'igaa_layerslider_overrides');
function igaa_layerslider_overrides() {
    
    $GLOBALS['lsAutoUpdateBox'] = false;
}