<?php
/*
 * Sets up the theme customizer options
 *
 * @package 		WordPress
 * @subpackage 		Preference
 * @version  		Release: 1.0.5
 */
 
// Lets create a customizable theme 
add_action('after_setup_theme','themedemo_setup');
function themedemo_setup() {
	add_theme_support( 'custom-background', array(
		'default-color' => 'DADDDF',
		'default-image' => get_template_directory_uri() . '/images/patterns/pattern-bg.png',
	) );
}


add_action('customize_register', 'themedemo_customize');
function themedemo_customize($wp_customize) {

// Lets remove the Display Header Text setting and control
$wp_customize->remove_setting( 'display_header_text');
$wp_customize->remove_control( 'display_header_text');

$wp_customize->remove_setting( 'background_color');
$wp_customize->remove_control( 'background_color');

/**
 * Lets begin adding our own settings and controls for this theme
 * Plus organize it in sequence in each setting group with a priority level
 */
	$wp_customize->add_setting( 'logo_style', array(
		'default' => 'text',
		'sanitize_callback' => 'preference_lite_sanitize_logo_style',
	) );

// Setting group for selecting logo title	
	$wp_customize->add_control( 'logo_style', array(
    'label'   => __( 'Logo Style', 'preference-lite' ),
    'section' => 'title_tagline',
	'priority' => 1,
    'type'    => 'radio',
        'choices' => array(
            'default' => __( 'Default Logo', 'preference-lite' ),
            'custom' => __( 'Your Logo', 'preference-lite' ),
            'text' => __( 'Text Title', 'preference-lite' ),
        ),
    ));
	
// Setting group for uploading logo
    $wp_customize->add_setting('my_logo', array(
        'default'           => '',
        'capability'        => 'edit_theme_options',
        'type'           => 'option',
		'sanitize_callback' => 'preference_lite_sanitize_upload',

    ));

    $wp_customize->add_control( new WP_Customize_Image_Control($wp_customize, 'my_logo', array(
        'label'    => __('Your Logo', 'preference-lite'),
        'section'  => 'title_tagline',
        'settings' => 'my_logo',
		'priority' => 2,
    )));
// Site Title
	$wp_customize->add_setting( 'sitetitle', array(
		'default'        => '#4c5d64',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sitetitle', array(
		'label'   => __( 'Site Title Colour', 'preference-lite' ),
		'section' => 'title_tagline',
		'settings'   => 'sitetitle',
		'priority' => 3,
	) ) );
// Site Tagline
	$wp_customize->add_setting( 'sitetagline', array(
		'default'        => '#8b8b8b',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sitetagline', array(
		'label'   => __( 'Site Tagline', 'preference-lite' ),
		'section' => 'title_tagline',
		'settings'   => 'sitetagline',
		'priority' => 4,
	) ) );		
		
// Lets add a section tab called BASIC SETTINGS
	$wp_customize->add_section( 'basic_settings', array(
		'title'          => __( 'Basic Settings', 'preference-lite' ),
		'priority'       => 25,
	) );	

// Setting group for a Copyright
	$wp_customize->add_setting( 'copyright', array(
		'default'        => 'Your Name Here',
		'sanitize_callback' => 'preference_lite_sanitize_text',
	) );

	$wp_customize->add_control( 'copyright', array(
		'settings' => 'copyright',
		'label'    => __( 'Your Copyright Notice', 'preference-lite' ),
		'section'  => 'basic_settings',
		'type'     => 'text',
	) );


/**
 * Header image section
 */
	
// showcase background colour
	$wp_customize->add_setting( 'showcase_bg_colour', array(
		'default'        => '#B9CADC',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'showcase_bg_colour', array(
		'label'   => __( 'Showcase Background Colour', 'preference-lite' ),
		'section' => 'header_image',
		'settings'   => 'showcase_bg_colour',
		'priority' => '1',
	) ) );
	
// lets set a showcase background image	
	$wp_customize->add_setting( 'showcase_bg', array(
		'default'        => 'Background 1',
	) );	
	$wp_customize->add_control( 'showcase_bg', array(
    'label'   => 'Showcase Background',
    'section' => 'header_image',
    'type'    => 'select',
	'priority' => '2',
    'choices'    => array(
        'showcase-bg1.jpg' => __( 'Background 1', 'preference-lite' ),
        'showcase-bg2.jpg' => __( 'Background 2', 'preference-lite' ),
        'showcase-bg3.jpg' => __( 'Background 3', 'preference-lite' ),
		'showcase-bg4.jpg' => __( 'Background 4', 'preference-lite' ),
		'showcase-bg5.jpg' => __( 'Background 5', 'preference-lite' ),
		'showcase-bg6.jpg' => __( 'Background 6', 'preference-lite' ),
		'showcase-bg7.jpg' => __( 'Background 7', 'preference-lite' ),
		'showcase-bg0.png' => __( 'None', 'preference-lite' ),
        ),
	) );

// Showcase bottom line
	$wp_customize->add_setting( 'showcase_botline', array(
	'default'        => '#B2C1CC',
	'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'showcase_botline', array(
		'label'   => __( 'Showcase Bottom Line', 'preference-lite' ),
		'section' => 'header_image',
		'settings'   => 'showcase_botline',
		'priority' => '3',
	) ) );

// Showcase footer background bar
	$wp_customize->add_setting( 'showcase_footerbar', array(
	'default'        => '#B9CBD8',
	'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'showcase_footerbar', array(
		'label'   => __( 'Showcase Footer Bar', 'preference-lite' ),
		'section' => 'header_image',
		'settings'   => 'showcase_footerbar',
		'priority' => '4',
	) ) );

// Showcase footer line
	$wp_customize->add_setting( 'showcase_footerline', array(
	'default'        => '#D7DFE6',
	'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'showcase_footerline', array(
		'label'   => __( 'Showcase Footer Line', 'preference-lite' ),
		'section' => 'header_image',
		'settings'   => 'showcase_footerline',
		'priority' => '5',
	) ) );
	
// Lets set a padding for the showcase area so that we can see the background around any image or slider we add
	$wp_customize->add_setting( 'showcase_bg_padding', array(
		'default'        => '10px 0px',
		'sanitize_callback' => 'preference_lite_sanitize_text',
	) );

	$wp_customize->add_control( 'showcase_bg_padding', array(
		'label'   => __( 'Showcase Background Padding', 'preference-lite' ),
		'section' => 'header_image',
		'settings'   => 'showcase_bg_padding',
		'type'     => 'text',
	) );


/**
 * Colour Section
 * Lets add some colours to our theme
 */
 
// Page top border
 	$wp_customize->add_setting( 'page_top_border', array(
		'default'        => '#595A67',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_top_border', array(
		'label'   => __( 'Page Top Border', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'page_top_border',
		'priority' => 1,
	) ) );
	
// Top page half background colour
	$wp_customize->add_setting( 'tophalf_bg', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'tophalf_bg', array(
		'label'   => __( 'Top Half Page Background', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'tophalf_bg',
		'priority' => 2,
	) ) );
// Top page half bottom line
	$wp_customize->add_setting( 'tophalf_botline', array(
		'default'        => '#BCBCBC',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'tophalf_botline', array(
		'label'   => __( 'Top Half Bottom Line', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'tophalf_botline',
		'priority' => 3,
	) ) );



// Main Content background colour
	$wp_customize->add_setting( 'content_bg', array(
		'default'        => '#F8F8F8',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'content_bg', array(
		'label'   => __( 'Main Content Background', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'content_bg',
		'priority' => 4,
	) ) );

// Main Content bottom line
	$wp_customize->add_setting( 'content_botline', array(
		'default'        => '#8FAEB8',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'content_botline', array(
		'label'   => __( 'Main Content Bottom Line', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'content_botline',
		'priority' => 5,
	) ) );

// Main Content text colour
	$wp_customize->add_setting( 'content_text', array(
		'default'        => '#747474',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'content_text', array(
		'label'   => __( 'Main Content Text Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'content_text',
		'priority' => 6,
	) ) );

// Footer background colour
	$wp_customize->add_setting( 'footer_bg', array(
		'default'        => '#78A5B6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_bg', array(
		'label'   => __( 'Footer Background', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_bg',
		'priority' => 7,
	) ) );
	
// Footer top line
	$wp_customize->add_setting( 'footer_topline', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_topline', array(
		'label'   => __( 'Footer Top Line', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_topline',
		'priority' => 8,
	) ) );	

// Footer Headings
	$wp_customize->add_setting( 'footer_headings', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_headings', array(
		'label'   => __( 'Footer Headings', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_headings',
		'priority' => 9,
	) ) );
		
// Footer text colour
	$wp_customize->add_setting( 'footer_text', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_text', array(
		'label'   => __( 'Footer Text Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_text',
		'priority' => 10,
	) ) );	
// Footer link colour
	$wp_customize->add_setting( 'footer_links', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_links', array(
		'label'   => __( 'Footer Links', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_links',
		'priority' => 11,
	) ) );
// Footer link hover
	$wp_customize->add_setting( 'footer_linkshov', array(
		'default'        => '#ddd7c3',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_linkshov', array(
		'label'   => __( 'Footer Link Hover', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_linkshov',
		'priority' => 12,
	) ) );	

// Footer list borders
	$wp_customize->add_setting( 'footer_listborder', array(
		'default'        => '#AFC7CF',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_listborder', array(
		'label'   => __( 'Footer List Border Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_listborder',
		'priority' => 13,
	) ) );
// Footer list borders on hover
	$wp_customize->add_setting( 'footer_listborderhov', array(
		'default'        => '#6891a0',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'footer_listborderhov', array(
		'label'   => __( 'Footer List Border Hover', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'footer_listborderhov',
		'priority' => 14,
	) ) );

// Page bottom text colour
	$wp_customize->add_setting( 'pagebottom_text', array(
		'default'        => '#747474',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pagebottom_text', array(
		'label'   => __( 'Page Bottom Text Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'pagebottom_text',
		'priority' => 15,
	) ) );	
	
// Page bottom link colour
	$wp_customize->add_setting( 'pagebottom_links', array(
		'default'        => '#78a5b6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pagebottom_links', array(
		'label'   => __( 'Page Bottom Links', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'pagebottom_links',
		'priority' => 16,
	) ) );		
	
// Content Headings
	$wp_customize->add_setting( 'page_headings', array(
		'default'        => '#333333',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'page_headings', array(
		'label'   => __( 'Page Headings', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'page_headings',
		'priority' => 17,
	) ) );	
		

// Text link colour
	$wp_customize->add_setting( 'links', array(
		'default'        => '#b88d28',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'links', array(
		'label'   => __( 'Text link Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'links',
		'priority' => 18,
	) ) );
// Text link hover colour
	$wp_customize->add_setting( 'linkshover', array(
		'default'        => '#719aa7',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'linkshover', array(
		'label'   => __( 'Text Link Hover Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'linkshover',
		'priority' => 19,
	) ) );
// Sidebar left and right link colour
	$wp_customize->add_setting( 'sidelinks', array(
		'default'        => '#747474',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sidelinks', array(
		'label'   => __( 'Side Column Links', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'sidelinks',
		'priority' => 20,
	) ) );
// Image border colour
	$wp_customize->add_setting( 'imgborder', array(
		'default'        => '#78a5b6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'imgborder', array(
		'label'   => __( 'Image Border', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'imgborder',
		'priority' => 21,
	) ) );	
	
// Custom Widget colour
	$wp_customize->add_setting( 'custom', array(
		'default'        => '#78A5B6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'custom', array(
		'label'   => __( 'Widget Colour', 'preference-lite' ),
		'section' => 'colors',
		'settings'   => 'custom',
		'priority' => 22,
	) ) );	
	
		
/**
 * Nav Section
 * Lets style our menus
 */
 
// Main menu background colour
	$wp_customize->add_setting( 'mainmenu_bg', array(
		'default'        => '#78A5B6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'mainmenu_bg', array(
		'label'   => __( 'Menu Background Row', 'preference-lite' ),
		'section' => 'nav',
		'settings'   => 'mainmenu_bg',
		'priority' => 15,
	) ) );
	 
// Main menu link
	$wp_customize->add_setting( 'menutext', array(
		'default'        => '#ffffff',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'menutext', array(
		'label'   => __( 'Menu Text Colour', 'preference-lite' ),
		'section' => 'nav',
		'settings'   => 'menutext',
		'priority' => 16,
	) ) );	
	
// Main menu link hover
	$wp_customize->add_setting( 'menutexthover', array(
		'default'        => '#F8D9B0',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'menutexthover', array(
		'label'   => __( 'Menu Text Hover/Active', 'preference-lite' ),
		'section' => 'nav',
		'settings'   => 'menutexthover',
		'priority' => 17,
	) ) );	
	
// Submenu Background
	$wp_customize->add_setting( 'submenubg', array(
		'default'        => '#78a5b6',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'submenubg', array(
		'label'   => __( 'Submenu Background', 'preference-lite' ),
		'section' => 'nav',
		'settings'   => 'submenubg',
		'priority' => 18,
	) ) );		
	
	
// Submenu active and hover Background
	$wp_customize->add_setting( 'submenubghover', array(
		'default'        => '#8cb5c4',
		'sanitize_callback' => 'preference_lite_sanitize_hex_color',
	) );

	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'submenubghover', array(
		'label'   => __( 'Submenu Hover/Active Link', 'preference-lite' ),
		'section' => 'nav',
		'settings'   => 'submenubghover',
		'priority' => 19,
	) ) );	
		
}






/**
 * adds sanitization callback function : colors
 * @package Preference Lite
 */
	function preference_lite_sanitize_hex_color( $color ) {
	if ( $unhashed = sanitize_hex_color_no_hash( $color ) )
		return '#' . $unhashed;

	return $color;
}

/**
 * adds sanitization callback function : text
 * @package Preference Lite
 */
function preference_lite_sanitize_text( $input ) {
    return wp_kses_post( force_balance_tags( $input ) );
}

/**
 * adds sanitization callback function : url
 * @package Preference Lite
 */
	function preference_lite_sanitize_url( $value) {
		$value = esc_url( $value);
		return $value;
	}

/**
 * adds sanitization callback function : checkbox
 * @package Preference Lite
 */
function preference_lite_sanitize_checkbox( $input ) {
    if ( $input == 1 ) {
        return 1;
    } else {
        return '';
    }
}	


/**
 * adds sanitization callback function for the logo style : radio
 * @package Preference Lite
 */
function preference_lite_sanitize_logo_style( $input ) {
    $valid = array(
            'default' => __( 'Default Logo', 'preference-lite' ),
            'custom' => __( 'Your Logo', 'preference-lite' ),
            'text' => __( 'Text Title', 'preference-lite' ),
    );
 
    if ( array_key_exists( $input, $valid ) ) {
        return $input;
    } else {
        return '';
    }
}

/**
 * adds sanitization callback function for the logo style : select
 * @package Preference Lite
 */
function preference_lite_sanitize_showcase_bg( $input ) {
    $valid = array(
        'showcase-bg1.jpg' => __( 'Background 1', 'preference-lite' ),
        'showcase-bg2.jpg' => __( 'Background 2', 'preference-lite' ),
        'showcase-bg3.jpg' => __( 'Background 3', 'preference-lite' ),
		'showcase-bg4.jpg' => __( 'Background 4', 'preference-lite' ),
		'showcase-bg5.jpg' => __( 'Background 5', 'preference-lite' ),
		'showcase-bg6.jpg' => __( 'Background 6', 'preference-lite' ),
		'showcase-bg7.jpg' => __( 'Background 7', 'preference-lite' ),
		'showcase-bg0.png' => __( 'None', 'preference-lite' ),
    );
 
    if ( array_key_exists( $input, $valid ) ) {
        return $input;
    } else {
        return '';
    }
}


/**
 * adds sanitization callback function for numeric data : number
 * @package Preference Lite
 */

function preference_lite_sanitize_number( $value ) {
    $value = (int) $value; // Force the value into integer type.
    return ( 0 < $value ) ? $value : null;
}

/**
 * adds sanitization callback function for uploading : uploader
 * @package Preference
 * Special thanks to: https://github.com/chrisakelley
 */
add_filter( 'preference_lite_sanitize_image', 'preference_lite_sanitize_upload' );
add_filter( 'preference_lite_sanitize_file', 'preference_lite_sanitize_upload' );
function preference_lite_sanitize_upload( $input ) {
        
        $output = '';
        
        $filetype = wp_check_filetype($input);
        
        if ( $filetype["ext"] ) {
        
                $output = $input;
        
        }
        
        return $output;

}
