<?php

add_action( 'init', 'register_cpt_slider' );

function register_cpt_slider() {

    $labels = array( 
        'name' => _x( 'Sliders', 'slider' ),
        'singular_name' => _x( 'Slider', 'slider' ),
        'add_new' => _x( 'Add New', 'slider' ),
        'add_new_item' => _x( 'Add New Slider', 'slider' ),
        'edit_item' => _x( 'Edit Slider', 'slider' ),
        'new_item' => _x( 'New Slider', 'slider' ),
        'view_item' => _x( 'View Slider', 'slider' ),
        'search_items' => _x( 'Search Sliders', 'slider' ),
        'not_found' => _x( 'No sliders found', 'slider' ),
        'not_found_in_trash' => _x( 'No sliders found in Trash', 'slider' ),
        'parent_item_colon' => _x( 'Parent Slider:', 'slider' ),
        'menu_name' => _x( 'Slider', 'slider' ),
    );

    $args = array( 
        'labels' => $labels,
        'hierarchical' => false,
        'description' => 'Add to the front page slider',
        'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'page-attributes' ),
        
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_in_nav_menus' => false,
        'publicly_queryable' => true,
        'exclude_from_search' => true,
        'has_archive' => true,
        'query_var' => true,
        'menu_icon' => 'dashicons-slides',
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'slider', $args );
}



function flexslider_customiser($wp_customize){

// Add a panel for flexslider

$wp_customize->add_panel( 'flexslider_settings', array(
    'priority'       => 20,
    'capability'     => 'edit_theme_options',
    'theme_supports' => '',
    'title'          => 'Flexslider settings',
    'description'    => 'Settings for Flexslider',
) );

// Flexslider animation options

$wp_customize->add_section( 'flexslider_setting_general', array(
            'title'    => 'Flexslider settings',
            'priority' => 35,
            'panel'    => 'flexslider_settings'
        ) );

        $wp_customize->add_setting( 'flex_animation_settings', array(
            'default'        => 'slide',
        ) );

        $wp_customize->add_control( 'flex_animation_settings', array(
                'label'   => 'Animation type',
                'section' => 'flexslider_setting_general',
                'type'    => 'select',
                'choices' => array(
                    'slide' => 'Slide', 
                    'fade' => 'Fade',
                ),
                'setting' => 'flex_animation_settings'
        ) );

// Flexslider transition speed options


        $wp_customize->add_setting( 'flex_slide_speed', array(
            'default'        => '7000',
        ) );

        $wp_customize->add_control( 'flex_slide_speed', array(
                'label'   => 'Time between slide transitions',
                'description' => 'Please enter time in milliseconds, for example 4000 is equal to 4 seconds',
                'section' => 'flexslider_setting_general',
                'type'    => 'text',
                'setting' => 'flex_slide_speed'
        ) );

        // Flexslider slide direction


        $wp_customize->add_setting( 'flex_slide_direction', array(
            'default'        => 'horizontal',
        ) );

        $wp_customize->add_control( 'flex_slide_direction', array(
                'label'   => 'Direction each slide travels in',
                'description' => 'Please note the animation type must be set to "slide" for this option to take effect',
                'section' => 'flexslider_setting_general',
                'type'    => 'select',
                'choices' => array(
                    'horizontal' => 'Horizontal', 
                    'vertical' => 'vertical',
                    ),
                'setting' => 'flex_slide_direction'
        ) );

        // Flexslider slide animation speed


        $wp_customize->add_setting( 'flex_slide_anispeed', array(
            'default'        => '1000',
        ) );

        $wp_customize->add_control( 'flex_slide_anispeed', array(
                'label'   => 'Transition animation speed',
                'description' => 'Adjust the speed of transition animation, please enter time in milliseconds, for example 1000 is equal to 1 second ',
                'section' => 'flexslider_setting_general',
                'type'    => 'text',
                'setting' => 'flex_slide_anispeed'
        ) );

        // Flexslider slide pause on action


        $wp_customize->add_setting( 'flex_slide_action_pause', array(
            'default'        => '1',
        ) );

        $wp_customize->add_control( 'flex_slide_action_pause', array(
                'label'   => 'Pause slider on action',
                'description' => 'Pause the slider when a user interacts with any of the slider controls',
                'section' => 'flexslider_setting_general',
                'type'    => 'checkbox',
                'setting' => 'flex_slide_action_pause'
        ) );

        // Flexslider slide pause on hover


        $wp_customize->add_setting( 'flex_slide_pause_hover', array(
            'default'        => '1',
        ) );

        $wp_customize->add_control( 'flex_slide_pause_hover', array(
                'label'   => 'Pause slider on hover',
                'description' => 'Pause the slider when a user hovers any of the slides',
                'section' => 'flexslider_setting_general',
                'type'    => 'checkbox',
                'setting' => 'flex_slide_pause_hover'
        ) );

        // Flexslider transition speed options

        $wp_customize->add_section( 'flexslider_navigation', array(
            'title'    => 'Slide navigation arrows',
            'priority' => 40,
            'panel'    => 'flexslider_settings'
        ) );

        $wp_customize->add_setting( 'flex_nav', array(
            'default'        => '1',
        ) );

        $wp_customize->add_control( 'flex_nav', array(
                'label'   => 'Show or hide the navigation',
                'section' => 'flexslider_navigation',
                'type'    => 'checkbox',
                'setting' => 'flex_nav'
        ) );

         $wp_customize->add_setting( 'flex_nav_paging', array(
            'default'        => '1',
        ) );

        $wp_customize->add_control( 'flex_nav_paging', array(
                'label'   => 'Show or hide the paging navigation',
                'section' => 'flexslider_navigation',
                'type'    => 'checkbox',
                'setting' => 'flex_nav_paging'
        ) );

        // Flexslider caption customisation

        $wp_customize->add_section( 'flexslider_typography', array(
            'title'          => 'Caption settings',
            'panel'         => 'flexslider_settings'
        ) );      

  $wp_customize->add_setting( 'flexslider_caption_header', array(
            'default'        => '#ffffff',
        ) );

  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'flexslider_heading_color_setting', array(
            'label'   => 'Heading font color',
            'section' => 'flexslider_typography',
            'settings'   => 'flexslider_caption_header'            
        ) ) );

        // Flexslider caption header size

        $wp_customize->add_setting( 'flexslider_caption_size', array(
            'default'        => '55',
        ) );

        $wp_customize->add_control( 'flexslider_caption_size', array(
                'label'   => 'Heading font size',
                'description' => 'Increase or decrease the caption font size',
                'section' => 'flexslider_typography',
                'type'    => 'text',
                'setting' => 'flexslider_caption_size'
        ) );

        //Flexslider text color

        $wp_customize->add_setting( 'flexslider_caption_text', array(
            'default'        => '#ffffff',
        ) );

  $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'flexslider_text_color_setting', array(
            'label'   => 'Caption text font color',
            'section' => 'flexslider_typography',
            'settings'   => 'flexslider_caption_text'            
        ) ) );

  // Flexslider caption text size

        $wp_customize->add_setting( 'flexslider_text_size', array(
            'default'        => '20',
        ) );

        $wp_customize->add_control( 'flexslider_text_size', array(
                'label'   => 'Caption text font size',
                'description' => 'Increase or decrease the caption text font size',
                'section' => 'flexslider_typography',
                'type'    => 'text',
                'setting' => 'flexslider_text_size'
        ) );

        // Flexslider caption animations

        $wp_customize->add_section( 'flexslider_caption_animation', array(
            'title'    => 'Animation for caption heading',
            'priority' => 41,
            'panel'    => 'flexslider_settings'
        ) );

        $wp_customize->add_setting( 'flex_caption_anim', array(
            'default'        => 'none',
        ) );

        $wp_customize->add_control( 'flex_caption_anim', array(
            'type'    => 'select',
                'label'   => 'Animation of the flexslider caption header',
                'description' => 'This option will animate the main heading of your slide.',
                'section' => 'flexslider_caption_animation',
                'choices' => array(
                    'none' => 'None',
                    'bounceIn' => 'bounce in',
                    'bounceInDown' => 'bounce in down',
                    'bounceInRight' => 'bounce in right',
                    'bounceInUp' => 'bounce in up',
                    'bounceInLeft' => 'bounce in left',
                    'fadeInDownShort' => 'fade in down short',
                    'fadeInUpShort' => 'fade in up short',
                    'fadeInLeftShort' => 'fade in left short',
                    'fadeInRightShort' => 'fade in right short',
                    'fadeInDown' => 'fade in down',
                    'fadeInUp' => 'fade in up',
                    'fadeInLeft' => 'fade in left',
                    'fadeInRight' => 'fade in right',
                    'fadeIn' => 'fade in',
                    'growIn' => 'grow in',
                    'shake' => 'shake',
                    'shakeUp' => 'shake up',
                    'rotateIn' => 'rotate in',
                    'rotateInUpLeft' => 'rotate in up left',
                    'rotateInDownLeft' => 'rotate in down left',
                    'rotateInUpRight' => 'rotate in up right',
                    'rotateInDownRight' => 'rotate in down right',
                    'rollIn' => 'roll in',
                    'wiggle' => 'wiggle',
                    'swing' => 'swing',
                    'tada' => 'tada',
                    'wobble' => 'wobble',
                    'pulse' => 'pulse',
                    'lightSpeedInRight' => 'light speed in right',
                    'lightSpeedInLeft' => 'light speed in left',
                    'flip' => 'flip',
                    'flipInX' => 'flip in x',
                    'flipInY' => 'flip in y'
                    ),

                'setting' => 'flex_caption_anim'
        ) );

    // Flexslider caption text animations

        

        $wp_customize->add_setting( 'flex_caption_text_anim', array(
            'default'        => 'none',
        ) );

        $wp_customize->add_control( 'flex_caption_text_anim', array(
            'type'    => 'select',
                'label'   => 'Animation of the flexslider caption text',
                'description' => 'This option animates any content placed in the slider post excerpt.',
                'section' => 'flexslider_caption_animation',
                'choices' => array(
                    'none' => 'None',
                    'bounceIn' => 'bounce in',
                    'bounceInDown' => 'bounce in down',
                    'bounceInRight' => 'bounce in right',
                    'bounceInUp' => 'bounce in up',
                    'bounceInLeft' => 'bounce in left',
                    'fadeInDownShort' => 'fade in down short',
                    'fadeInUpShort' => 'fade in up short',
                    'fadeInLeftShort' => 'fade in left short',
                    'fadeInRightShort' => 'fade in right short',
                    'fadeInDown' => 'fade in down',
                    'fadeInUp' => 'fade in up',
                    'fadeInLeft' => 'fade in left',
                    'fadeInRight' => 'fade in right',
                    'fadeIn' => 'fade in',
                    'growIn' => 'grow in',
                    'shake' => 'shake',
                    'shakeUp' => 'shake up',
                    'rotateIn' => 'rotate in',
                    'rotateInUpLeft' => 'rotate in up left',
                    'rotateInDownLeft' => 'rotate in down left',
                    'rotateInUpRight' => 'rotate in up right',
                    'rotateInDownRight' => 'rotate in down right',
                    'rollIn' => 'roll in',
                    'wiggle' => 'wiggle',
                    'swing' => 'swing',
                    'tada' => 'tada',
                    'wobble' => 'wobble',
                    'pulse' => 'pulse',
                    'lightSpeedInRight' => 'light speed in right',
                    'lightSpeedInLeft' => 'light speed in left',
                    'flip' => 'flip',
                    'flipInX' => 'flip in x',
                    'flipInY' => 'flip in y'
                    ),

                'setting' => 'flex_caption_text_anim'
        ) );

    // Flexslider caption text animations

        

        $wp_customize->add_setting( 'flex_caption_body_anim', array(
            'default'        => 'none',
        ) );

        $wp_customize->add_control( 'flex_caption_body_anim', array(
            'type'    => 'select',
                'label'   => 'Animation of the flexslider body content',
                'description' => 'This option will animate any content placed in the main slider post editor.',
                'section' => 'flexslider_caption_animation',
                'choices' => array(
                    'none' => 'None',
                    'bounceIn' => 'bounce in',
                    'bounceInDown' => 'bounce in down',
                    'bounceInRight' => 'bounce in right',
                    'bounceInUp' => 'bounce in up',
                    'bounceInLeft' => 'bounce in left',
                    'fadeInDownShort' => 'fade in down short',
                    'fadeInUpShort' => 'fade in up short',
                    'fadeInLeftShort' => 'fade in left short',
                    'fadeInRightShort' => 'fade in right short',
                    'fadeInDown' => 'fade in down',
                    'fadeInUp' => 'fade in up',
                    'fadeInLeft' => 'fade in left',
                    'fadeInRight' => 'fade in right',
                    'fadeIn' => 'fade in',
                    'growIn' => 'grow in',
                    'shake' => 'shake',
                    'shakeUp' => 'shake up',
                    'rotateIn' => 'rotate in',
                    'rotateInUpLeft' => 'rotate in up left',
                    'rotateInDownLeft' => 'rotate in down left',
                    'rotateInUpRight' => 'rotate in up right',
                    'rotateInDownRight' => 'rotate in down right',
                    'rollIn' => 'roll in',
                    'wiggle' => 'wiggle',
                    'swing' => 'swing',
                    'tada' => 'tada',
                    'wobble' => 'wobble',
                    'pulse' => 'pulse',
                    'lightSpeedInRight' => 'light speed in right',
                    'lightSpeedInLeft' => 'light speed in left',
                    'flip' => 'flip',
                    'flipInX' => 'flip in x',
                    'flipInY' => 'flip in y'
                    ),

                'setting' => 'flex_caption_body_anim'
        ) );

}

function ventoux_flexslider_css () {
    ?>

    <style>
        .vf-caption h2 {
            color: <?php echo get_theme_mod('flexslider_caption_header', '#ffffff'); ?>;
            font-size: <?php echo get_theme_mod('flexslider_caption_size', '55'); ?>px;
            text-transform: uppercase;
        }

        .vf-caption, .vf-slider-excerpt {
            color: <?php echo get_theme_mod('flexslider_caption_text', '#ffffff'); ?>;
            font-size: <?php echo get_theme_mod('flexslider_text_size', '18'); ?>px;;
            display: block;
            margin-bottom: 20px;
        }
    </style>

    <?php
}
add_action('wp_head', 'ventoux_flexslider_css' );
add_action( 'customize_register', 'flexslider_customiser' );

