<?php
/**
 * Theme Name: 		Noisa
 * Theme Author: 	Mariusz Rek - Rascals Themes
 * Theme URI: 		http://rascalsthemes.com/noisa
 * Author URI: 		http://rascalsthemes.com
 * File:			functions.php
 * =========================================================================================================================================
 *
 * @package noisa
 * @since 1.0.0
 */


/* Set up the content width value based on the theme's design.
 -------------------------------------------------------------------------------- */
if ( ! isset( $content_width ) ) {
	$content_width = 680;
}


/* ----------------------------------------------------------------------
	THEME TRANSLATION
/* ---------------------------------------------------------------------- */

load_theme_textdomain( 'noisa', get_template_directory() . '/languages' );


/* ----------------------------------------------------------------------
	UPDATE HELPERS
/* ---------------------------------------------------------------------- */

if ( !function_exists( 'noisa_custom_admin_notice' ) ) :
function noisa_custom_admin_notice() { ?>
	
	<div class="notice notice-warning is-dismissible">
		<p><strong><?php esc_html_e( 'PLEASE NOTE: ', 'noisa' ); ?></strong><?php esc_html_e( 'Please set your customize options again because, aLL customize options are moved from "Theme Options" to "Customizer Options" (Apperance > Customize). Also please move CSS and JS codes from QUICK edit section (Theme Options) to Apperance > Customize > Additional CSS / Additional Javascript.', 'noisa' ); ?><br><a href="<?php echo admin_url( '/customize.php') ?>" class="button-primary"><?php esc_html_e( 'Customizer', 'noisa' ) ; ?></a></p>
	</div>
	
<?php }
//add_action('admin_notices', 'noisa_custom_admin_notice');
endif;

// Check if older version of plugin is activated
if ( function_exists( 'is_plugin_active' ) && ( 'rascals_noisa_plugin/rascals_noisa_plugin.php' ) ) {
	deactivate_plugins('rascals_noisa_plugin/rascals_noisa_plugin.php');
} 


/* ----------------------------------------------------------------------
	ADMIN PANEL
/* ---------------------------------------------------------------------- */

// Admin panel
require_once( trailingslashit( get_template_directory() ) . '/admin/panel-init.php' );


/* ----------------------------------------------------------------------
	THEME SETUP
/* ---------------------------------------------------------------------- */
if ( ! function_exists( 'noisa_setup' ) ) :

	/**
	 * noisa setup.
	 *
	 * Set 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 noisa_setup() {

	// This theme styles the visual editor to resemble the theme style.
	add_editor_style( get_template_directory_uri() . '/css/editor-style.css' );

	// Add RSS feed links to <head> for posts and comments.
	add_theme_support( 'automatic-feed-links' );

	// Add Title tag
	add_theme_support( 'title-tag' );

	// Enable support for Post Thumbnails, and declare two sizes.
	add_theme_support( 'post-thumbnails' );

	set_post_thumbnail_size( 780, 440, array( 'center', 'center' ) );

	add_image_size( 'noisa-release-thumb', 660, 660, array( 'center', 'center' ) );
	add_image_size( 'noisa-full-thumb', 1090, 613, array( 'center', 'center' )  );
	add_image_size( 'noisa-main-thumb', 780, 440, array( 'center', 'center' ) );
	add_image_size( 'noisa-small-thumb', 300, 300, array( 'center', 'center' ) );

	// Menu support
	add_theme_support( 'menus' );

	// This theme uses wp_nav_menu() in two locations.
	register_nav_menus( array(
		'sidebar'   => esc_html__( 'Sidebar Menu', 'noisa' ),
		'top'   => esc_html__( 'Top Menu', 'noisa' )
	) );

	/*
	 * 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( 'post-formats', array(
	 'quote', 'image', 'video', 'audio', 'gallery', 'link'
	) );

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

	// Enable support for Woocommerce
	add_theme_support( 'woocommerce' );

}

add_action( 'after_setup_theme', 'noisa_setup' );

endif; 


/* ----------------------------------------------------------------------
	REQUIRED STYLES AND SCRIPTS
/* ---------------------------------------------------------------------- */
function noisa_scripts_and_styles() {
	
	global $post, $wp_query;

	$noisa_opts = noisa_opts();

	$skin = get_theme_mod( 'noisa_skin', 'dark' );

	// Add comment reply script when applicable
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) )
		wp_enqueue_script( 'comment-reply' );
	
	/*--- Required Scripts ---*/

	// Google maps
	if ( ! is_404() && $noisa_opts->get_option( 'google_maps_key' ) && $noisa_opts->get_option( 'google_maps_key' ) !== '') {
		$map_key = '?key=' . $noisa_opts->get_option( 'google_maps_key' );
		if ( $noisa_opts->get_option( 'ajaxed' ) && $noisa_opts->get_option( 'ajaxed' ) === 'on' ) {
	  		wp_enqueue_script('js-gmaps-api','https://maps.googleapis.com/maps/api/js' . $map_key, array('jquery'), '1.0.0' );
	  		wp_enqueue_script( 'gmap', get_template_directory_uri() . '/js/jquery.gmap.min.js', false, false, true );
		} else {
			if ( get_post_meta( $wp_query->post->ID, '_intro_type', true ) === 'gmap' || has_shortcode( $post->post_content, 'google_maps' ) ) {
		  		wp_enqueue_script('js-gmaps-api','https://maps.googleapis.com/maps/api/js' . $map_key, array('jquery'), '1.0.0' );
	  			wp_enqueue_script( 'gmap', get_template_directory_uri() . '/js/jquery.gmap.min.js', false, false, true );
		  	}
		}
	}
  	// YTPlayer
  	if ( ! is_404() ) {
	  	wp_enqueue_script( 'youtubebackground', get_template_directory_uri() . '/js/jquery.youtubebackground.js', false, false, true );
  	}
  
	wp_enqueue_script( 'countdown', get_template_directory_uri() . '/js/jquery.countdown.js', false, false, true );
	wp_enqueue_script( 'TweenMax', get_template_directory_uri() . '/js/TweenMax.min.js', false, false, true ); //Tween max
	wp_enqueue_script( 'ScrollToPlugin', get_template_directory_uri() . '/js/ScrollToPlugin.min.js', false, false, true ); //ScrollToPlugin
	wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', false, false, true ); //OWL CAROUSEL
	wp_enqueue_script( 'magnific-popup', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', false, false, true ); // jQuery lightbox
	wp_enqueue_script( 'isotope', get_template_directory_uri() . '/js/jquery.isotope.min.js', false, false, true ); // jQuery masonry plugin

	// Plugins
	wp_enqueue_script( 'noisa-plugins', get_template_directory_uri() . '/js/plugins.js', false, false, true );

	// Slide sidebar
	wp_enqueue_script( 'iscroll', get_template_directory_uri() . '/js/iscroll.js', false, false, true );
	
	// Enable retina displays
	if ( $noisa_opts->get_option( 'retina' ) && $noisa_opts->get_option( 'retina' ) === 'on' ) {
		wp_enqueue_script( 'retina', get_template_directory_uri() . '/js/retina.min.js', false, false, true );
	}

	// ----------------------- WP Ajax Loader
	$ajaxed = 0;

	if ( $noisa_opts->get_option( 'ajaxed' ) && $noisa_opts->get_option( 'ajaxed' ) === 'on' ) {

		$ajaxed = 1;
		wp_enqueue_script( 'jquery.WPAjaxLoader.plugins', get_template_directory_uri() . '/js/jquery.WPAjaxLoader.plugins.js' , array( 'jquery' ), false, true);
		wp_enqueue_script( 'jquery.WPAjaxLoader', get_template_directory_uri() . '/js/jquery.WPAjaxLoader.js' , array( 'jquery' ), false, true);
	
	 	
	 	// ----------------------- Ajax Containers

		$default_ajax_containers = array(
			'#nav',
			'#responsive-nav',
			'#header-lang-selector',
			'#footer-lang-selector',
			'#site-logo',
			'#wpadminbar'
		);

		$ajax_containers = $noisa_opts->get_option( 'ajax_reload_containers' );
		$ajax_containers = preg_replace( '/\n$/','',preg_replace('/^\n/','',preg_replace('/[\r\n]+/',"\n", $ajax_containers) ) );
		$ajax_containers = str_replace("\n", ',', $ajax_containers );
	    $ajax_containers = explode( ",", $ajax_containers );
	    $ajax_containers = array_unique ( array_merge( $default_ajax_containers, $ajax_containers ) );
	    $ajax_containers = array_filter( $ajax_containers );


		// ----------------------- Ajax Scripts

		$default_ajax_scripts = array(
			'waypoints.min.js',
			'shortcodes/assets/js/shortcodes.js',
			'contact-form-7/includes/js/scripts.js',
			'/dist/skrollr.min.js',
			'js_composer_front.min.js',
			'/js/custom.js'
		);

		$ajax_scripts = $noisa_opts->get_option( 'ajax_reload_scripts' );
		$ajax_scripts = preg_replace( '/\n$/','',preg_replace('/^\n/','',preg_replace('/[\r\n]+/',"\n", $ajax_scripts) ) );
		$ajax_scripts = str_replace("\n", ',', $ajax_scripts );
	    $ajax_scripts = explode( ",", $ajax_scripts );
	    $ajax_scripts = array_unique ( array_merge( $default_ajax_scripts, $ajax_scripts ) );
	    $ajax_scripts = array_filter( $ajax_scripts );


		// ----------------------- Ajax Events

		$default_ajax_events = array(
			'YTAPIReady',
			'getVideoInfo_bgndVideo'
		);

		$ajax_events = $noisa_opts->get_option( 'ajax_events' );
		$ajax_events = preg_replace( '/\n$/','',preg_replace('/^\n/','',preg_replace('/[\r\n]+/',"\n", $ajax_events) ) );
		$ajax_events = str_replace("\n", ',', $ajax_events );
	    $ajax_events = explode( ",", $ajax_events );
	    $ajax_events = array_unique ( array_merge( $default_ajax_events, $ajax_events ) );
	    $ajax_events = array_filter( $ajax_events );
		

		// ----------------------- Ajax Elements Filter
		$default_ajax_el = array(
			'.sp-play-list.sp-add-list',
			'.sp-play-track',
			'.sp-add-track',
			'.smooth-scroll',
			'.ui-tabs-nav li a',
			'.wpb_tour_next_prev_nav span a',
			'.wpb_accordion_header a',
			'.vc_tta-tab',
			'.vc_tta-tab a',
			'.vc_pagination-trigger'
		);
		if ( class_exists( 'WooCommerce' ) ) {
			$wc_ajax_el  = array(
				'.ajax_add_to_cart',
				'.wc-tabs li a',
				'ul.tabs li a',
				'.woocommerce-review-link',
				'.woocommerce-Button.download',
				'.woocommerce-MyAccount-downloads-file'
			);
			$default_ajax_el = array_unique ( array_merge( $default_ajax_el, $wc_ajax_el ) );
		}

		$ajax_el = $noisa_opts->get_option( 'ajax_elements' );
		$ajax_el = preg_replace( '/\n$/','',preg_replace('/^\n/','',preg_replace('/[\r\n]+/',"\n", $ajax_el) ) );
		$ajax_el = str_replace("\n", ',', $ajax_el );
	    $ajax_el = explode( ",", $ajax_el );
	    $ajax_el = array_unique ( array_merge( $default_ajax_el, $ajax_el ) );
	    $ajax_el = array_filter( $ajax_el );


	    // ----------------------- Ajax Exclude Links
		$default_ajax_exclude_links = array(

		);
		if ( class_exists( 'WooCommerce' ) ) {
			$wc_ajax_exclude_links  = array();

			$wc_ajax_exclude_links[] = str_replace( home_url('/'), '', get_permalink( get_option( 'woocommerce_shop_page_id' ) ) );
			$wc_ajax_exclude_links[] = str_replace( home_url('/'), '', get_permalink( get_option( 'woocommerce_cart_page_id' ) ) );
			$wc_ajax_exclude_links[] = str_replace( home_url('/'), '', get_permalink( get_option( 'woocommerce_checkout_page_id' ) ) ); 
			$wc_ajax_exclude_links[] = str_replace( home_url('/'), '', get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ); 
			$wc_ajax_exclude_links[] = str_replace( home_url('/'), '', get_post_type_archive_link( 'product' ) );

			$permalinks = get_option( 'woocommerce_permalinks' ); 
			$wc_ajax_exclude_links[] = '?product=';
			if ( isset( $permalinks['product_base'] ) && $permalinks['product_base'] ) {
				$wc_ajax_exclude_links[] = $permalinks['product_base'];
			} else {
				$wc_ajax_exclude_links[] = '/product';
			}

			$wc_ajax_exclude_links[] = '?product_tag=';
			if ( isset( $permalinks['tag_base'] ) && $permalinks['tag_base'] ) {
				$wc_ajax_exclude_links[] = $permalinks['tag_base'];
			} else {
				$wc_ajax_exclude_links[] = '/product-tag';
			}

			$wc_ajax_exclude_links[] = '?product_cat=';
			if ( isset( $permalinks['category_base'] ) && $permalinks['category_base'] != '' ) {
				$wc_ajax_exclude_links[] = $permalinks['category_base'];
			} else {
				$wc_ajax_exclude_links[] = '/product-category';
			}

			if ( isset( $permalinks['attribute_base'] ) && $permalinks['attribute_base'] != '' ) {
				$wc_ajax_exclude_links[] = $permalinks['attribute_base'];
			} else {
				$wc_ajax_exclude_links[] = '/attribute' ;
			}

			$default_ajax_exclude_links = array_unique ( array_merge( $default_ajax_exclude_links, $wc_ajax_exclude_links ) );
		}

		$ajax_exclude_links = $noisa_opts->get_option( 'ajax_exclude_links' );
		$ajax_exclude_links = preg_replace( '/\n$/','',preg_replace('/^\n/','',preg_replace('/[\r\n]+/',"\n", $ajax_exclude_links) ) );
		$ajax_exclude_links = str_replace("\n", ',', $ajax_exclude_links );
	    $ajax_exclude_links = explode( ",", $ajax_exclude_links );
	    $ajax_exclude_links = array_unique ( array_merge( $default_ajax_exclude_links, $ajax_exclude_links ) );
	    $ajax_exclude_links = array_filter( $ajax_exclude_links );

		// Get AJAX path
		$dir = parse_url( get_option( 'home' ) );
		if ( ! isset( $dir[ 'path' ] ) ) {
			$dir[ 'path' ] = '';
		}

		// Permalinks
		$permalinks = 0;
		if ( get_option('permalink_structure') ) {
			$permalinks = 1;
		}

		$js_controls_variables = array(
			'home_url'               => esc_url( home_url('/') ),
			'theme_uri'              => get_template_directory_uri(),
			'dir'                    => esc_url( $dir[ 'path' ] ),
			'ajaxed'                 => esc_attr( $ajaxed ),
			'permalinks'             => $permalinks,
			'ajax_events'            => esc_attr( implode( ",", $ajax_events ) ),
			'ajax_elements'          => esc_attr( implode( ",", $ajax_el ) ),
			'ajax_reload_scripts'    => esc_attr( implode( ",", $ajax_scripts ) ),
			'ajax_reload_containers' => esc_attr( implode( ",", $ajax_containers ) ),
			'ajax_exclude_links'     => esc_attr( implode( "|", $ajax_exclude_links ) ),
			'ajax_async'             => esc_attr( $noisa_opts->get_option( 'ajax_async' ) ),
			'ajax_cache'             => esc_attr( $noisa_opts->get_option( 'ajax_cache' ) ),
			
		);
	} else {
		$js_controls_variables = array(
			'ajaxed'              => esc_attr( $ajaxed ),
		);
	}

	wp_enqueue_script( 'custom-controls', get_template_directory_uri() . '/js/custom.controls.js' , array( 'jquery', 'imagesloaded' ), false, true );
	wp_localize_script( 'custom-controls', 'controls_vars', $js_controls_variables );
	wp_localize_script( 'custom-controls', 'ajax_action', array('ajaxurl' => admin_url('admin-ajax.php'), 'ajax_nonce' => wp_create_nonce( 'ajax-nonce') ) );

	// ----------------------- Custom Scripts
	wp_enqueue_script( 'custom-scripts', get_template_directory_uri() . '/js/custom.js' , 'jquery', 'imagesloaded', false, true ); // Loads custom scripts

	$js_variables = array(
		'theme_uri'          => get_template_directory_uri(),
		'map_marker'         => esc_url( $noisa_opts->get_image( $noisa_opts->get_option( 'map_marker' ) ) ),
		'content_animations' => $noisa_opts->get_option( 'content_animations' ),
		'mobile_animations'  => $noisa_opts->get_option( 'mobile_animations' )
	);
	wp_localize_script( 'custom-scripts', 'theme_vars', $js_variables );

	/*--- Required Styles ---*/
	wp_enqueue_style( 'icomoon', get_stylesheet_directory_uri() . '/icons/icomoon.css' ); // Loads icons ICOMOON.
	wp_enqueue_style( 'magnific-popup', get_stylesheet_directory_uri() . '/css/magnific-popup.css' ); 
	wp_enqueue_style( 'owl-carousel', get_stylesheet_directory_uri() . '/css/owl.carousel.css' ); // Loads OWL CAROUSEL style.
	wp_enqueue_style( 'noisa-style', get_stylesheet_uri() );	// Loads the main stylesheet.

	// Skin
	if ( $skin != 'dark' ) {
		wp_enqueue_style( 'noisa-style-' . $skin, get_stylesheet_directory_uri() . '/css/theme-style-' . $skin . '.css' );	// Loads skin stylesheet.
	}

	if ( class_exists( 'WooCommerce' ) ) {
		wp_enqueue_style( 'woocommerce-theme-style', get_stylesheet_directory_uri() . '/css/woocommerce-theme-style-' . $skin . '.css' );	// Loads woocommerce stylesheet.
	}
	
}

add_action( 'wp_enqueue_scripts', 'noisa_scripts_and_styles' );



/* ----------------------------------------------------------------------
	TGM PLUGIN ACTIVATION 
/* ---------------------------------------------------------------------- */

require_once( 'inc/class-tgm-plugin-activation.php' );

add_action( 'tgmpa_register', 'noisa_register_required_plugins' );

function noisa_register_required_plugins() {
 
	/**
	 * Array of plugin arrays. Required keys are name, slug and required.
	 * If the source is NOT from the .org repo, then source is also required.
	 */
	$plugins = array(
 		
 		/**
		 * Pre-packaged Plugins
		*/
		array(
			'name'                  => esc_html__( 'Noisa Extensions', 'noisa' ), // The plugin name
			'slug'                  => 'rt-noisa-extensions', // The plugin slug (typically the folder name)
			'source'                => get_template_directory_uri() . '/plugins/rt-noisa-extensions.zip', // The plugin source
			'required'              => true, // If false, the plugin is only 'recommended' instead of required
			'version'               => '1.3.4', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
			'force_activation'      => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
			'force_deactivation'    => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
			'external_url'          => '', // If set, overrides default API URL and points to an external URL
		),
		array(
			'name'               => esc_html__( 'WPBakery Visual Composer', 'noisa' ), // The plugin name
			'slug'               => 'js_composer', // The plugin slug (typically the folder name)
			'source'             => get_template_directory_uri() . '/plugins/js_composer.zip', // The plugin source
			'required'           => true, // If false, the plugin is only 'recommended' instead of required
			'version'            => '5.5.2', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
			'force_activation'   => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
			'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
			'external_url'       => '', // If set, overrides default API URL and points to an external URL
		),
		array(
			'name'               => esc_html__( 'Slider Revolution', 'noisa' ), // The plugin name
			'slug'               => 'revslider', // The plugin slug (typically the folder name)
			'source'             => get_template_directory_uri() . '/plugins/revslider.zip', // The plugin source
			'required'           => false, // If false, the plugin is only 'recommended' instead of required
			'version'            => '5.4.8', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
			'force_activation'   => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
			'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
			'external_url'       => '', // If set, overrides default API URL and points to an external URL
		),

		/**
		 * WordPress.org Plugins
		 */
		array(
			'name'               => esc_html__( 'Contact Form 7', 'noisa' ), // The plugin name
			'slug'               => 'contact-form-7', // The plugin slug (typically the folder name)
			'required'           => false, // If false, the plugin is only 'recommended' instead of required
		),
		array(
			'name'               => esc_html__( 'MailChimp for WordPress', 'noisa' ), // The plugin name
			'slug'               => 'mailchimp-for-wp', // The plugin slug (typically the folder name)
			'required'           => false, // If false, the plugin is only 'recommended' instead of required
		),
		array(
			'name'               => esc_html__( 'WooCommerce', 'noisa' ), // The plugin name
			'slug'               => 'woocommerce', // The plugin slug (typically the folder name)
			'required'           => false, // If false, the plugin is only 'recommended' instead of required
		)
 
   );
 
	$theme_text_domain = 'noisa';
 
	$config = array(
		'domain'            => 'noisa',           // Text domain - likely want to be the same as your theme.
		'default_path'      => '',                           // Default absolute path to pre-packaged plugins
		'menu'              => 'install-required-plugins',   // Menu slug
		'has_notices'       => true,                         // Show admin notices or not
		'is_automatic'      => false,            // Automatically activate plugins after installation or not
		'message'           => ''               // Message to output right before the plugins table
	);

	tgmpa( $plugins, $config );
 
}


/* ----------------------------------------------------------------------
	VC
/* ---------------------------------------------------------------------- */

if ( function_exists( 'vc_set_as_theme' ) ) {
	vc_set_as_theme( true );
}


/* ----------------------------------------------------------------------
	REVOLUTION SLIDER
/* ---------------------------------------------------------------------- */

if  ( class_exists( 'RevSliderFront' ) ) {
	set_revslider_as_theme();
}


/* ----------------------------------------------------------------------
	WOOCOMMERCE
/* ---------------------------------------------------------------------- */

if ( class_exists( 'WooCommerce' ) ) {

	$noisa_opts = noisa_opts();

	add_theme_support( 'wc-product-gallery-zoom' );
	add_theme_support( 'wc-product-gallery-lightbox' );
	add_theme_support( 'wc-product-gallery-slider' );

	// Add body class if page is excluded
	if ( $noisa_opts->get_option( 'ajaxed' ) && $noisa_opts->get_option( 'ajaxed' ) === 'on' ) {

		if ( ! function_exists( 'wc_body_classes' ) ) {
			function wc_body_classes( $classes ) {

				if ( is_woocommerce() || is_shop() || is_product_category() || is_product_tag() || is_product() || is_cart() || is_checkout() || is_account_page() ){
					return array_merge( $classes, array( 'wp-ajax-exclude-page' ) );
				} else {
					return $classes;
				}

	    		
			}
			add_filter( 'body_class','wc_body_classes' );
		}
	}

	if ( ! function_exists( 'loop_columns' ) ) {
		function loop_columns() {

			// Shop page ID
			$shop_page_id = get_option( 'woocommerce_shop_page_id' );
			$shop_layout = get_post_meta( $shop_page_id, '_layout', true );
			if ( $shop_layout !== 'wide' && $shop_layout !== 'thin' && $shop_layout !== 'vc' ) {
	    		return 3; // 3 products per row
	    	} else {
	    		return 4;
	    	}
	   	}
	}


	add_filter( 'loop_shop_columns', 'loop_columns' );
}


/* ----------------------------------------------------------------------
	WIDGETS AND SIDEBARS
/* ---------------------------------------------------------------------- */
function noisa_widgets_init() {

	$noisa_opts = noisa_opts();

	register_sidebar( array(
		'name'          => esc_html__( 'Primary Sidebar', 'noisa' ),
		'id'            => 'primary-sidebar',
		'description'   => esc_html__( 'Main sidebar that appears on the left or right.', 'noisa' ),
		'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'          => esc_html__( 'Category Sidebar', 'noisa' ),
		'id'            => 'category-sidebar',
		'description'   => esc_html__( 'Category sidebar that appears on the left or right on category, archives, tag pages.', 'noisa' ),
		'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'          => esc_html__( 'Slide Sidebar', 'noisa' ),
		'id'            => 'slidebar-sidebar',
		'description'   => esc_html__( 'Slide sidebar that appear on the right after click on menu icon button.', 'noisa' ),
		'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'          => esc_html__( 'Footer Column 1', 'noisa' ),
		'id'            => 'footer-col1-sidebar',
		'description'   => esc_html__( 'Footer Column 1 that appear on the botton of the page.', 'noisa' ),
		'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'          => esc_html__( 'Footer Column 2', 'noisa' ),
		'id'            => 'footer-col2-sidebar',
		'description'   => esc_html__( 'Footer Column 2 that appear on the botton of the page.', 'noisa' ),
		'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'          => esc_html__( 'Footer Column 3', 'noisa' ),
		'id'            => 'footer-col3-sidebar',
		'description'   => esc_html__( 'Footer Column 3 that appear on the botton of the page.', 'noisa' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	

	// Custom sidebars
	if ( $noisa_opts->get_option( 'custom_sidebars' ) ) {
			
			foreach ( $noisa_opts->get_option( 'custom_sidebars' ) as $sidebar ) {
				
				$id = sanitize_title_with_dashes( $sidebar[ 'name' ] );
				register_sidebar( array(
					'name'          => $sidebar[ 'name' ],
					'id'            => $id,
					'description'   => esc_html__( 'Custom sidebar created in admin options.', 'noisa' ),
					'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', 'noisa_widgets_init' );



/* ----------------------------------------------------------------------
	FIXES
/* ---------------------------------------------------------------------- */



/* ----------------------------------------------------------------------
	INCLUDE NECESSARY FILES
/* ---------------------------------------------------------------------- */

// Helpers
require_once( trailingslashit( get_template_directory() ) . '/inc/helpers.php' );
require_once( trailingslashit( get_template_directory() ) . '/inc/template-tags.php' );
require_once( trailingslashit( get_template_directory() ) . '/inc/frontend.php' );

// Add Theme Customizer functionality.
require_once( trailingslashit( get_template_directory() ) . '/inc/customizer/customizer-class/kirki.php' );
require_once( trailingslashit( get_template_directory() ) . '/inc/customizer/customizer.php' );
require_once( trailingslashit( get_template_directory() ) . '/inc/customizer/customizer-options.php' );

// One Click Import
require_once( trailingslashit( get_template_directory() ) . '/inc/importer/init.php' );