<?php
/**
 * Claydell Media Theme Customizer
 *
 * @package Claydell Media
 * @link http://ottopress.com/tag/customizer/
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function claydell_media_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';
	
    // Logo upload
    $wp_customize->add_section( 'claydell_media_logo_section' , array(
    'title'       => __( 'Logo', 'claydell-media' ),
    'priority'    => 30,
    'description' => 'Upload a logo to replace the default site name and description in the header',
) );

	$wp_customize->add_setting( 'claydell_media_logo' );
	$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'claydell_media_logo', array(
    'label'    => __( 'Logo', 'claydell-media' ),
    'section'  => 'claydell_media_logo_section',
    'settings' => 'claydell_media_logo',
	'sanitize_callback' => 'claydell_media_sanitize_logo',
) ) );

	// add settings to create various social media text areas.
	$wp_customize->add_section( 'claydell_media_socialmedia_settings', array(
		'title'    => 'Social Media Settings',
		'priority' => 35,
	) );
	
	$wp_customize->add_setting( 'rss', array(
		'default' => '',
		'sanitize_callback' => 'claydell_media_sanitize_rss',
	) );

	$wp_customize->add_control( 'rss', array(
		'label'   => __( 'RSS url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );

	$wp_customize->add_setting( 'twitter', array(
		'default' => '',
		'sanitize_callback' => 'claydell_media_sanitize_twitter',
	) );

	$wp_customize->add_control( 'twitter', array(
		'label'   => __( 'Twitter url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'facebook', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_facebook',
	) );

	$wp_customize->add_control( 'facebook', array(
		'label'   => __( 'Facebook url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'googleplus', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_googleplus',
	) );

	$wp_customize->add_control( 'googleplus', array(
		'label'   => __( 'Google + url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'flickr', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_flickr',
	) );

	$wp_customize->add_control( 'flickr', array(
		'label'   => __( 'Flickr url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'linkedin-alt', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_linkedin_alt',
	) );

	$wp_customize->add_control( 'linkedin-alt', array(
		'label'   => __( 'LinkedIn url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'wordpress', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_wordpress',
	) );

	$wp_customize->add_control( 'wordpress', array(
		'label'   => __( 'WordPress url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'pinterest-alt', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_pinterest_alt',
	) );

	$wp_customize->add_control( 'pinterest-alt', array(
		'label'   => __( 'Pinterest url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'youtube', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_youtube',
	) );

	$wp_customize->add_control( 'youtube', array(
		'label'   => __( 'YouTube url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'vimeo', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_vimeo',
	) );

	$wp_customize->add_control( 'vimeo', array(
		'label'   => __( 'Vimeo url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'dribble', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_dribble',
	) );

	$wp_customize->add_control( 'dribble', array(
		'label'   => __( 'Dribble url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'tumblr', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_tumblr',
	) );

	$wp_customize->add_control( 'tumblr', array(
		'label'   => __( 'Tumblr url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'github', array(
		'default'        => '',
		'sanitize_callback' => 'claydell_media_sanitize_github',
	) );

	$wp_customize->add_control( 'github', array(
		'label'   => __( 'Github url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
	
	$wp_customize->add_setting( 'instagram', array(
		'default' => '',
		'sanitize_callback' => 'claydell_media_sanitize_instagram',
	) );

	$wp_customize->add_control( 'instagram', array(
		'label'   => __( 'Instagram url:', 'claydell-media' ),
		'section' => 'claydell_media_socialmedia_settings',
		'type'    => 'text',
	) );
}
add_action( 'customize_register', 'claydell_media_customize_register' );

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