<?php
/**
 * podcastin Theme Customizer
 *
 * @package podcastin
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function podcastin_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	$podcastin_options = podcastin_theme_options();

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'podcastin_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'podcastin_customize_partial_blogdescription',
			)
		);
	}

	$wp_customize->add_panel(
        'theme_options',
        array(
            'title' => esc_html__('Theme Options', 'podcastin'),
            'priority' => 2,
        )
    );

//Social Links
    $wp_customize->add_section(
    'social_section',
	    array(
	        'title' => esc_html__( 'Social Links','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);
	$wp_customize->add_setting('podcastin_theme_options[fb_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['fb_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[fb_url]',
	    array(
	        'label' => esc_html__('Facebook Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'social_section',
	        'settings' => 'podcastin_theme_options[fb_url]',
	    )
	);
		$wp_customize->add_setting('podcastin_theme_options[youtube_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['youtube_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[youtube_url]',
	    array(
	        'label' => esc_html__('Youtube Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'social_section',
	        'settings' => 'podcastin_theme_options[youtube_url]',
	    )
	);




//Banner section
    $wp_customize->add_section(
    'banner_section',
	    array(
	        'title' => esc_html__( 'Banner Section','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[banner_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['banner_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[banner_title]',
	    array(
	        'label' => esc_html__('Banner Title', 'podcastin'),
	        'priority' => 1,
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);



	
	$wp_customize->add_setting('podcastin_theme_options[banner_image]',
	array(
	    'type' => 'option',
	    'sanitize_callback' => 'esc_url_raw',
	)
	);
	$wp_customize->add_control(
	new WP_Customize_Image_Control(
	    $wp_customize,
	    'podcastin_theme_options[banner_image]',
	    array(
	        'label' => esc_html__('Add Background Image', 'podcastin'),
	        'section' => 'banner_section',
	        'settings' => 'podcastin_theme_options[banner_image]',
	    ))
	);


	$wp_customize->add_setting('podcastin_theme_options[banner_subtext]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['banner_subtext'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[banner_subtext]',
	    array(
	        'label' => esc_html__('Banner Subtitle', 'podcastin'),
	        'priority' => 1,
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);

		$wp_customize->add_setting('podcastin_theme_options[soundcloud_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['soundcloud_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[soundcloud_url]',
	    array(
	        'label' => esc_html__('Soundcloud Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'banner_section',
	        'settings' => 'podcastin_theme_options[soundcloud_url]',
	    )
	);
		$wp_customize->add_setting('podcastin_theme_options[stitcher_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['stitcher_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[stitcher_url]',
	    array(
	        'label' => esc_html__('Stitcher Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'banner_section',
	        'settings' => 'podcastin_theme_options[stitcher_url]',
	    )
	);








	$wp_customize->add_setting('podcastin_theme_options[streaming_site_label]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['streaming_site_label'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[streaming_site_label]',
	    array(
	        'label' => esc_html__('Streaming Site Label', 'podcastin'),
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('podcastin_theme_options[banner_btn_text]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['banner_btn_text'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[banner_btn_text]',
	    array(
	        'label' => esc_html__('Banner Button Text', 'podcastin'),
	        'section' => 'banner_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('podcastin_theme_options[banner_button_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['banner_button_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[banner_button_url]',
	    array(
	        'label' => esc_html__('Banner Button Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'banner_section',
	        'settings' => 'podcastin_theme_options[banner_button_url]',
	    )
	);




    //Listing section
	$wp_customize->add_section(
    'episode_section',
	    array(
	        'title' => esc_html__( 'Episode Section','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[episode_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $podcastin_options['episode_sec_show'],
	        'sanitize_callback' => 'podcastin_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('podcastin_theme_options[episode_sec_show]',
	    array(
	        'label' => esc_html__('Show Episode Section', 'podcastin'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'episode_section',

	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[episode_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['episode_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[episode_sec_title]',
	    array(
	        'label' => esc_html__('Section Title', 'podcastin'),
	        'priority' => 1,
	        'section' => 'episode_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('podcastin_theme_options[episode_full_width]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $podcastin_options['episode_full_width'],
	        'sanitize_callback' => 'podcastin_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('podcastin_theme_options[episode_full_width]',
	    array(
	        'label' => esc_html__('Show Full Width Episodes', 'podcastin'),
	        'type' => 'Checkbox',
	        'section' => 'episode_section',

	    )
	);


    //About section
	$wp_customize->add_section(
    'about_section',
	    array(
	        'title' => esc_html__( 'About Section','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[about_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $podcastin_options['about_sec_show'],
	        'sanitize_callback' => 'podcastin_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('podcastin_theme_options[about_sec_show]',
	    array(
	        'label' => esc_html__('Show About Section', 'podcastin'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'about_section',

	    )
	);


	$wp_customize->add_setting('podcastin_theme_options[about_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['about_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[about_sec_title]',
	    array(
	        'label' => esc_html__('About Title', 'podcastin'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[about_sec_sub_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['about_sec_sub_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[about_sec_sub_title]',
	    array(
	        'label' => esc_html__('About Sub Title', 'podcastin'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[about_btn_text]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['about_btn_text'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[about_btn_text]',
	    array(
	        'label' => esc_html__('About Button Text', 'podcastin'),
	        'priority' => 1,
	        'section' => 'about_section',
	        'type' => 'text',
	    )
	);
	$wp_customize->add_setting('podcastin_theme_options[about_button_url]',
	    array(
	        'type' => 'option',
	        'default' => $podcastin_options['about_button_url'],
	        'sanitize_callback' => 'podcastin_sanitize_url',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[about_button_url]',
	    array(
	        'label' => esc_html__('About Button Link', 'podcastin'),
	        'type' => 'text',
	        'section' => 'about_section',
	        'settings' => 'podcastin_theme_options[about_button_url]',
	    )
	);


	$wp_customize->add_setting('podcastin_theme_options[about_front_image]',
	array(
	    'type' => 'option',
	    'sanitize_callback' => 'esc_url_raw',
	)
	);
	$wp_customize->add_control(
	new WP_Customize_Image_Control(
	    $wp_customize,
	    'podcastin_theme_options[about_front_image]',
	    array(
	        'label' => esc_html__('Add About Image', 'podcastin'),
	        'section' => 'about_section',
	        'settings' => 'podcastin_theme_options[about_front_image]',
	    ))
	);





    //Blog section
	$wp_customize->add_section(
    'blog_section',
	    array(
	        'title' => esc_html__( 'Blog Section','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[blog_sec_show]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $podcastin_options['blog_sec_show'],
	        'sanitize_callback' => 'podcastin_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('podcastin_theme_options[blog_sec_show]',
	    array(
	        'label' => esc_html__('Show Blog Section', 'podcastin'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'blog_section',

	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[blog_sec_title]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['blog_sec_title'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[blog_sec_title]',
	    array(
	        'label' => esc_html__('Section Title', 'podcastin'),
	        'priority' => 1,
	        'section' => 'blog_section',
	        'type' => 'text',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[blog_post_no]',
	    array(
	        'capability' => 'edit_theme_options',
	        'default' => $podcastin_options['blog_post_no'],
	        'sanitize_callback' => 'sanitize_text_field',
	        'type' => 'option',
	    )
	);
	$wp_customize->add_control('podcastin_theme_options[blog_post_no]',
	    array(
	        'label' => esc_html__('No Of Blog Posts to show?', 'podcastin'),
	        'priority' => 1,
	        'section' => 'blog_section',
	        'type' => 'text',
	    )
	);




	    //Footer
	$wp_customize->add_section(
    'footer_section',
	    array(
	        'title' => esc_html__( 'Footer Option','podcastin' ),
	        'panel'=>'theme_options',
	        'capability'=>'edit_theme_options',
	    )
	);

	$wp_customize->add_setting('podcastin_theme_options[show_widgets]',
	    array(
	        'type' => 'option',
	        'default'        => true,
	        'default' => $podcastin_options['show_widgets'],
	        'sanitize_callback' => 'podcastin_sanitize_checkbox',
	    )
	);

	$wp_customize->add_control('podcastin_theme_options[show_widgets]',
	    array(
	        'label' => esc_html__('Show Widgets', 'podcastin'),
	        'type' => 'Checkbox',
	        'priority' => 1,
	        'section' => 'footer_section',

	    )
	);

}
add_action( 'customize_register', 'podcastin_customize_register' );

/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function podcastin_customize_partial_blogname() {
	bloginfo( 'name' );
}

/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function podcastin_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function podcastin_customize_preview_js() {
	wp_enqueue_script( 'podcastin-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true );
}
add_action( 'customize_preview_init', 'podcastin_customize_preview_js' );
