<?php 
/*-----------------------------------------------------------------------------------*/
/* MOVE THEME SETTINGS TO WORDPRESS CUSTOMIZER
/*-----------------------------------------------------------------------------------*/

if ( ! function_exists('kktfwp_settings_update') ) {
	function kktfwp_settings_update() {
		
		if ( get_option( 'kktfwpSettingsUpdated' ) === 'true' ) return;
		
		// Old settings to new
		$options_arr = array(			
			'toppic_theme_content_style' => 'kktfwp_content_width',					
			'toppic_theme_gallery_fullscreen_delay' => 'kktfwp_fs_gallery_lenght',					
			'toppic_theme_gallery_fullscreen_transition' => 'kktfwp_fs_gallery_transition',					
			'toppic_theme_gallery_fullscreen_effect' => 'kktfwp_fs_gallery',					
			'toppic_theme_blog_sidebar' => 'kktfwp_blog_sidebar', 				
			'toppic_theme_ken_b_zoom' => 'kktfwp_kenb_zoom',					
			'toppic_theme_ken_b_frames' => 'kktfwp_kenb_fps',					
			'toppic_theme_ken_b_delay' => 'kktfwp_kenb_lenght',					
			'toppic_theme_ken_b_transition' => 'kktfwp_kenb_transition',					
			'toppic_theme_fullscreen_delay' => 'kktfwp_slider_lenght',					
			'toppic_theme_fullscreen_transition' => 'kktfwp_slider_transition',					
			'toppic_theme_fullscreen_effect' => 'kktfwp_slider_effect',					
			'toppic_theme_fullscreen_stream' => 'kktfwp_slider_type',					
			'toppic_theme_color_scheme_links' => 'kktfwp_secondary_accent_color',					
			'toppic_theme_color_scheme' => 'kktfwp_accent_color',					
			'toppic_theme_skin_color' => 'kktfwp_skin',					
			'toppic_theme_menu_opacity' => 'kktfwp_menu_opacity',					
			'toppic_theme_menu_links_color' => 'kktfwp_menu_txt_color',					
			'toppic_theme_menu_color' => 'kktfwp_menu_bg_color',					
			'toppic_theme_menu_style' => 'kktfwp_menu_style',					
			'toppic_theme_protection_message' => 'kktfwp_protection_message',					
			'toppic_theme_content_protection' => array( 'kktfwp_protection' ),
			'toppic_theme_search_button' => array( 'kktfwp_search_btn' ),
			'toppic_theme_con_res' => array( 'kktfwp_responsive' ),
			'toppic_theme_kk_page_anim' => array( 'kktfwp_animation' ),
			'toppic_theme_fullscreen_start_slide' => array( 'kktfwp_slider_random' ),
			'toppic_theme_gallery_fullscreen_autoplay' => array( 'kktfwp_fs_gallery_autoplay' ),
			'toppic_theme_gallery_fullscreen_loop' => array( 'kktfwp_fs_gallery_loop' ),
			'toppic_theme_is_border' => array( 'kktfwp_borders' ),
		);
		
		foreach ( $options_arr as $old_setting => $new_setting ) {
			if ( !empty( get_option( $old_setting ) ) && !is_array( $new_setting ) ) {
				set_theme_mod( $new_setting, get_option( $old_setting ) );
				//delete_option( $old_setting );
			} else if ( !empty( get_option( $old_setting ) ) ) {
				( get_option( $old_setting ) === 'true' ) ? set_theme_mod( $new_setting[0], 1 ) : set_theme_mod( $new_setting[0], 0 );
				//delete_option( $old_setting );
			}		
		}
		
		if ( !empty( get_option('toppic_theme_copyrights') ) ) {
			set_theme_mod('kktfwp_copyrights', stripslashes(get_option('toppic_theme_copyrights') ) );
			delete_option('toppic_theme_copyrights');
		};		
		
		// Move custom CSS
		$css = wp_strip_all_tags( get_option('toppic_theme_custom_css') );
		
		if ( $css !== '' ) {
			$css .= wp_get_custom_css();
			wp_update_custom_css_post( $css );
			delete_option( 'toppic_theme_custom_css' );
		}

		update_option( 'kktfwpSettingsUpdated', 'true' );		
	}
}

add_action( 'after_setup_theme', 'kktfwp_settings_update' );