<?php
/**
 * Magazine Style Theme Customizer
 *
 * @package Magazine Style
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'magazinestyle_customize_register' ) ) {
	
	
	
	/**
	 * Register basic support (site title, header text color) for the Theme Customizer.
	 *
	 * @param WP_Customize_Manager $wp_customize Customizer reference.
	 */
	function magazinestyle_customize_register( $wp_customize ) {
		$settings = array( 'blogname', 'header_textcolor' );
		foreach ( $settings as $setting ) {
			$get_setting = $wp_customize->get_setting( $setting );
			if ( $get_setting instanceof WP_Customize_Setting ) {
				$get_setting->transport = 'postMessage';
			}
		}

		// Override default partial for custom logo.
		$wp_customize->selective_refresh->add_partial(
			'custom_logo',
			array(
				'settings'            => array( 'custom_logo' ),
				'selector'            => '.custom-logo-link',
				'render_callback'     => 'magazinestyle_customize_partial_custom_logo',
				'container_inclusive' => false,
			)
		);
		
		class magazinestyle_Important_Links extends WP_Customize_Control {

			public $type = "magazinestyle-important-links";
	  
			public function render_content() {
			
			   echo '<ul><b>
				  <li>' . esc_attr__( '* Fully Mobile Responsive', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Dedicated Option Panel', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Customize Theme Color', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* WooCommerce & bbPress Support', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* SEO Optimized', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Control Individual Meta Option like: Category, date, Author, Tags etc. ', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Full Support', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Google Fonts', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Theme Color Customization', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Custom CSS', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Website Layout', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Select Number of Columns', 'magazine-style' ) . '</li>
				  <li>' . esc_attr__( '* Website Width Control', 'magazine-style' ) . '</li>
				  </b></ul>
			   ';
			   $important_links = array(
			   
				  'theme-info' => array(
					 'link' => esc_url('https://www.insertcart.com/product/magazine-style-wp-theme/'),
					 'text' => __('Magazine Style Pro', 'magazine-style'),
				  ),
				  'support' => array(
					 'link' => esc_url('https://www.insertcart.com/contact-us/'),
					 'text' => __('Contact us', 'magazine-style'),
				  ),         
				  'Documentation' => array(
					 'link' => esc_url('https://www.insertcart.com/magazinestyle-wordpress-theme-setup-and-documentation/'),
					 'text' => __('Documentation', 'magazine-style'),
				  ),			 
			   );
			   foreach ($important_links as $important_link) {
				  echo '<p><a target="_blank" href="' . $important_link['link'] . '" >' . esc_attr($important_link['text']) . ' </a></p>';
			   }
					 }
	  
		 }
			$wp_customize->add_section('magazinestyle_important_links', array(
			'priority' => 1,
			'title' => __('Upgrade to Pro', 'magazine-style'),
			 ));
	  
			 $wp_customize->add_setting('magazinestyle_important_links', array(
				'capability' => 'edit_theme_options',
				'sanitize_callback' => 'magazinestyle_links_sanitize'
			 ));
	  
			 $wp_customize->add_control(new magazinestyle_Important_Links($wp_customize, 'important_links', array(
				'section' => 'magazinestyle_important_links',
				'settings' => 'magazinestyle_important_links'
			 )));
	}
}
add_action( 'customize_register', 'magazinestyle_customize_register' );


if ( ! function_exists( 'magazinestyle_customize_partial_custom_logo' ) ) {
	/**
	 * Callback for rendering the custom logo, used in the custom_logo partial.
	 *
	 * @return string The custom logo markup or the site title.
	 */
	function magazinestyle_customize_partial_custom_logo() {
		if ( has_custom_logo() ) {
			return get_custom_logo();
		} else {
			return get_bloginfo( 'name' );
		}
	}
}


//$dir = MAGAZINESTYLE_INC_DIR . 'customizer/controls/';

if ( ! function_exists( 'magazinestyle_theme_customize_register' ) ) {
	
	function magazinestyle_theme_customize_register( $wp_customize ) {


		class magazinestyle_Customizer_Buttonset_Control extends \WP_Customize_Control {
			//public $type = 'text_radio_button';
			
			public function render_content() {
				?>
				<div class="text_radio_button_control">
				<?php if ( ! empty( $this->label ) ) { ?>
					<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
				<?php } ?>
				<?php if ( ! empty( $this->description ) ) { ?>
					<span class="customize-control-description"><?php echo wp_kses_post( $this->description ); ?></span>
				<?php } ?>				
					<div class="radio-buttons">
						<?php foreach ( $this->choices as $key => $value ) { ?>
							<label class="radio-button-label">
								<input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" <?php $this->link(); checked( $this->value(), $key ); ?>/>
								<span><?php echo esc_html( $value ); ?></span>
							</label>
						<?php	} ?>
					</div>
				</div>
				<?php
			}
		}
	

class magazinestyle_Image_Radio_Control extends \WP_Customize_Control {
    public function render_content() {
        if (empty($this->choices))
            return;

        $name = '_customize-radio-' . $this->id;
        ?>
        <span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
        <ul class="controls" id='magazinestyle-img-container'>
            <?php
            foreach ($this->choices as $value => $label) :
                $class = ($this->value() == $value) ? 'magazinestyle-radio-img-selected magazinestyle-radio-img-img' : 'magazinestyle-radio-img-img';
                ?>
                <li style="display: inline;">
                    <label>
                        <input <?php $this->link(); ?>style = 'display:none' type="radio" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($name); ?>" <?php
                                                      $this->link();
                                                      checked($this->value(), $value);
                                                      ?> />
                        <img src='<?php echo esc_url($label); ?>' class='magazinestyle-radio-img magazinestyle-radio-img-<?php echo esc_attr($value); ?>' />
                    </label>
                </li>
                <?php
            endforeach;
            ?>
        </ul>
		<script>
            (function ($) {
				
                wp.customize.control('magazinestyle_posts_layout', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'magazinestyle-radio-img-selected' class from all images
                        $('ul#magazinestyle-img-container img').removeClass('magazinestyle-radio-img-selected');
                        // Add the 'magazinestyle-radio-img-selected' class to the selected image
                        $('ul#magazinestyle-img-container img.magazinestyle-radio-img-' + value).addClass('magazinestyle-radio-img-selected');
                    });
                });
                wp.customize.control('magazinestyle_sidebar_position', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'magazinestyle-radio-img-selected' class from all images
                        $('ul#magazinestyle-img-container img').removeClass('magazinestyle-radio-img-selected');
                        // Add the 'magazinestyle-radio-img-selected' class to the selected image
                        $('ul#magazinestyle-img-container img.magazinestyle-radio-img-' + value).addClass('magazinestyle-radio-img-selected');
                    });
                });
                wp.customize.control('magazinestyle_container_type', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'magazinestyle-radio-img-selected' class from all images
                        $('ul#magazinestyle-img-container img').removeClass('magazinestyle-radio-img-selected');
                        // Add the 'magazinestyle-radio-img-selected' class to the selected image
                        $('ul#magazinestyle-img-container img.magazinestyle-radio-img-' + value).addClass('magazinestyle-radio-img-selected');
                    });
                });
				  wp.customize.control('magazinestyle_posts_layout', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'magazinestyle-radio-img-selected' class from all images
                        $('ul#magazinestyle-img-container img').removeClass('magazinestyle-radio-img-selected');
                        // Add the 'magazinestyle-radio-img-selected' class to the selected image
                        $('ul#magazinestyle-img-container img.magazinestyle-radio-img-' + value).addClass('magazinestyle-radio-img-selected');
                    });
                });
                wp.customize.control('magazinestyle_header_style', function (control) {
                    control.container.on('change', 'input:radio', function () {
                        var value = $(this).val();
                        control.setting.set(value);

                        // Remove the 'magazinestyle-radio-img-selected' class from all images
                        $('ul#magazinestyle-img-container img').removeClass('magazinestyle-radio-img-selected');
                        // Add the 'magazinestyle-radio-img-selected' class to the selected image
                        $('ul#magazinestyle-img-container img.magazinestyle-radio-img-' + value).addClass('magazinestyle-radio-img-selected');
                    });
                });
				
				
            })(jQuery);
        </script>
			<?php
		}
	}
		
	if ( class_exists( 'WP_Customize_Panel' ) ):
	$wp_customize->register_control_type('magazinestyle_Customizer_Heading_Control');
	
	$magazinestyle_inc_dir = 'inc';
	$magazinestyle_includes_controls = array(
		'/controls/class-control-heading.php',               // Heading Controls.
		'/controls/woocommerce.php',                         // WooCommerce Controls.
		'/controls/footerarea.php',                          // Footer Controls.
		'/controls/headercontrol.php',                       // Header Control.
		'/controls/authorcontrol.php',                       // Author Control.
		'/controls/tagcloudcontrol.php',                       // Author Control.
		'/controls/themeelement.php',                        // Theme element Control.
		'/controls/list-block-posts.php',                    // List block posts Control.
		'/controls/news-ticker.php',                         // News Ticker Control.
		'/controls/block-tiles.php',                         // Block Control.
		'/controls/post-settings.php',                         // Block Control.
		'/controls/post-singles.php',                         // Block Control.
		'/controls/sidebars.php',                         // sidebar
		'/controls/breadcrumbs.php',                         // Breadcrumbs
		'/controls/404errorcontrol.php',                         // 404 error
		'/controls/navigations.php',                         // 404 error
		'/controls/postnavi.php',                         // post navi
		'/controls/scrolltotop.php',                         // scroll to top
	);
	// Include files.
	foreach ( $magazinestyle_includes_controls as $file ) {
		require_once get_theme_file_path( $magazinestyle_inc_dir . $file );
	}
	
	$wp_customize->get_section( 'background_image' )->panel = 'panel_general';
	 $wp_customize->get_section( 'colors' )->panel = 'panel_general';
	$colors_section = $wp_customize->get_section( 'colors' );
	
	
	
	// Add "display_title_and_tagline" setting for displaying the site-title & tagline.
	$wp_customize->add_setting(
		'display_title_and_tagline',
		array(
			'capability'        => 'edit_theme_options',
			'default'           => true,
			'sanitize_callback' => 'magazinestyle_customize_sanitize_checkbox',
		)
	);

	// Add control for the "display_title_and_tagline" setting.
	$wp_customize->add_control(
		'display_title_and_tagline',
		array(
			'type'    => 'checkbox',
			'section' => 'title_tagline',
			'label'   => esc_html__( 'Display Site Title & Tagline', 'magazine-style' ),
		)
	);

    // Check if the section exists
    if ( $colors_section ) {
        // Set a new title for the colors section
        $colors_section->title = __( 'Theme Background Color', 'magazine-style' );
    }
	$wp_customize->add_panel( 'panel_general', array(
			'priority' => 30,
			'capability' => 'edit_theme_options',
			'description' => __( 'Control theme default settings', 'magazine-style' ),
			'priority'    => apply_filters( 'magazinestyle_theme_settings_priority', 150 ),
			'title' => __( 'Theme Settings', 'magazine-style' )
		) );
	/*********************
	Browser Color
	*******************/
	$wp_customize->add_setting(
		'magazinestyle_browser_color', array(
		'default' => '#03A9F4', // Default font color
		'sanitize_callback' => 'sanitize_hex_color',
	));

	$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'magazinestyle_browser_color', array(
		'label' => __('Default Browser Color (Effect only Mobile)', 'magazine-style'),
		'section' => 'colors',
		'settings' => 'magazinestyle_browser_color',
	)));		
		
		$wp_customize->add_section('custom_section_css',
				array(
					'title'			=> __( 'Custom CSS', 'magazine-style' ),			
					'panel'			=> 'panel_general',
					'priority'    => 32
				)
			);
        $wp_customize->add_setting('custom_css',
		array(
			'default'			=> '',
			'type'				=> 'theme_mod',
			'capability'		=> 'edit_theme_options',
			'sanitize_callback'    => 'wp_filter_nohtml_kses',
			'sanitize_js_callback' => 'wp_filter_nohtml_kses'
		)
	);
       $wp_customize->add_control('custom_css',
		array(

			'settings'		=> 'custom_css',
			'section'		=> 'custom_section_css',
			'type'			=> 'textarea',
			'label'			=> __( 'Custom CSS', 'magazine-style' ),
			'description'	=> __( 'Define custom CSS be used for your site. Do not enclose in script tags.', 'magazine-style' ),
		)
	);
	
		/*********************
		Menu settings. Style One
		*******************/
		$wp_customize->add_section(
			'magazinestyle_menu_settings',
			array(
				'title'       => __( 'Menu Settings', 'magazine-style' ),
				'description'       => __( 'Menu Settings', 'magazine-style' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'panel_general',
			)
		);
		
		$wp_customize->add_setting('magazinestyle_topside',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'magazinestyle_customize_sanitize_select'
			));
		$wp_customize->add_control('magazinestyle_topside',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Woocommerce/Search Bar in Right','magazine-style'),
				'settings'   => 'magazinestyle_topside',
				'section' => 'magazinestyle_theme_settings',
				'choices' => array(
					'enable' => __('Enable','magazine-style'),
					'disable' => __('Disable','magazine-style'),
				 ),
			 ));		

		
		/*********************
		Social Links
		*******************/
		$wp_customize->add_section('magazinestyle_sociallinks',
			array(
				'title'       => __( 'Social Links', 'magazine-style' ),
				'description'       => __( 'Author Profile Control on Posts and Archive Pages (Make Sure to fill all detail to show profile in Dashboard > Users > Profile)', 'magazine-style' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'magazinestyle_theme_elements',
			));
			
		// Add setting for social media links style
    $wp_customize->add_setting('social_links_style', array(
        'default' => 'rounded-circle',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    // Add control for social media links style
    $wp_customize->add_control('social_links_style', array(
        'label' => __('Social Links Style', 'magazine-style'),
        'section' => 'magazinestyle_sociallinks',
        'type' => 'select',
        'choices' => array(
            'rounded' => __('Round', 'magazine-style'),
            'rounded-circle' => __('Circle', 'magazine-style'),
            'rounded-0' => __('Tile', 'magazine-style'),
        ),
    ));	
	$social_media_platforms = array(
        'facebook' => __('Facebook', 'magazine-style'),
        'twitter' => __('Twitter', 'magazine-style'),
        'whatsapp' => __('WhatsApp', 'magazine-style'),
        'calling' => __('Calling', 'magazine-style'),
        'youtube' => __('YouTube', 'magazine-style'),		
		'telegram' => __('Telegram', 'magazine-style'),
    );

    foreach ($social_media_platforms as $platform => $label) {
        $wp_customize->add_setting("social_media_$platform", array(
            'default' => '#',
            'sanitize_callback' => 'esc_url_raw',
        ));

        $wp_customize->add_control("social_media_$platform", array(
            'label' => $label . ' URL',
            'section' => 'magazinestyle_sociallinks',
            'type' => 'text',
        ));
    }
		
		/*********************
		Google Fonts
		*******************/
		$wp_customize->add_section('magazinestyle_google_font',
			array(
				'title'       => __( 'Google Fonts', 'magazine-style' ),
				'description'       => __( 'Google Fonts Settings', 'magazine-style' ),
				'capability'  => 'edit_theme_options',						
				'panel'			=> 'panel_general',
			)
		);
		$font_array = array('Raleway','Khula','Open Sans','Poppins','Futura','Indie Flower','Droid Sans','Droid Serif','Roboto','Roboto Condensed','Lato','Bree Serif','Oswald','Slabo','Lora','Source Sans Pro','PT Sans','Ubuntu','Lobster','Arimo','Bitter','Noto Sans','Fjalla One','PT Sans Narrow','Poiret One','Passion One','Arvo','Inconsolata','Shadows Into Light','Pacifico','Dancing Script','Architects Daughter','Sigmar One','Righteous','Amatic SC','Orbitron','Chewy','Lobster Two','Gloria Hallelujah','Lekton','Almendra Display','Swanky and Moo Moo','Hanalei Fill','Uncial Antiqua','Rouge Script','Engagement','Bonbon','Caesar Dressing','Kenia','Lemon','Stardos Stencil','Bilbo','Macondo','Delius Unicase','Butcherman','Monoton','Nosifer','Codystar','Fontdiner Swanky','Diplomata SC','Snowburst One','Faster One','Rock Salt','Eater','Noto Sans JP','Montserrat','Fira Sans','Baloo Tamma 2','AR One Sans','Alegreya','Anek Kannada','Anek Odia','Anek Tamil','Anek Devanagari');
		$fonts = array_combine($font_array, $font_array);

		$wp_customize->add_setting('magazinestyle_enablefonts',	
			array(
				'default'			=> 'disable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'magazinestyle_customize_sanitize_select'
			));
		
		$wp_customize->add_control('magazinestyle_enablefonts',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Google Fonts','magazine-style'),
				'settings'   => 'magazinestyle_enablefonts',
				'section' => 'magazinestyle_google_font',
				'choices' => array(
					'enable' => __('Enable','magazine-style'),
					'disable' => __('Disable','magazine-style'),
				 ),
			 ));
		
	
		$wp_customize->add_setting(
		'magazinestyle_body_font',
			array(	
			'default'=> 'Open Sans',
			'sanitize_callback' => 'magazinestyle_sanitize_gfont' 
		));

		$wp_customize->add_control(
			'magazinestyle_body_font',array(
					'label' => __('Body Font Family','magazine-style'),
					'settings' => 'magazinestyle_body_font',
					'section'  => 'magazinestyle_google_font',
					'type' => 'select',
					'choices' => $fonts
			));
		
	

		
		/*********************
		Theme settings.
		*******************/
		$wp_customize->add_section(
			'magazinestyle_theme_settings',
			array(
				'title'       => __( 'Preloading Bar', 'magazine-style' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Effects while loading your website', 'magazine-style' ),							
				'panel'			=> 'panel_general',
			));			
		
			
			$wp_customize->add_setting('magazinestyle_loading_animation',	
			array(
				'default'			=> 'enable',
				'type'				=> 'theme_mod',
				'capability'		=> 'edit_theme_options',
				'sanitize_callback'	=> 'magazinestyle_customize_sanitize_select'
			));
		$wp_customize->add_control('magazinestyle_loading_animation',
			 array (                             
				'type' => 'radio',
				'label' => __('Enable Loading Animation','magazine-style'),
				'settings'   => 'magazinestyle_loading_animation',
				'section' => 'magazinestyle_theme_settings',
				'choices' => array(
					'enable' => __('Enable','magazine-style'),
					'disable' => __('Disable','magazine-style'),
				 ),
			 ));

			// Add a control to choose the loading bar color
			$wp_customize->add_setting('magazinestyle_loading_bar_color', array(
				'default' => '#ff3030',
				'transport' => 'refresh',
				'sanitize_callback'	=> 'sanitize_hex_color',
			));

			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'magazinestyle_loading_bar_color', array(
				'label' => __('Loading Bar Color', 'magazine-style'),
				'section' => 'magazinestyle_theme_settings',
			)));


		

//Woocommerce Sidebar
		$wp_customize->add_section('magazinestyle_woosidebars_section',
        array(
            'title' => __( 'Sidebar', 'magazine-style' ),
            'description' => __( 'Sidebar Panel', 'magazine-style' ),
            'capability'  => 'edit_theme_options',		
            'panel'			=> 'woocommerce',
            'priority'    => apply_filters( 'magazinestyle_sidebars_section_priority', 10 ),
        ));
        $wp_customize->add_setting('magazinestyle_woo_sides',	
        array(
            'default'			=> 'disable',
            'type'				=> 'theme_mod',
            'capability'		=> 'edit_theme_options',
            'sanitize_callback'	=> 'magazinestyle_customize_sanitize_select'
        ));
        $wp_customize->add_control('magazinestyle_woo_sides',
            array (                             
            'type' => 'radio',
            'label' => __('WooCommerce Sidebars','magazine-style'),
            'settings'   => 'magazinestyle_woo_sides',
            'section' => 'magazinestyle_woosidebars_section',
            'choices' => array(
                'enable' => __('Enable','magazine-style'),
                'disable' => __('Disable','magazine-style'),
                ),
            ));
			 
endif;	 



	/*********************
    Schema Markup
    *******************/
	$wp_customize->add_section('magazinestyle_schema_markup',
    array(
        'title'       => __( 'Schema', 'magazine-style' ),
        'capability'  => 'edit_theme_options',						
        'panel'			=> 'panel_general',
        'priority'    => apply_filters( 'magazinestyle_postnavi_section_priority', 10 ),
    ));
$wp_customize->add_setting(
    'magazinestyle_enable_schema',
    array(
        'capability'        => 'edit_theme_options',
        'default'           => false,
        'sanitize_callback' => 'magazinestyle_customize_sanitize_checkbox',
    )
);
$wp_customize->add_control(
    'magazinestyle_enable_schema',
    array(
        'type'    => 'checkbox',
        'section' => 'magazinestyle_schema_markup',
        'label'   => esc_html__( 'Enable Schema', 'magazine-style' ),
    )
);

			
// Theme layout settings.
		$wp_customize->add_section(
			'magazinestyle_theme_layout_options',
			array(
				'title'       => __( 'Theme Layout Settings', 'magazine-style' ),
				'capability'  => 'edit_theme_options',
				'description' => __( 'Container width and sidebar defaults', 'magazine-style' ),
				'priority'    => apply_filters( 'magazinestyle_theme_layout_options_priority', 160 ),
			)
		);

		$wp_customize->add_setting(
			'magazinestyle_container_type',
			array(
				'default'           => 'container',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'magazinestyle_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new magazinestyle_Image_Radio_Control(
				$wp_customize,
				'magazinestyle_container_type',
				array(
					'label'       => __( 'Container Width', 'magazine-style' ),
					'description' => __( 'Choose between Fixed or Full width container', 'magazine-style' ),
					'section'     => 'magazinestyle_theme_layout_options',
					'choices'     => array(
						'container-fluid'  => get_template_directory_uri() . '/images/widthfull.png',
						'container' => get_template_directory_uri() . '/images/widthfixed.png',
						'container-box' => get_template_directory_uri() . '/images/widthbox.png',
					),
					'priority'    => apply_filters( 'magazinestyle_container_type_priority', 10 ),
				)
			));

		$wp_customize->add_setting(
			'magazinestyle_content_background',
			array(
				'default'           => 'contentdefault',
				'type'              => 'theme_mod',
				'sanitize_callback' => 'magazinestyle_customize_sanitize_select',
				'capability'        => 'edit_theme_options',
			)
		);
		
		
		$wp_customize->add_control(
			new magazinestyle_Image_Radio_Control(
				$wp_customize,
				'magazinestyle_content_background',
				array(
					'label'       => __( 'Content Background (Blended / Separated )', 'magazine-style' ),
					'description' => __( 'Choose website content Full background or Content only', 'magazine-style' ),
					'section'     => 'magazinestyle_theme_layout_options',
					'choices'     => array(
						'contentdefault'  => get_template_directory_uri() . '/images/c.png',
						'contentblock' => get_template_directory_uri() . '/images/contentblock.png',
					),
					'priority'    => apply_filters( 'magazinestyle_container_type_priority', 30 ),
				)
			));

		$magazinestyle_site_info = $wp_customize->get_setting( 'magazinestyle_site_info_override' );
		if ( $magazinestyle_site_info instanceof WP_Customize_Setting ) {
			$magazinestyle_site_info->transport = 'postMessage';
		}
		
		
	}

	
	
} // End of if function_exists( 'magazinestyle_theme_customize_register' ).
add_action( 'customize_register', 'magazinestyle_theme_customize_register' );


function magazinestyle_customize_sanitize_checkbox( $checked ) {
    // Check if the checkbox is checked.
    return ( ( isset( $checked ) && true === $checked ) ? true : false );
}

if ( ! function_exists( 'magazinestyle_customize_sanitize_select' ) ) {
	function magazinestyle_customize_sanitize_select( $input, $setting ) {

		// Ensure input is a slug (lowercase alphanumeric characters, dashes and underscores are allowed only).
		$input = sanitize_key( $input );

		$control = $setting->manager->get_control( $setting->id );
		if ( ! $control instanceof WP_Customize_Control ) {
			return false;
		}

		// Get the list of possible select options.
		$choices = $control->choices;

		// If the input is a valid key, return it; otherwise, return the default.
		return ( array_key_exists( $input, $choices ) ? $input : $setting->default );
	}
}



/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
 
 function magazinestyle_customize_preview_js() {
	$file = '/js/customizer.js';
	$files = '/js/customizer-controls.js';

	$url = get_template_directory_uri() . $file;
	$urls = get_template_directory_uri() . $files;
	$version = filemtime( get_template_directory() . $file );
	if ( false === $version ) {
		$version = time();
	}

	wp_enqueue_script(
		'magazinestyle_customizer_result',
		$url,
		array( 'customize-preview' ),
		(string) $version,
		true
	);
	wp_enqueue_script( 'magazinestyle-customizer-preview', $urls , array( 'customize-preview', 'jquery' ) );
}
add_action( 'customize_preview_init', 'magazinestyle_customize_preview_js' );



function magazinestyle_is_post_meta_enabled($control) {
	return get_theme_mod('magazinestyle_blog_postmeta', 'enable') === 'enable';
}

function magazinestyle_header_selected_styleone($control) {
    return get_theme_mod('magazinestyle_header_style', 'styleone') === 'styleone';
}

function magazinestyle_header_selected_styletwo($control) {
    return get_theme_mod('magazinestyle_header_style', 'styletwo') === 'styletwo';
}

function magazinestyle_header_selected_stylethree($control) {
    return get_theme_mod('magazinestyle_header_style', 'stylethree') === 'stylethree';
}

function magazinestyle_header_selected_stylefour($control) {
    return get_theme_mod('magazinestyle_header_style', 'stylefour') === 'stylefour';
}

function magazinestyle_header_selected_stylefive($control) {
    return get_theme_mod('magazinestyle_header_style', 'stylefive') === 'stylefive';
}
function magazinestyle_is_readmore_enabled($control) {
	return get_theme_mod('magazinestyle_enable_readmore', 'enable') === 'enable';
}

function magazinestyle_sanitize_gfont( $input ) {
		if ( in_array($input, array('Raleway','Khula','Open Sans','Poppins','Futura','Indie Flower','Droid Sans','Droid Serif','Roboto','Roboto Condensed','Lato','Bree Serif','Oswald','Slabo','Lora','Source Sans Pro','PT Sans','Ubuntu','Lobster','Arimo','Bitter','Noto Sans','Fjalla One','PT Sans Narrow','Poiret One','Passion One','Arvo','Inconsolata','Shadows Into Light','Pacifico','Dancing Script','Architects Daughter','Sigmar One','Righteous','Amatic SC','Orbitron','Chewy','Lobster Two','Gloria Hallelujah','Lekton','Almendra Display','Swanky and Moo Moo','Hanalei Fill','Uncial Antiqua','Rouge Script','Engagement','Bonbon','Caesar Dressing','Kenia','Lemon','Stardos Stencil','Bilbo','Macondo','Delius Unicase','Butcherman','Monoton','Nosifer','Codystar','Fontdiner Swanky','Diplomata SC','Snowburst One','Faster One','Rock Salt','Eater','Noto Sans JP','Montserrat','Fira Sans','Baloo Tamma 2','AR One Sans','Alegreya','Anek Kannada','Anek Odia','Anek Tamil','Anek Devanagari') ) )
			return $input;
		else
			return '';	
	}
	
if ( ! function_exists( 'magazinestyle_headerone' ) ) {
	function magazinestyle_headerone( $current_mod ) {

		if ( 'styletwo' !== get_theme_mod( 'magazinestyle_header_style' ) ) {
			$current_mod = 'enable';
		}

		return $current_mod;
	}
}
add_filter( 'theme_mod_magazinestyle_heroarea', 'magazinestyle_headerone', 30 );	

add_action( 'customize_controls_print_scripts','magazinestyle_enqueue_scripts' );
function magazinestyle_enqueue_scripts() {
	$filess = '/js/customizer-controls.js';

	$urll = get_template_directory_uri() . $filess;
	wp_enqueue_script(
		'magazinestyle-options-reset',
		$urll,
		array( 'jquery' ),
		'2143132',
		false
	);
	
}

add_action( 'wp_ajax_customizer_reset', 'magazinestyle_remove_theme_modifications' );
function magazinestyle_remove_theme_modifications() {
	global $wp_customize, $options;

	// Bail early if we are not in preview mode.
	if ( ! $wp_customize->is_preview() ) {
		wp_send_json_error( 'not_preview' );
	}

	// Bail early if nonce is invalid.
	if ( ! check_ajax_referer( 'customizer-reset', 'nonce', false ) ) {
		wp_send_json_error( 'invalid_nonce' );
	}

	$settings = apply_filters( 'customizer_reset_settings', $wp_customize->settings() );

	if ( ! empty( $settings ) ) {
		foreach ( $settings as $setting ) {
			if ( 'theme_mod' === $setting->type ) {
				remove_theme_mod( $setting->id );
			}
		}
	}
	wp_send_json_success();
}

// Sanitize Select Callback
function magazinestyle_customize_sanitize_selectnew( $input, $setting ) {
    $valid = array(
        'styleone' => __( 'Enable', 'magazine-style' ),
        'styletwo' => __( 'Disable', 'magazine-style' ),
    );

    if ( array_key_exists( $input, $valid ) ) {
        return $input;
    } else {
        return '';
    }
}
