<?php

$homepage = get_option( 'show_on_front');
if( $homepage == "page" ) {
	$meta = get_post_custom_values("_wp_page_template",get_option( 'page_on_front'));
	if($homepage == "page" && $meta[0] == "template-homepage.php") {$has_homepage=true;} else {$has_homepage=false;}
}
	
	
function register_my_menus() {
	if ( function_exists( 'register_nav_menus' ) ) {
		register_nav_menus(
			array( 
				'top-menu' => esc_html__('Top Menu','gadgetine-theme'),
				'main-menu' => esc_html__('Main Menu','gadgetine-theme'),
				'footer-menu' => esc_html__('Footer Menu','gadgetine-theme'),
			)
		);
	}	
}


function orange_register_sidebar($name, $id, $description){
	register_sidebar(array('name'=>$name,
		'id' => $id,
		'description' => $description,
		'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
	));
}



/* -------------------------------------------------------------------------*
 * 							DEFAULT SIDEBARS								*
 * -------------------------------------------------------------------------*/
$stickySidebar = get_option ( THEME_NAME."_sticky_sidebar" );
$orange_sidebars=array();
$orange_sidebars[] = array('name'=>esc_html__('Default Sidebar','gadgetine-theme'), 'id'=>'default','description' => esc_html__('The default page sidebar.','gadgetine-theme'));
$orange_sidebars[] = array('name'=>esc_html__('Footer Widgets','gadgetine-theme'), 'id'=>'ot_footer', 'description' => esc_html__('Footer widget area, supports up to 3 widgets.','gadgetine-theme'));	

if(function_exists('is_woocommerce')) {
	$orange_sidebars[] = array('name'=>'Woocommerce', 'id'=>'ot_woocommerce', 'description' => esc_html__('Woocommerce Page Sidebar','gadgetine-theme'));	
}
if(function_exists("is_bbpress")) {
	$orange_sidebars[] = array('name'=>'bbPress', 'id'=>'ot_bbpress', 'description' => esc_html__('bbPress Page Sidebar','gadgetine-theme'));
}
if(function_exists("is_buddypress")) {
	$orange_sidebars[] = array('name'=>'BuddyPress', 'id'=>'ot_buddypress', 'description' => esc_html__('BuddyPress Page Sidebar','gadgetine-theme'));	
}
if($stickySidebar=="on") {
	$orange_sidebars[] = array('name'=>'Sicky Sidebar', 'id'=>'sicky_sidebar', 'description' => __('Sticky sidebar under the main sidebar, that will stay fixed while you scroll down the page','gadgetine-theme'));	
}


$sidebar_strings = get_option(THEME_NAME.'_sidebar_names');
$generated_sidebars = explode("|*|", $sidebar_strings);
array_pop($generated_sidebars);
$orange_generated_sidebars=array();
	
foreach($generated_sidebars as $sidebar) {
	$orange_sidebars[]=array('name'=>$sidebar, 'id'=>convert_to_class($sidebar), 'description'=>$sidebar);
	$orange_generated_sidebars[]=array('name'=>$sidebar, 'id'=>convert_to_class($sidebar), 'description'=>$sidebar);
}
 
 /* -------------------------------------------------------------------------*
 * 							REGISTER ALL SIDEBARS
 * -------------------------------------------------------------------------*/

if (function_exists('register_sidebar')) {
	
	//register the sidebars
	foreach($orange_sidebars as $sidebar){
		orange_register_sidebar($sidebar['name'], $sidebar['id'], $sidebar['description']);
	}
	
}

add_action('init', 'register_my_menus' );
add_theme_support( 'post-thumbnails' );
add_theme_support( "title-tag" );

?>