<?php
/********* Theme Customizer Options ***********/

/* Setup Sanitization Functions */

// Select sanitization
    function wisnia_sanitize_select( $input, $setting ){

        //input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only
        $input = sanitize_key($input);

        //get the list of possible select options
        $choices = $setting->manager->get_control( $setting->id )->choices;

        //return input if valid or return default option
        return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
    }

// Checkbox sanitization
    function wisnia_sanitize_checkbox( $input ) {
    		return ( 1 === absint( $input ) ) ? 1 : 0;
    	}



add_action( 'customize_register', 'wisnia_customize_register' );

if (!function_exists('wisnia_customize_register')) {
	function wisnia_customize_register( $wp_customize ) {

/**
------------------------------------------------------------
PANEL: Wisnia Settings
------------------------------------------------------------
**/

    $wp_customize->add_panel( 'wisnia_settings_panel', array(
        'title' => esc_html__( 'Wisnia Settings', 'wisnia' ),
        'priority' => 10,
    ) );

    /**
    ------------------------------------------------------------
    SECTION: Dynamic Banner
    ------------------------------------------------------------
    **/

    $wp_customize->add_section( 'section_banner_settings', array(
    	'title'		  => esc_html__( 'Dynamic Banner', 'wisnia' ),
    	'priority'	=> 10,
      'panel'     => 'wisnia_settings_panel',
    ));

      /**
      ------------------------------------------------------------
      SETTING: Banner Background Color
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_color', array(
        'default'           => '#6EC4DB',
        'transport'         => 'refresh',
        'sanitize_callback' => 'sanitize_hex_color'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'banner_color', array(
        'label'    => esc_html__( 'Banner Color', 'wisnia' ),
        'description' => esc_html__( 'Sets the background color for the banner. You\'ll need to add widgets to Widgets > First/Second/Third Front Page Banner to see this.', 'wisnia' ),
        'settings' => 'banner_color',
        'section'  => 'section_banner_settings',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Banner Background Image
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_image', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'banner_image', array(
        'label'    => esc_html__( 'Banner Background Image', 'wisnia' ),
        'settings' => 'banner_image',
        'section'  => 'section_banner_settings',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Banner Background Image Size
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_size', array(
        'default'           => 'auto',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wisnia_sanitize_select'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'banner_size', array(
        'label'    => esc_html__( 'Banner Image Size', 'wisnia' ),
        'settings' => 'banner_size',
        'section'  => 'section_banner_settings',
        'type'     => 'select',
        'choices' => array(
          'auto' => esc_html__( 'Auto', 'wisnia' ),
          'cover' => esc_html__( 'Cover', 'wisnia' )
    )
      )));
      /**
      ------------------------------------------------------------
      SETTING: Banner Background Image Repeat
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_repeat', array(
        'default'           => 'repeat',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wisnia_sanitize_select'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'banner_repeat', array(
        'label'    => esc_html__( 'Banner Image Repeat', 'wisnia' ),
        'settings' => 'banner_repeat',
        'section'  => 'section_banner_settings',
        'type'     => 'select',
        'choices' => array(
          'repeat' => esc_html__( 'Repeat All', 'wisnia' ),
          'repeat-x' => esc_html__( 'Repeat Horizontally', 'wisnia' ),
          'repeat-y' => esc_html__( 'Repeat Vertically', 'wisnia' ),
          'no-repeat' => esc_html__( 'No Repeat', 'wisnia' )
    )
      )));
      /**
      ------------------------------------------------------------
      SETTING: Banner Background Image Position
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_position', array(
        'default'           => 'top left',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wp_filter_nohtml_kses'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'banner_position', array(
        'label'    => esc_html__( 'Banner Image Position', 'wisnia' ),
        'settings' => 'banner_position',
        'section'  => 'section_banner_settings',
        'type'     => 'select',
        'choices' => array(
          'top left'      => esc_html__( 'Top Left', 'wisnia' ),
      		'top center'    => esc_html__( 'Top Center', 'wisnia' ),
      		'top right'     => esc_html__( 'Top Right', 'wisnia' ),
      		'center left'   => esc_html__( 'Middle Left', 'wisnia' ),
      		'center center' => esc_html__( 'Middle Center', 'wisnia' ),
      		'center right'  => esc_html__( 'Middle Right', 'wisnia' ),
      		'bottom left'   => esc_html__( 'Bottom Left', 'wisnia' ),
      		'bottom center' => esc_html__( 'Bottom Center', 'wisnia' ),
      		'bottom right'  => esc_html__( 'Bottom Right', 'wisnia')
          )
      )));
      /**
      ------------------------------------------------------------
      SETTING: Banner Background Image Attachment
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'banner_attachment', array(
        'default'           => 'scroll',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wisnia_sanitize_select'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'banner_attachment', array(
        'label'    => esc_html__( 'Banner Image Scroll', 'wisnia' ),
        'settings' => 'banner_attachment',
        'section'  => 'section_banner_settings',
        'type'     => 'select',
        'choices' => array(
          'scroll' => esc_html__( 'Scroll Normally', 'wisnia' ),
      		'fixed'  => esc_html__( 'Fixed in Place', 'wisnia')
          )
      )));
      /**
      ------------------------------------------------------------
      SECTION: Footer
      ------------------------------------------------------------
      **/

      $wp_customize->add_section( 'section_footer_settings', array(
        'title'		  => esc_html__( 'Footer', 'wisnia' ),
        'priority'	=> 11,
        'panel'     => 'wisnia_settings_panel',
      ));

        /**
        ------------------------------------------------------------
        SETTING: Footer Background Color
        ------------------------------------------------------------
        **/
        $wp_customize->add_setting( 'footer_color', array(
            'default'           => '#6EC4DB',
            'transport'         => 'refresh',
            'sanitize_callback' => 'sanitize_hex_color'
        ));
        // Add control for setting
        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'footer_color', array(
          'label'    => esc_html__( 'Footer Color', 'wisnia' ),
          'description' => esc_html__( 'Sets the background color for the footer.', 'wisnia' ),
          'settings' => 'footer_color',
          'section'  => 'section_footer_settings',
        )));

      /**
      ------------------------------------------------------------
      SETTING: Footer Position
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'footer_position', array(
        'default'           => 'center',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wisnia_sanitize_select'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'footer_position', array(
        'label'    => esc_html__( 'Footer Position', 'wisnia' ),
        'settings' => 'footer_position',
        'section'  => 'section_footer_settings',
        'type'     => 'select',
        'choices' => array(
          'left' => esc_html__( 'Left aligned', 'wisnia' ),
      		'center' => esc_html__( 'Center aligned', 'wisnia' ),
      		'right' => esc_html__( 'Right aligned', 'wisnia' )
          )
      )));
      /**
      ------------------------------------------------------------
      SETTING: Footer Content
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'footer_content', array(
        'default'           => wisnia_get_credits(),
        'transport'         => 'refresh',
        'sanitize_callback' => 'wp_kses_post'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'footer_content', array(
        'label'    => esc_html__( 'Footer Content', 'wisnia' ),
        'description' => esc_html__( 'Enter the text you&lsquo;d like to display in the footer. This content will be displayed just below the footer widgets. It&lsquo;s ideal for displaying your copyright message or credits.', 'wisnia' ),
        'settings' => 'footer_content',
        'section'  => 'section_footer_settings',
        'type'     => 'textarea',
      )));
      /**
      ------------------------------------------------------------
      SECTION: Social Icons
      ------------------------------------------------------------
      **/

      $wp_customize->add_section( 'section_social_settings', array(
        'title'		  => esc_html__( 'Social Icons', 'wisnia' ),
        'priority'	=> 12,
        'panel'     => 'wisnia_settings_panel',
      ));
      /**
      ------------------------------------------------------------
      SETTING: Open Social Links In A Newtab
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_newtab', array(
        'default'           => '1',
        'transport'         => 'refresh',
        'sanitize_callback' => 'wisnia_sanitize_checkbox'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_newtab', array(
        'label'    => esc_html__( 'Open Social Links in a Newtab?', 'wisnia' ),
        'settings' => 'social_newtab',
        'section'  => 'section_social_settings',
        'type'     => 'checkbox',
      )));

      /**
      ------------------------------------------------------------
      SETTING: Twitter
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_twitter', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_twitter', array(
        'label'    => esc_html__( 'Twitter', 'wisnia' ),
        'settings' => 'social_twitter',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Facebook
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_facebook', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_facebook', array(
        'label'    => esc_html__( 'Facebook', 'wisnia' ),
        'settings' => 'social_facebook',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: LinkedIn
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_linkedin', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_linkedin', array(
        'label'    => esc_html__( 'LinkedIn', 'wisnia' ),
        'settings' => 'social_linkedin',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Slideshare
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_slideshare', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_slideshare', array(
        'label'    => esc_html__( 'Slideshare', 'wisnia' ),
        'settings' => 'social_slideshare',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Slack
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_slack', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_slack', array(
        'label'    => esc_html__( 'Slack', 'wisnia' ),
        'settings' => 'social_slack',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Dribbble
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_dribbble', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_dribbble', array(
        'label'    => esc_html__( 'Dribbble', 'wisnia' ),
        'settings' => 'social_dribbble',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Tumblr
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_tumblr', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_tumblr', array(
        'label'    => esc_html__( 'Tumblr', 'wisnia' ),
        'settings' => 'social_tumblr',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Reddit
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_reddit', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_reddit', array(
        'label'    => esc_html__( 'Reddit', 'wisnia' ),
        'settings' => 'social_reddit',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Twitch
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_twitch', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_twitch', array(
        'label'    => esc_html__( 'Twitch', 'wisnia' ),
        'settings' => 'social_twitch',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Github
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_github', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_github', array(
        'label'    => esc_html__( 'Github', 'wisnia' ),
        'settings' => 'social_github',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Bitbucket
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_bitbucket', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_bitbucket', array(
        'label'    => esc_html__( 'Bitbucket', 'wisnia' ),
        'settings' => 'social_bitbucket',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Stackoverflow
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_stackoverflow', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_stackoverflow', array(
        'label'    => esc_html__( 'Stackoverflow', 'wisnia' ),
        'settings' => 'social_stackoverflow',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Codepen
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_codepen', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_codepen', array(
        'label'    => esc_html__( 'Codepen', 'wisnia' ),
        'settings' => 'social_codepen',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Foursquare
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_foursquare', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_foursquare', array(
        'label'    => esc_html__( 'Foursquare', 'wisnia' ),
        'settings' => 'social_foursquare',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: YouTube
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_youtube', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_youtube', array(
        'label'    => esc_html__( 'YouTube', 'wisnia' ),
        'settings' => 'social_youtube',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Vimeo
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_vimeo', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_vimeo', array(
        'label'    => esc_html__( 'Vimeo', 'wisnia' ),
        'settings' => 'social_vimeo',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Instagram
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_instagram', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_instagram', array(
        'label'    => esc_html__( 'Instagram', 'wisnia' ),
        'settings' => 'social_instagram',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Vine
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_vine', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_vine', array(
        'label'    => esc_html__( 'Vine', 'wisnia' ),
        'settings' => 'social_vine',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Snapchat
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_snapchat', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_snapchat', array(
        'label'    => esc_html__( 'Snapchat', 'wisnia' ),
        'settings' => 'social_snapchat',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Flickr
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_flickr', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_flickr', array(
        'label'    => esc_html__( 'Flickr', 'wisnia' ),
        'settings' => 'social_flickr',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: Pinterest
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_pinterest', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_pinterest', array(
        'label'    => esc_html__( 'Pinterest', 'wisnia' ),
        'settings' => 'social_pinterest',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
      /**
      ------------------------------------------------------------
      SETTING: RSS
      ------------------------------------------------------------
      **/
      $wp_customize->add_setting( 'social_rss', array(
        'default'           => '',
        'transport'         => 'refresh',
        'sanitize_callback' => 'esc_url_raw'
      ));
      // Add control for setting
      $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'social_rss', array(
        'label'    => esc_html__( 'RSS', 'wisnia' ),
        'settings' => 'social_rss',
        'section'  => 'section_social_settings',
        'type'     => 'url',
      )));
  /**---------------------------------------------------------------**/
    }
}
