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

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function pitra_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';

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



/**
 * Header and social Customizer Settings
 */
$wp_customize->add_panel( 'theme_options' ,
    array(
        'title'       => esc_html__( 'Theme Options', 'pitra' ),
        'description' => ''
        )
    );
$wp_customize->add_setting( 'button_text', array(
    'type'              => 'theme_mod',
    'capability'        => 'edit_theme_options',
    'sanitize_callback' => 'sanitize_text_field',
    ) );

$wp_customize->add_control( 'button_text', array(
    'label'    => __( "pitra Button Text", 'pitra' ),
    'section'  => 'header_image',
    'type'     => 'text',
    'priority' => 1,
    ) );
$wp_customize->add_setting( 'button_link', array(
    'type'              => 'theme_mod',
    'capability'        => 'edit_theme_options',
    'sanitize_callback' => 'esc_url_raw'
    ) );

$wp_customize->add_control( 'button_link', array(
    'label'    => __( "pitra Button Link URL", 'pitra' ),
    'section'  => 'header_image',
    'description' => __( 'For example: Http://google.com/', 'pitra' ),
    'type'     => 'text',
    'priority' => 1,
    ) );
$wp_customize->add_section( 'pitra_social' ,
    array(
        'title'      => esc_html__('Social Links', 'pitra'),
        'priority'   => 1,
        ) 
    );

$wp_customize->add_setting(
    'pitra_facebook',
    array(
        'default'     => '',
        'description' => __( 'Enter your social media link(URL. Icons will not show if left blank.', 'pitra' ),
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_twitter',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_instagram',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_bloglovin',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_google',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_linkedin',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_soundcloud',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_youtube',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );
$wp_customize->add_setting(
    'pitra_vimeo',
    array(
        'default'     => '',
        'sanitize_callback' => 'esc_url_raw'
        )
    );

$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_facebook',
        array(
            'label'      => esc_html__('Facebook', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_facebook',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_twitter',
        array(
            'label'      => esc_html__('Twitter', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_twitter',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_instagram',
        array(
            'label'      => esc_html__('Instagram', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_instagram',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_bloglovin',
        array(
            'label'      => esc_html__('Bloglovin', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_bloglovin',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_google',
        array(
            'label'      => esc_html__('Google Plus', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_google',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_linkedin',
        array(
            'label'      => esc_html__('Linkedin', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_linkedin',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_soundcloud',
        array(
            'label'      => esc_html__('Soundcloud', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_soundcloud',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_youtube',
        array(
            'label'      => esc_html__('Youtube', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_youtube',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );
$wp_customize->add_control(
    new WP_Customize_Control(
        $wp_customize,
        'pitra_vimeo',
        array(
            'label'      => esc_html__('Vimeo', 'pitra'),
            'section'    => 'pitra_social',
            'description' => __( 'Icons will not show if left blank. Enter your social media link(URL). . For example http://google.com/', 'pitra' ),
            'settings'   => 'pitra_vimeo',
            'type'       => 'url',
            'priority'   => 99
            )
        )
    );


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

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

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

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


