<?php
/**
 * Maicha Blog functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package maicha_blog
 */

if ( ! function_exists( 'maicha_blog_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 maicha_blog_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Maicha Blog, use a find and replace
		 * to change 'maicha-blog' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'maicha-blog', 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' );
        add_image_size( 'blog-thumbnail', 800, 600, true);
		// This theme uses wp_nav_menu() in one location.
		register_nav_menus( array(
			'primary' => esc_html__( 'Primary Menu', 'maicha-blog' ),
		) );

		/*
		 * 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',
		) );

		// Set up the WordPress core custom background feature.
		add_theme_support( 'custom-background', apply_filters( 'maicha_blog_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_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'video', 'audio'));

        /**
		 * 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,
		) );

	}
endif;
add_action( 'after_setup_theme', 'maicha_blog_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 maicha_blog_content_width() {
	// This variable is intended to be overruled from themes.
	// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$GLOBALS['content_width'] = apply_filters( 'maicha_blog_content_width', 640 );
}
add_action( 'after_setup_theme', 'maicha_blog_content_width', 0 );

if (!function_exists('maicha_blog_fonts_url')) :
    function maicha_blog_fonts_url()
    {
        $fonts_url = '';
        $fonts = array();


        if ('off' !== _x('on', 'Cormorant font: on or off', 'maicha-blog')) {
            $fonts[] = 'Cormorant:500,600';
        }

        if ('off' !== _x('on', 'Work Sans font: on or off', 'maicha-blog')) {
            $fonts[] = 'Work Sans';
        }
        if ($fonts) {
            $fonts_url = add_query_arg(array(
                'family' => urlencode(implode('|', $fonts)),
            ), '//fonts.googleapis.com/css');
        }

        return $fonts_url;
    }
endif;

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function maicha_blog_widgets_init() {
	register_sidebar( array(
		'name'          => esc_html__( 'Default Sidebar', 'maicha-blog' ),
		'id'            => 'default-sidebar',
		'description'   => esc_html__( 'Add widgets here.', 'maicha-blog' ),
		'before_widget' => '<section id="%1$s" class="widget %2$s">',
		'after_widget'  => '</section>',
		'before_title'  => '<h2 class="widget-title">',
		'after_title'   => '</h2>',
	) );
    register_sidebar( array(
        'name'          => esc_html__( 'Maicha Blog Mid Section Sidebar', 'maicha-blog' ),
        'id'            => 'story-sidebar',
        'description'   => esc_html__( 'Add widgets here.', 'maicha-blog' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );

    for ($i = 1; $i <= 3; $i++) {
        register_sidebar(array(
            'name' => esc_html__('Maicha Blog Footer Widget', 'maicha-blog') . $i,
            'id' => 'maicha_blog_footer_' . $i,
            'description' => esc_html__('Shows widgets at Footer Widget ', 'maicha-blog') . $i,
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h4 class="widget-title">',
            'after_title' => '</h4>',
        ));
    }

}
add_action( 'widgets_init', 'maicha_blog_widgets_init' );

/**
 * Enqueue script for custom customize control.
 */
function theme_slug_custom_customize_enqueue()
{
    wp_enqueue_style('maicha-blog-customizer-style', trailingslashit(get_template_directory_uri()) . '/inc/css/customizer.css');
    wp_enqueue_script('maicha-blog-customizer-js', trailingslashit(get_template_directory_uri()) . 'inc/js/customizer.js');
}

add_action('customize_controls_enqueue_scripts', 'theme_slug_custom_customize_enqueue');



/**
 * Enqueue scripts and styles.
 */

function maicha_blog_scripts() {

	wp_enqueue_style( 'maicha-blog-style', get_stylesheet_uri() );
    wp_enqueue_style( 'maicha-blog-fonts', maicha_blog_fonts_url(), array(), null);
    wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '1.0' );
    wp_enqueue_style( 'font-awesome-css', get_template_directory_uri() . '/assets/css/font-awesome.css' , array(), '1.0' );
    wp_enqueue_style( 'slick-css', get_template_directory_uri() . '/assets/css/slick.css', array(), '1.0' );
    wp_enqueue_style( 'base-css', get_template_directory_uri() . '/assets/css/base.css', array(), '1.0' );
    wp_enqueue_style( 'maicha-blog-custom-style', get_template_directory_uri() . '/assets/css/maicha.css', array(), '1.0' );
    wp_enqueue_style( 'maicha-blog-media-queries', get_template_directory_uri() . '/assets/css/media-queries.css', array(), '1.0' );



	wp_enqueue_script( 'maicha-blog-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
	wp_enqueue_script( 'maicha-blog-bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array('jquery'), '20151215', true );
	wp_enqueue_script( 'maicha-blog-slick', get_template_directory_uri() . '/assets/js/slick.min.js', array('jquery'), '20151215', true );
    wp_enqueue_script( 'maicha-blog-anime-js', get_template_directory_uri() . '/assets/js/anime.min.js', array('jquery'), '20151215', true );
    wp_enqueue_script( 'maicha-blog-slider-js', get_template_directory_uri() . '/assets/js/animated-slider.js', array('jquery'), '20151215', true );
	wp_enqueue_script( 'maicha-blog-main', get_template_directory_uri() . '/assets/js/app.js', array('jquery'), '20151215', true );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

    $mb_theme_options = maicha_blog_theme_options();
    $header_overlay = $mb_theme_options['header_color_overlay'];
        $bgcolor = '';
        $bgcolor .= ".top-header:before{background: $header_overlay;}
        ";

    wp_add_inline_style('maicha-blog-custom-style', $bgcolor);
}
add_action( 'wp_enqueue_scripts', 'maicha_blog_scripts' );

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';
require get_template_directory() . '/inc/custom-functions.php';
require get_template_directory() . '/inc/maicha-blog-menu.php';
require get_template_directory() . '/inc/customizer-control.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';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/maicha-blog-customizer-default.php';


/**
 * This file represents an example of the code that themes would use to register
 * the required plugins.
 *
 * It is expected that theme authors would copy and paste this code into their
 * functions.php file, and amend to suit.
 *
 * @see http://tgmpluginactivation.com/configuration/ for detailed documentation.
 *
 * @package    TGM-Plugin-Activation
 * @subpackage Example
 * @version    2.6.1 for parent theme Maicha Blog for publication on WordPress.org
 * @author     Thomas Griffin, Gary Jones, Juliette Reinders Folmer
 * @copyright  Copyright (c) 2011, Thomas Griffin
 * @license    http://opensource.org/licenses/gpl-2.0.php GPL v2 or later
 * @link       https://github.com/TGMPA/TGM-Plugin-Activation
 */

/**
 * Include the TGM_Plugin_Activation class.
 *
 * Depending on your implementation, you may want to change the include call:
 *
 * Parent Theme:
 * require_once get_template_directory() . '/path/to/class-tgm-plugin-activation.php';
 *
 * Child Theme:
 * require_once get_stylesheet_directory() . '/path/to/class-tgm-plugin-activation.php';
 *
 * Plugin:
 * require_once dirname( __FILE__ ) . '/path/to/class-tgm-plugin-activation.php';
 */
require_once get_template_directory() . '/inc/class-tgm-plugin-activation.php';

add_action( 'tgmpa_register', 'maicha_blog_register_required_plugins' );

function maicha_blog_register_required_plugins() {
    /*
     * Array of plugin arrays. Required keys are name and slug.
     * If the source is NOT from the .org repo, then source is also required.
     */
    $plugins = array(


        // This is an example of how to include a plugin from the WordPress Plugin Repository.
        array(
            'name'      => 'Awesome Instagram Feed',
            'slug'      => 'awesome-instagram-feed',
            'required'  => false,
        ),


    );

    /*
     * Array of configuration settings. Amend each line as needed.
     *
     * TGMPA will start providing localized text strings soon. If you already have translations of our standard
     * strings available, please help us make TGMPA even better by giving us access to these translations or by
     * sending in a pull-request with .po file(s) with the translations.
     *
     * Only uncomment the strings in the config array if you want to customize the strings.
     */
    $config = array(
        'id'           => 'maicha-blog',                 // Unique ID for hashing notices for multiple instances of TGMPA.
        'default_path' => '',                      // Default absolute path to bundled plugins.
        'menu'         => 'tgmpa-install-plugins', // Menu slug.
        'has_notices'  => true,                    // Show admin notices or not.
        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
        'is_automatic' => false,                   // Automatically activate plugins after installation or not.
        'message'      => '',                      // Message to output right before the plugins table.

    );

    tgmpa( $plugins, $config );
}



/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}

if (!function_exists('maicha_blog_theme_options')):
    function maicha_blog_theme_options()
    {
        return wp_parse_args(get_option('maicha_blog_theme_options', array()), maicha_blog_theme_options());
    }
endif;

if (!function_exists('maicha_blog_add_editor_styles')) {
    // Add editor styles
    function maicha_blog_add_editor_styles()
    {
        add_editor_style(get_template_directory() . '/inc/customizer/css/admin/editor-styles.min.css');
    }
    add_action('init', 'maicha_blog_add_editor_styles');
}

if ( ! function_exists( 'wp_body_open' ) ) {
        function wp_body_open() {
                do_action( 'wp_body_open' );
        }
}

// function maicha_blog_header_customize_register( $wp_customize ) {
//  //All our sections, settings, and controls will be added here
//  $wp_customize->remove_section( 'header_image');

// }
// add_action( 'customize_register', 'maicha_blog_header_customize_register',50 );
