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

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
function wheelify_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' => 'wheelify_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'wheelify_customize_partial_blogdescription',
			)
		);
	}
}
add_action( 'customize_register', 'wheelify_customize_register' );

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

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

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


<?php 
/***
    *** Register Customizer Add Panel Function Code start Here
***/
function wheelify_Theme_Register_Customizer_Add_Panel_Function( $wp_customize ) {

	// Create Custom Aanel for Home Page.
	$wp_customize->add_panel( 'Wheelify_Theme_Custom_Add_Panel_Function', array(
		'theme_supports' => '',
		'title'          => __( ' Wheelify Theme Options ', 'wheelify' ),
		'priority' => 1,
	) ); 
}
add_action( 'customize_register', 'wheelify_Theme_Register_Customizer_Add_Panel_Function' );
/***
    *** Register Customizer Add Panel Function Code END Here
***/
?>

<?php 
/***
    *** Register Customizer Home Banner Section Code start Here
***/
class Wheelify_Banner_Section_Customizer {

	public static function wheelify_Register_Theme_Customizer_For_Home_Banner_Section( $wp_customize ) {

		// Add Home Banner Section Add Section for home page.
		$wp_customize->add_section( 'Wheelify_Section_For_Home_Page_Banner_Section' , array(
			'title'    => __(' Home Banner Section ','wheelify'),
			'panel'    => 'Wheelify_Theme_Custom_Add_Panel_Function',
			'priority' => 1,
		) );

		//  ============================================================
	    //       Home Page Banner Section Image Upload         
	    //  ============================================================
	    $wp_customize->add_setting( 'wheelify_Setting_For_Home_Banner_Section_Image_Upload', array( 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
	    )); 
	        	   
	    $wp_customize->add_control( new WP_Customize_Image_Control( 
	    	$wp_customize, 'Wheelify_Theme_Home_Banner_Section_Image_Upload_Id', array(
	        'label'    => ' Banner Image ',
	        'priority' => 1,
	        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
	        'settings' => 'wheelify_Setting_For_Home_Banner_Section_Image_Upload',
	        'button_labels' => array(
	                    // All These labels are optional
	                    'select' => __( 'Select Image', 'wheelify' ),
	                    'remove' => __( 'Remove Image', 'wheelify' ),
	                    'change' => __( 'Change Image', 'wheelify' )
	                    )
	    )));

		//  ============================================================
	    //       Home Page Banner Section Section Title        
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_Setting_For_Home_Page_Banner_Section_Title_Name', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			
		) );

		// Add Banner Title Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Wp_Theme_Home_Banner_Section_Title_Name_ID',
			    array(
			        'label'    => __( ' Banner Title ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_Setting_For_Home_Page_Banner_Section_Title_Name',
			        'type'     => 'text',
			        'priority' => 2,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Content        
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_Setting_For_Home_Page_Banner_Section_Content_Textarea', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			
		) );

		// Add Banner Content Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'WP_Theme_Wheelify_custom_Home_Banner_Section_Main_Content',
			    array(
			        'label'    => __( ' Banner Content ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_Setting_For_Home_Page_Banner_Section_Content_Textarea',
			        'type'     => 'textarea',
			        'priority' => 3,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Button Text         
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_Setting_For_Home_Banner_Section_Button_Text', array(
			 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			 
		) );

		// Button Text Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_custom_Home_Banner_Section_Button_Text',
			    array(
			        'label'    => __( ' Button Text ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_Setting_For_Home_Banner_Section_Button_Text',
			        'type'     => 'text',
			        'priority' => 4,
			    )
		    )
		);

		//  ============================================================
	    //       Home Page Banner Section Button Url Path          
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_Setting_For_Home_Banner_Btn_URl_Path', array(
			 'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
			 
		) );

		// Add Button Url Path Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Home_Banner_Section_Custom_Button_URl_Path',
			    array(
			        'label'    => __( ' Button Url ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_Setting_For_Home_Banner_Btn_URl_Path',
			        'type'     => 'text',
			        'priority' => 5,
			    )
		    )
		);

		//  ============================================================
	    //       Home Banner Section Button Text Second       
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_For_Home_Banner_Section_Button_Text_Second', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',
		) );

		// Add Banner Section Button Text Second 
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Theme_Home_Banner_Section_Buuton_Text_Second_ID',
			    array(
			        'label'    => __( ' Second Button Text ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_For_Home_Banner_Section_Button_Text_Second',
			        'type'     => 'text',
			        'priority' => 6,
			    )
		    )
		);

		//  ============================================================
	    //       Home Banner Section Button URI For Second Button        
	    //  ============================================================
		$wp_customize->add_setting( 'Wheelify_For_Home_Banner_Section_Second_Button_Settings', array(
			'sanitize_callback' => 'Home_Banner_Section_Sanitize_Text_Function',			
		) );

		// Add Banner Section Button Link /url Second Add control Here
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Custom_Home_Banner_Section_NameSecond_Button_Link',
			    array(
			        'label'    => __( ' Second Button Link ', 'wheelify' ),
			        'section'  => 'Wheelify_Section_For_Home_Page_Banner_Section',
			        'settings' => 'Wheelify_For_Home_Banner_Section_Second_Button_Settings',
			        'type'     => 'text',
			        'priority' => 7,
			    )
		    )
		);

	    // Sanitize Text Function For Home Banner
		function Home_Banner_Section_Sanitize_Text_Function( $text ) {
		    return sanitize_text_field( $text );
		}
	}
}
add_action( 'customize_register', array('Wheelify_Banner_Section_Customizer', 'wheelify_Register_Theme_Customizer_For_Home_Banner_Section') );
/***
    *** Register Customizer Home Banner Section Code END Here
***/


/***
    *** Register Customizer Blog Section Code start Here
***/
class Wheelify_Blog_Section_Customizer {

	public static function Wheelify_Register_Theme_Customizer_For_Blog_Section( $wp_customize ) {

		// Add Blog Section
		$wp_customize->add_section( 'Wheelify_Theme_Section_For_Blog_Section' , array(
			'title'    => __(' Blog Section ','wheelify'),
			'panel' => 'Wheelify_Theme_Custom_Add_Panel_Function',
		) );

		/*******************************************************************************
		                    Blog Section Title Text Code 
		********************************************************************************/
		$wp_customize->add_setting( 'Wheelify_Setting_For_Blog_Section_Title', array(
	       'sanitize_callback' => 'Wheelify_Blog_Section_Page_Sanitize_Text',
		) );

		// Add Blog Section Title Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Theme_Blog_Section_Title_ID',
			    array(
			        'label'    => __( ' Blog Section Title ', 'wheelify' ),
			        'section'  => 'Wheelify_Theme_Section_For_Blog_Section',
			        'settings' => 'Wheelify_Setting_For_Blog_Section_Title',
			        'type'     => 'text',
			        'priority' => 1,
			    )
		    )
		);

		/*******************************************************************************
		                    Blog Section Title Description Code 
		********************************************************************************/
		$wp_customize->add_setting( 'Wheelify_Setting_For_Blog_Section_Description', array(
	       'sanitize_callback' => 'Wheelify_Blog_Section_Page_Sanitize_Text',
		) );

		// Add Blog Section Description Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Theme_Blog_Section_Description_Id',
			    array(
			        'label'    => __( ' Blog Section Description ', 'wheelify' ),
			        'section'  => 'Wheelify_Theme_Section_For_Blog_Section',
			        'settings' => 'Wheelify_Setting_For_Blog_Section_Description',
			        'type'     => 'textarea',
			        'priority' => 2,
			    )
		    )
		);

		$categories = get_categories();

		$cats = array();
		$i = 0;
		foreach($categories as $category){
		    if($i==0){
		        $default = $category->slug;
		        $i++;
		    }
		    $cats[$category->slug] = $category->name;
		}

		$wp_customize->add_setting('Blog_Section_Home_Page_Featured_Category', array(
	       'sanitize_callback' => 'Wheelify_Blog_Section_Page_Sanitize_Text',
		));

		$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'Blog_Section_Home_Page_Featured_Category', array(
		    'label' => 'Blog Show Base On Category',
		    'description' => 'In Home Template Only upto 6 Blog Post Display.', 
		    'section' => 'Wheelify_Theme_Section_For_Blog_Section',
		    'settings' => 'Blog_Section_Home_Page_Featured_Category',
		    'type'    => 'select',
		    'choices' => $cats
		)));
		
		$wp_customize->add_setting( 'blog_content',
		   array(
			  'type'              => 'theme_mod',
			  'default' => '',
			  'sanitize_callback' => 'absint',
			  'capability'        => 'edit_theme_options',
		   )
		);
		
		$wp_customize->add_control( 'blog_content',
		   array(
			  'label' => __( 'Choose content option for blog, archive page','wheelify' ),
			  'section' => 'Wheelify_Theme_Section_For_Blog_Section',
			  'priority' => 10,
			  'type' => 'select',
			  'capability' => 'edit_theme_options',
			  'choices' => array( 
				 '1' => __( 'Excerpt','wheelify' ),
				 '2' => __( 'Full-Content','wheelify' ),
			  )
		   )
		);
		
		$wp_customize->add_setting( 'enable_scroll', 
				array(
				 'type' => 'theme_mod',
				 'default'=>1,
				 'sanitize_callback' => 'wheelify_sanitize_checkbox',
			));
			
			$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'enable_scroll', array(
			'type'=>'checkbox',
			'label'   => esc_html__('Enable Scroll to top button','wheelify'),
			'section' => 'Wheelify_Theme_Section_For_Blog_Section',
			)));

	    // Sanitize Text Function For Home Blog  Section
		function Wheelify_Blog_Section_Page_Sanitize_Text( $text ) {
		    return sanitize_text_field( $text );
		}	
		function wheelify_sanitize_checkbox( $checked ) {
			// Boolean check.
			return ( ( isset( $checked ) && true == $checked ) ? true : false );
		}

	}
	
}
add_action( 'customize_register', array('Wheelify_Blog_Section_Customizer', 'Wheelify_Register_Theme_Customizer_For_Blog_Section') );













/***
    *** Footer Section
***/
class Wheelify_Footer_Section_Customizer {
public static function Wheelify_Register_Theme_Customizer_For_Footer_Section( $wp_customize ) {
		 $wp_customize->add_section(
            'Wheelify_Theme_Section_For_Footer_Section',
            array(
                'title'    => esc_html__( 'Footer Section', 'wheelify' ),
                'priority' => 20,
				'panel' => 'Wheelify_Theme_Custom_Add_Panel_Function',
            )
        );
		
/****** Enable Footer Widget Area *****/

$wp_customize->add_setting(
            'Wheelify_footer_areas',
            array(
                 'type' => 'theme_mod',
				 'default'=>1,
				'sanitize_callback' => 'Wheelify_sanitize_checkbox',
            )
       );
		$wp_customize->add_control(
            new WP_Customize_Control(
                $wp_customize,
                'Wheelify_footer_areas',
                array(
				    'label'   => esc_html__('Enable Footer Widget Area','wheelify'),
                    'type'            => 'checkbox',
                    'section'         => 'Wheelify_Theme_Section_For_Footer_Section',
                    
                )
            )
        );
		
		
		
		
		
		

        // Sanitize Text Function For Footer Section
        function Wheelify_Footer_Section_Page_Sanitize_Text( $text ) {
            return sanitize_text_field( $text );
        }

    }

}

add_action( 'customize_register', array( 'Wheelify_Footer_Section_Customizer', 'Wheelify_Register_Theme_Customizer_For_Footer_Section' ) );





/***
    *** Register Customizer Blog Section Code End Here
***/


/***
    *** Register Customizer 404 Page Section Code start Here
***/
class Wheelify_404_Page_Section_Customizer {

	public static function Wheelify_Register_Theme_Customizer_For_404_Page_Section( $wp_customize ) {

		// Add 404 Page Section
		$wp_customize->add_section( 'Wheelify_Theme_Section_For_404_Page_Section' , array(
			'title'    => __(' 404 Page Section ','wheelify'),
			'panel' => 'Wheelify_Theme_Custom_Add_Panel_Function',
		) );

		/*******************************************************************************
		                    404 Page Section Title
		********************************************************************************/
		$wp_customize->add_setting( 'Wheelify_Setting_For_404_Page_Section_Title', array(
			'sanitize_callback' => 'Wheelify_404_Page_Section_Page_Sanitize_Text',
		 ) );
 
		 // Add 04 Page Main Title Section Title Add control
		 $wp_customize->add_control( new WP_Customize_Control(
			 $wp_customize,
			 'Wheelify_Setting_For_404_Page_Section_Title',
				 array(
					 'label'    => __( ' 404 Page Main Title ', 'wheelify' ),
					 'section'  => 'Wheelify_Theme_Section_For_404_Page_Section',
					 'settings' => 'Wheelify_Setting_For_404_Page_Section_Title',
					 'type'     => 'text',
					 'priority' => 1,
				 )
			 )
		 );

		/*******************************************************************************
		                    404 Page Section For Button Label In 404 Page
		********************************************************************************/
		$wp_customize->add_setting( 'Wheelify_Setting_For_404_Page_Section_Button_Label', array(
	       'sanitize_callback' => 'Wheelify_404_Page_Section_Page_Sanitize_Text',
		) );

		// Add 404 Page Section Button Label Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Theme_404_Page_Section',
			    array(
			        'label'    => __( ' Button Label For 404 Page ', 'wheelify' ),
			        'section'  => 'Wheelify_Theme_Section_For_404_Page_Section',
			        'settings' => 'Wheelify_Setting_For_404_Page_Section_Button_Label',
			        'type'     => 'text',
			        'priority' => 1,
			    )
		    )
		);

		/*******************************************************************************
		                    404 Page Section Title Description Code 
		********************************************************************************/
		$wp_customize->add_setting( 'Wheelify_Setting_For_404_Page_Section_Description', array(
	       'sanitize_callback' => 'Wheelify_404_Page_Section_Page_Sanitize_Text',
		) );

		// Add 404 Page Section Description Add control
		$wp_customize->add_control( new WP_Customize_Control(
		    $wp_customize,
			'Wheelify_Setting_For_404_Page_Section_Description',
			    array(
			        'label'    => __( ' 404 Page Description ', 'wheelify' ),
			        'section'  => 'Wheelify_Theme_Section_For_404_Page_Section',
			        'settings' => 'Wheelify_Setting_For_404_Page_Section_Description',
			        'type'     => 'textarea',
			        'priority' => 2,
			    )
		    )
		);

		// Add Settings For 404 Page Button
		$wp_customize->add_setting( 'Wheelify_404_Page_Button_background', array(
			'default' => '#f4c201',
			'sanitize_callback' => 'Wheelify_404_Page_sanitize_color',

		));

		// Add Controls For 404 Page Button
		$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'Wheelify_404_Page_Button_background', array(
			'label' => '404 Page Button background',
			'section' => 'Wheelify_Theme_Section_For_404_Page_Section',
			'settings' => 'Wheelify_404_Page_Button_background'
		)));

		/**
		 * Color sanitization callback
		*/
		function Wheelify_404_Page_sanitize_color( $color ) {
			if ( empty( $color ) || is_array( $color ) ) {
				return '';
			}

			// If string does not start with 'rgba', then treat as hex.
			// sanitize the hex color and finally convert hex to rgba
			if ( false === strpos( $color, 'rgba' ) ) {
				return sanitize_hex_color( $color );
			}

			// By now we know the string is formatted as an rgba color so we need to further sanitize it.
			$color = str_replace( ' ', '', $color );
			sscanf( $color, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );

			return 'rgba('.$red.','.$green.','.$blue.','.$alpha.')';
		}
		 
		/**
		 * Text sanitization callback
		*/
		function Wheelify_404_Page_Section_Page_Sanitize_Text( $text ) {
		    return sanitize_text_field( $text );
		}	

	}
}
add_action( 'customize_register', array('Wheelify_404_Page_Section_Customizer', 'Wheelify_Register_Theme_Customizer_For_404_Page_Section') );
/***
    *** Register Customizer 404 Page Section Code End Here
***/
?>