<?php
/**
 * NDesign functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package NDesign
 */

if ( ! function_exists( 'ndesign_setup' ) ) :

	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function ndesign_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on NDesign, use a find and replace
		 * to change 'ndesign' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'ndesign', get_template_directory() . '/languages' );
		// Add default posts and comments RSS feed links to head.
		add_theme_support( 'automatic-feed-links' );

		/*
		 * Let WordPress manage the document title.
		 * By adding theme support, we declare that this theme does not use a
		 * hard-coded <title> tag in the document head, and expect WordPress to
		 * provide it for us.
		 */

		add_theme_support( 'title-tag' );

		/*
		* Enable support for Post Thumbnails on posts and pages.
		*
		* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
		*/

		add_theme_support( 'post-thumbnails' );
		// This theme uses wp_nav_menu() in one location.
		register_nav_menus(
			array(
				'menu-1' => esc_html__( 'Primary', 'ndesign' ),
			)
		);

		/*
		* Switch default core markup for search form, comment form, and comments
		* to output valid HTML5.
		*/

		add_theme_support(
			'html5',
			array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
			)
		);
		// Set up the WordPress core custom background feature.
		add_theme_support(
			'custom-background',
			apply_filters(
				'ndesign_custom_background_args',
				array(
					'default-color' => 'ffffff',
					'default-image' => '',
				)
			)
		);
		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );
		/**
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		add_theme_support(
			'custom-logo',
			array(
				'height' => 250,
				'width' => 250,
				'flex-width' => true,
				'flex-height' => true,
			)
		);

		if ( empty( get_post_format( 'post-formats' ) ) ) {
			add_theme_support( 'post-formats', array( 'aside', 'gallery', 'image', 'video' ) );
		}
	}

endif;
add_action( 'after_setup_theme', 'ndesign_setup' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @global int $ndesign_content_width
 */
function ndesign_content_width() {
	// This variable is intended to be overruled from themes.
	// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
	// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
	$GLOBALS['content_width'] = apply_filters( 'content_width', 640 );
}

add_action( 'after_setup_theme', 'ndesign_content_width', 0 );

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function ndesign_widgets_init() {
	register_sidebar(
		array(
			'name' => esc_html__( 'Sidebar', 'ndesign' ),
			'id' => 'sidebar-1',
			'description' => esc_html__( 'Add widgets here.', 'ndesign' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget' => '</section>',
			'before_title' => '<h2 class="widget-title">',
			'after_title' => '</h2>',
		)
	);
}

add_action( 'widgets_init', 'ndesign_widgets_init' );

/**
 * Enqueue scripts and styles.
 *
 * @since 1.0.0
 * @author Niraj Gohel
 */
function ndesign_scripts() {
	wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '4.2.1', 'all' );
	wp_enqueue_script( 'ndesign-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
	wp_enqueue_script( 'ndesign-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}
	wp_enqueue_style( 'themefonts-css', 'https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i|Open+Sans', array(), '1.0.0', 'all' );
	wp_enqueue_style( 'fontawesome-css', get_template_directory_uri() . '/css/font-awesome.min.css', array(), '4.7.0', 'all' );
	wp_enqueue_style( 'swiper-css', get_template_directory_uri() . '/css/swiper.min.css', array(), '4.4.6', 'all' );
	wp_enqueue_style( 'venobox-css', get_template_directory_uri() . '/css/venobox.min.css', array(), '1.8.5', 'all' );
	wp_enqueue_style( 'ndesign-style', get_stylesheet_uri(), array(), '1.0.0', 'all' );
	wp_enqueue_script( 'popper-js', get_template_directory_uri() . '/js/popper.min.js', array(), '1.14.6', true );
	wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery', 'popper-js' ), '4.2.1', true );
	wp_enqueue_script( 'swiper-js', get_template_directory_uri() . '/js/swiper.min.js', array(), '4.4.6' );
	wp_enqueue_script( 'venobox-js', get_template_directory_uri() . '/js/venobox.min.js', array( 'jquery' ), '1.8.5' );
	if ( is_front_page() ) {
		wp_enqueue_script( 'frontpage-js', get_template_directory_uri() . '/js/frontpage.js', array( 'jquery' ), '1.0.0' );
	}
	if ( ! is_front_page() ) {
		wp_enqueue_script( 'notfrontpage-js', get_template_directory_uri() . '/js/innerpage.js', array( 'jquery' ), '1.0.0' );
		wp_localize_script( 'notfrontpage-js', 'homepage_url_object', array( 'homeurl' => get_site_url() ) );
	}

	wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/js/custom.js', array( 'jquery' ), '1.0.0' );
}

add_theme_support( 'editor-styles' );
add_editor_style( 'editor-style.css' );
add_action( 'wp_enqueue_scripts', 'ndesign_scripts' );
/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.php';
/**
 * Custom template tags for this theme.
 */
require get_template_directory() . '/inc/template-tags.php';
/**
 * Functions which enhance the theme by hooking into WordPress.
 */
require get_template_directory() . '/inc/template-functions.php';
/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';
/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
	require get_template_directory() . '/inc/jetpack.php';
}
/**
 * Embedded Kirki
*/
require get_template_directory() . '/inc/kirki/kirki.php';
/*
	ACTUAL CODE STARTS HERE
*/

/*
	Register the required plugins for this theme
*/

	require_once get_theme_file_path( 'includes/class-tgm-plugin-activation.php' );
	add_action( 'tgmpa_register', 'ndesign_my_theme_register_required_plugins' );

/**
 * Function to register the required Plugins
 *
 * @since 1.0.0
 * @author Vishal Valand
 */
function ndesign_my_theme_register_required_plugins() {
	$ndesign_plugins = array(
		array(
			'name' => 'Contact Form 7 ',
			'slug' => 'contact-form-7',
			'required' => false,
		),
		array(
			'name' => 'NDesign Theme Support',
			'slug' => 'ndesign-theme-support',
			'required' => false,
		),
		// Disable Kirki as a required plugin
		// array(
		// 	'name' => 'Kirki',
		// 	'slug' => 'kirki',
		// 	'required' => false,
		// ),
	);
	$ndesign_config = array(
		'id' => 'ndesign',
		'has_notices' => true, // Show admin notices or not.
		'strings' => array(),
		'WPCF7_LOAD_JS' => true,
	);
	tgmpa( $ndesign_plugins, $ndesign_config );
}

/** Register Portfolio post ** */
add_action( 'init', 'ndesign_customize_register_2' );

/**
 * NDesign Customizer Registeration
 *
 * @since 1.0.0
 * @author Aarti Chauhan, Niraj Gohel
 *
 * @param WordPress Customizer Object $ndesign_wp_customize The Default Customizer Object of WordPress.
 */
function ndesign_customize_register_2( $ndesign_wp_customize ) {
	if ( class_exists( 'Kirki' ) ) {
		Kirki::add_config(
			'ndesign',
			array(
				'capability' => 'edit_theme_options',
				'option_type' => 'theme_mod',
			)
		);
		/* Adding Contact Information Panel */
		Kirki::add_panel(
			'contact_panel',
			array(
				'priority' => 11,
				'title' => esc_html__( 'Contact Information', 'ndesign' ),
				'description' => esc_html__( 'Your Contact Information which will be displayed in the top header and footer', 'ndesign' ),
			)
		);
		/* Adding Phone Number Section in Contact Information Panel */
		Kirki::add_section(
			'phone_info',
			array(
				'title' => esc_html__( 'Phone Number', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in Phone Number Section */
		Kirki::add_field(
			'phone_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'phone_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'phone_info',
				'default' => 'envelope-o',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'phone_text',
			array(
				'type' => 'text',
				'settings' => 'phone_text',
				'label' => __( 'Text to Display', 'ndesign' ),
				'section' => 'phone_info',
				'priority' => 10,
				'partial_refresh' => array(
					'phone_info' => array(
						'selector' => '.phone-number',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		Kirki::add_field(
			'phone_link',
			array(
				'type' => 'link',
				'settings' => 'phone_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'phone_info',
				'priority' => 10,
			)
		);
		/* Adding Email Section in Contact Information Panel */
		Kirki::add_section(
			'email_info',
			array(
				'title' => esc_html__( 'Email', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in Email Address Section */
		Kirki::add_field(
			'email_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'email_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'email_info',
				'default' => 'envelope-o',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'email_text',
			array(
				'type' => 'text',
				'settings' => 'email_text',
				'label' => __( 'Text to Display', 'ndesign' ),
				'section' => 'email_info',
				'priority' => 10,
				'partial_refresh' => array(
					'email_info' => array(
						'selector' => '.email-address',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		Kirki::add_field(
			'email_link',
			array(
				'type' => 'link',
				'settings' => 'email_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'email_info',
				'priority' => 10,
			)
		);
		/* Adding Facebook Section in Contact Information Panel */
		Kirki::add_section(
			'fb_info',
			array(
				'title' => esc_html__( 'Facebook', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in Facebook Section */
		Kirki::add_field(
			'fb_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'fb_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'fb_info',
				'default' => 'facebook',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'fb_link',
			array(
				'type' => 'link',
				'settings' => 'fb_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'fb_info',
				'priority' => 10,
				'partial_refresh' => array(
					'fb_info' => array(
						'selector' => '.facebook-link',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Twitter Section in Contact Information Panel */
		Kirki::add_section(
			'twitter_info',
			array(
				'title' => esc_html__( 'Twitter', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in Twitter Section */
		Kirki::add_field(
			'twitter_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'twitter_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'twitter_info',
				'default' => 'twitter',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'twitter_link',
			array(
				'type' => 'link',
				'settings' => 'twitter_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'twitter_info',
				'priority' => 10,
				'partial_refresh' => array(
					'twitter_info' => array(
						'selector' => '.twitter-link',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Linked In Section in Contact Information Panel */
		Kirki::add_section(
			'linked_in_info',
			array(
				'title' => esc_html__( 'Linked In', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in linked_in Section */
		Kirki::add_field(
			'linked_in_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'linked_in_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'linked_in_info',
				'default' => 'linkedin',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'linked_in_link',
			array(
				'type' => 'link',
				'settings' => 'linked_in_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'linked_in_info',
				'priority' => 10,
				'partial_refresh' => array(
					'linked_in_info' => array(
						'selector' => '.linkedin-link',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Pinterest Section in Contact Information Panel */
		Kirki::add_section(
			'pinterest_info',
			array(
				'title' => esc_html__( 'Pinterest', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in pinterest Section */
		Kirki::add_field(
			'pinterest_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'pinterest_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'pinterest_info',
				'default' => 'pinterest',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'pinterest_link',
			array(
				'type' => 'link',
				'settings' => 'pinterest_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'pinterest_info',
				'priority' => 10,
				'partial_refresh' => array(
					'pinterest_info' => array(
						'selector' => '.pinterest-link',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Youtube Section in Contact Information Panel */
		Kirki::add_section(
			'youtube_info',
			array(
				'title' => esc_html__( 'YouTube', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in youtube Section */
		Kirki::add_field(
			'youtube_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'youtube_icon',
				'label' => __( 'Icon', 'ndesign' ),
				'section' => 'youtube_info',
				'default' => 'youtube',
				'priority' => 10,
			)
		);
		Kirki::add_field(
			'youtube_link',
			array(
				'type' => 'link',
				'settings' => 'youtube_link',
				'label' => __( 'URL', 'ndesign' ),
				'section' => 'youtube_info',
				'priority' => 10,
				'partial_refresh' => array(
					'youtube_info' => array(
						'selector' => '.youtube-link',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Logo variant Field in Site Options */
		Kirki::add_field(
			'logo_variant_for_footer',
			array(
				'type' => 'image',
				'settings' => 'footer_logo',
				'label' => __( 'Footer Logo', 'ndesign' ),
				'section' => 'title_tagline',
				'priority' => 10,
				'partial_refresh' => array(
					'footer_logo' => array(
						'selector' => 'footer .site-logo',
						'render_callback' => '__return_false',
					),
				),
			)
		);

		Kirki::add_field(
			'theme_color',
			array(
				'type' => 'color',
				'settings' => 'theme_color',
				'label' => __( 'Theme Color', 'ndesign' ),
				'section' => 'title_tagline',
				'priority' => 10,
				'default'=> !empty(get_theme_mod('theme_color'))? get_theme_mod('theme_color') : '#161B5A',
				'partial_refresh' => array(
					'footer_logo' => array(
						'selector' => '',
						'render_callback' => '__return_false',
					),
				),
			)
		);

		Kirki::add_field(
			'site_description',
			array(
				'type' => 'textarea',
				'settings' => 'site_description',
				'label' => __( 'Site Description', 'ndesign' ),
				'section' => 'title_tagline',
				'priority' => 10,
				'partial_refresh' => array(
					'site_description' => array(
						'selector' => 'footer .footer-site-description',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Renaming the Site Option to General Options */
		Kirki::add_section(
			'title_tagline',
			array(
				'title' => esc_html__( 'General Options', 'ndesign' ),
			)
		);
		/* Adding Slider Section */
		Kirki::add_section(
			'slider',
			array(
				'title' => esc_html__( 'Main Slider', 'ndesign' ),
				'priority' => 11,
			)
		);
		/* Adding Repeater of Slides in Slider Section */
		Kirki::add_field(
			'slides',
			array(
				'type' => 'repeater',
				'label' => esc_html__( 'Slides', 'ndesign' ),
				'section' => 'slider',
				'priority' => 10,
				'row_label' => array(
					'type' => 'field',
					'value' => esc_html__( 'Slide', 'ndesign' ),
					'field' => 'title',
				),
				'button_label' => esc_html__( 'Add new Slide', 'ndesign' ),
				'settings' => 'slides',
				'fields' => array(
					'title' => array(
						'type' => 'text',
						'label' => esc_html__( 'Slide Title', 'ndesign' ),
						'default' => '',
					),
					'subtitle' => array(
						'type' => 'text',
						'label' => esc_html__( 'Slide Subtitle', 'ndesign' ),
						'default' => '',
					),
					'description' => array(
						'type' => 'textarea',
						'label' => esc_html__( 'Slide Description', 'ndesign' ),
						'default' => '',
					),
					'textcolor' => array(
						'type' => 'color',
						'label' => esc_html__( 'Text Color', 'ndesign' ),
						'default'=> !empty(get_theme_mod('theme_color'))? get_theme_mod('theme_color') : '#161B5A',
					),
					'background' => array(
						'type' => 'image',
						'label' => esc_html__( 'Slider Background Image', 'ndesign' ),
					),
				),
				'partial_refresh' => array(
					'slides' => array(
						'selector' => '.main-banner',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Contact Address Section in Contact Information Panel */
		Kirki::add_section(
			'contact_address_section',
			array(
				'title' => esc_html__( 'Contact Address', 'ndesign' ),
				'priority' => 160,
				'panel' => 'contact_panel',
			)
		);
		/* Adding Fields in Address Icon Field */
		Kirki::add_field(
			'caddress_icon',
			array(
				'type' => 'fontawesome',
				'settings' => 'caddress_icon',
				'label' => __( 'Address Icon', 'ndesign' ),
				'section' => 'contact_address_section',
				'default' => 'home',
				'priority' => 10,
			)
		);
		/* Adding Fields in Contact Address Field */
		Kirki::add_field(
			'contact_address',
			array(
				'type' => 'textarea',
				'settings' => 'contact_address',
				'label' => __( 'Contact Address', 'ndesign' ),
				'section' => 'contact_address_section',
				'priority' => 10,
				'partial_refresh' => array(
					'contact_address' => array(
						'selector' => '.contact-address',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Blog Section */
		Kirki::add_section(
			'blog_section',
			array(
				'title' => esc_html__( 'Blog', 'ndesign' ),
				'priority' => 16,
			)
		);
		/* Adding Blog Title Fields in Blog Section */
		Kirki::add_field(
			'blog_title',
			array(
				'type' => 'text',
				'settings' => 'blog_title',
				'label' => __( 'Blog Title', 'ndesign' ),
				'section' => 'blog_section',
				'partial_refresh' => array(
					'blog_title' => array(
						'selector' => '.blog-section .main-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Blog SubTitle Fields in Blog Section */
		Kirki::add_field(
			'blog_sub_title',
			array(
				'type' => 'text',
				'settings' => 'blog_sub_title',
				'label' => __( 'Blog Sub Title', 'ndesign' ),
				'section' => 'blog_section',
				'partial_refresh' => array(
					'blog_sub_title' => array(
						'selector' => '.blog-section .main-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Number of Blogs Fields in Blog Section */
		Kirki::add_field(
			'number_of_blog',
			array(
				'type' => 'number',
				'settings' => 'number_of_blog',
				'label' => esc_html__( 'Number of Blog Display (Min: 1, Max:6)', 'ndesign' ),
				'section' => 'blog_section',
				'default' => 3,
				'choices' => array(
					'min' => 1,
					'max' => 6,
					'step' => 1,
				),
				'partial_refresh' => array(
					'blog_section' => array(
						'selector' => '.blog-wrap',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		Kirki::add_field(
			'blog_button_text',
			array(
				'type' => 'text',
				'settings' => 'blog_button_text',
				'label' => __( 'Button Text', 'ndesign' ),
				'section' => 'blog_section',
				'partial_refresh' => array(
					'blog_button_text' => array(
						'selector' => '#blogViewAll',
						'render_callback' => '__return_false',
					),
				),
				'default' => 'View All',
			)
		);
		Kirki::add_field(
			'blog_dummy_image',
			array(
				'type' => 'image',
				'settings' => 'blog_dummy_image',
				'label' => esc_html__( 'Select Dummy Image for Blog', 'ndesign' ),
				'section' => 'blog_section',
				'default' => '',
			)
		);
		/* Adding Read More Button Checkbox in Blog Section */
		Kirki::add_field(
			'read_more_button',
			array(
				'type' => 'checkbox',
				'settings' => 'read_more_button',
				'label' => esc_html__( 'Display Read More Button', 'ndesign' ),
				'section' => 'blog_section',
				'default' => true,
			)
		);
		/* Adding Date Checkbox in Blog Section */
		Kirki::add_field(
			'display_date',
			array(
				'type' => 'checkbox',
				'settings' => 'display_date',
				'label' => esc_html__( 'Display Date', 'ndesign' ),
				'section' => 'blog_section',
				'default' => true,
			)
		);
		/* Adding Auther Checkbox in Blog Section */
		Kirki::add_field(
			'display_author',
			array(
				'type' => 'checkbox',
				'settings' => 'display_author',
				'label' => esc_html__( 'Display Author', 'ndesign' ),
				'section' => 'blog_section',
				'default' => true,
			)
		);
		/* Adding Testimonial Section */
		Kirki::add_section(
			'testimonial_section',
			array(
				'title' => esc_html__( 'Testimonials', 'ndesign' ),
				'priority' => 15,
			)
		);
		/* Adding Sub Title Field in Testimonial Section */
		Kirki::add_field(
			'testimonial_subtitle',
			array(
				'type' => 'text',
				'settings' => 'testimonial_subtitle',
				'label' => esc_html__( 'Sub Title', 'ndesign' ),
				'section' => 'testimonial_section',
				'partial_refresh' => array(
					'testimonial_subtitle' => array(
						'selector' => '.testimonial-section .main-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Title Field in Testimonial Section */
		Kirki::add_field(
			'testimonial_title',
			array(
				'type' => 'text',
				'settings' => 'testimonial_title',
				'label' => esc_html__( 'Title', 'ndesign' ),
				'section' => 'testimonial_section',
				'partial_refresh' => array(
					'testimonial_title' => array(
						'selector' => '.testimonial-section .main-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Repeater of Testimonial in Testimonial Section */
		Kirki::add_field(
			'testimonial',
			array(
				'type' => 'repeater',
				'label' => esc_html__( 'Testimonial', 'ndesign' ),
				'section' => 'testimonial_section',
				'priority' => 10,
				'row_label' => array(
					'type' => 'field',
					'value' => esc_html__( 'Testimonial', 'ndesign' ),
					'field' => 'name',
				),
				'button_label' => esc_html__( 'Add new Slide', 'ndesign' ),
				'settings' => 'testimonial',
				'fields' => array(
					'name' => array(
						'type' => 'text',
						'label' => esc_html__( 'Name', 'ndesign' ),
						'default' => '',
					),
					'description' => array(
						'type' => 'textarea',
						'label' => esc_html__( 'Description', 'ndesign' ),
						'default' => '',
					),
					'image' => array(
						'type' => 'image',
						'label' => esc_html__( 'Image', 'ndesign' ),
						'default' => '',
					),
					'designation' => array(
						'type' => 'text',
						'label' => esc_html__( 'Designation', 'ndesign' ),
						'default' => '',
					),
					'organization' => array(
						'type' => 'text',
						'label' => esc_html__( 'Organization', 'ndesign' ),
						'default' => '',
					),
				),
				'partial_refresh' => array(
					'testimonial' => array(
						'selector' => '.testimonial-slider-wrap',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Our Team Section */
		Kirki::add_section(
			'meet_the_team_section',
			array(
				'title' => esc_html__( 'Our Team', 'ndesign' ),
				'priority' => 14,
			)
		);
		/* Adding Sub Title Field in service Section */
		Kirki::add_field(
			'team_subtitle',
			array(
				'type' => 'text',
				'settings' => 'team_subtitle',
				'label' => esc_html__( 'Sub Title', 'ndesign' ),
				'section' => 'meet_the_team_section',
				'partial_refresh' => array(
					'team_subtitle' => array(
						'selector' => '.our-team-section .main-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Title Field in Our Team Section */
		Kirki::add_field(
			'team_title',
			array(
				'type' => 'text',
				'settings' => 'team_title',
				'label' => esc_html__( 'Title', 'ndesign' ),
				'section' => 'meet_the_team_section',
				'partial_refresh' => array(
					'team_title' => array(
						'selector' => '.our-team-section .main-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Repeater of Team in Our Team Section */
		Kirki::add_field(
			'meet_the_team',
			array(
				'type' => 'repeater',
				'label' => esc_html__( 'Team', 'ndesign' ),
				'section' => 'meet_the_team_section',
				'priority' => 10,
				'row_label' => array(
					'type' => 'field',
					'value' => esc_html__( 'Team', 'ndesign' ),
					'field' => 'team_name',
				),
				'button_label' => esc_html__( 'Add New Team Member', 'ndesign' ),
				'settings' => 'meet_the_team',
				'fields' => array(
					'team_name' => array(
						'type' => 'text',
						'label' => esc_html__( 'Name', 'ndesign' ),
						'default' => '',
					),
					'team_image' => array(
						'type' => 'image',
						'label' => esc_html__( 'Image', 'ndesign' ),
						'default' => '',
					),
					'team_designation' => array(
						'type' => 'text',
						'label' => esc_html__( 'Designation', 'ndesign' ),
						'default' => '',
					),
				),
				'partial_refresh' => array(
					'meet_the_team' => array(
						'selector' => '.team-slider-wrap',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding About Us Section */
		Kirki::add_section(
			'about_us_section',
			array(
				'title' => esc_html__( 'About Us', 'ndesign' ),
				'priority' => 13,
				'settings' => 'about_us_section',
			)
		);
		/* Adding Title Field in About Us Section */
		Kirki::add_field(
			'about_title',
			array(
				'type' => 'text',
				'settings' => 'about_title',
				'label' => esc_html__( 'Title', 'ndesign' ),
				'section' => 'about_us_section',
				'partial_refresh' => array(
					'about_title' => array(
						'selector' => '.about-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Sub Title Field in About Us Section */
		Kirki::add_field(
			'about_subtitle',
			array(
				'type' => 'text',
				'settings' => 'about_subtitle',
				'label' => esc_html__( 'Sub Title', 'ndesign' ),
				'section' => 'about_us_section',
				'partial_refresh' => array(
					'about_subtitle' => array(
						'selector' => '.about-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Description Field in About Us Section */
		Kirki::add_field(
			'about_des',
			array(
				'type' => 'editor',
				'settings' => 'about_des',
				'label' => esc_html__( 'Description', 'ndesign' ),
				'section' => 'about_us_section',
				'partial_refresh' => array(
					'about_des' => array(
						'selector' => '.about-content',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Image Field in About Us Options */
		Kirki::add_field(
			'about_image',
			array(
				'type' => 'image',
				'settings' => 'about_image',
				'label' => esc_html__( 'About Image', 'ndesign' ),
				'section' => 'about_us_section',
				'default' => '',
				'partial_refresh' => array(
					'about_image' => array(
						'selector' => '.about-video-content',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Description Field in About Us Section */
		Kirki::add_field(
			'about_video',
			array(
				'type' => 'text',
				'settings' => 'about_video',
				'label' => esc_html__( 'Video Link', 'ndesign' ),
				'section' => 'about_us_section',
				'partial_refresh' => array(
					'about_video' => array(
						'selector' => '',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Service Section */
		Kirki::add_section(
			'service_section',
			array(
				'title' => esc_html__( 'Our Services', 'ndesign' ),
				'priority' => 13,
			)
		);
		/* Adding Title Field in About Us Section */
		Kirki::add_field(
			'service_title',
			array(
				'type' => 'text',
				'settings' => 'service_title',
				'label' => esc_html__( 'Title', 'ndesign' ),
				'section' => 'service_section',
				'partial_refresh' => array(
					'service_title' => array(
						'selector' => '.services-section .main-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Sub Title Field in About Us Section */
		Kirki::add_field(
			'service_subtitle',
			array(
				'type' => 'text',
				'settings' => 'service_subtitle',
				'label' => esc_html__( 'Sub Title', 'ndesign' ),
				'section' => 'service_section',
				'partial_refresh' => array(
					'service_subtitle' => array(
						'selector' => '.services-section .main-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Repeater of Team in Our Team Section */
		Kirki::add_field(
			'services',
			array(
				'type' => 'repeater',
				'label' => esc_html__( 'Services', 'ndesign' ),
				'section' => 'service_section',
				'priority' => 10,
				'row_label' => array(
					'type' => 'field',
					'value' => esc_html__( 'Services', 'ndesign' ),
					'field' => 'service_name',
				),
				'button_label' => esc_html__( 'Add New Service', 'ndesign' ),
				'settings' => 'services',
				'fields' => array(
					'service_name' => array(
						'type' => 'text',
						'label' => esc_html__( 'Name', 'ndesign' ),
						'default' => '',
					),
					'service_image' => array(
						'type' => 'image',
						'label' => esc_html__( 'Image', 'ndesign' ),
						'default' => '',
					),
					'service_description' => array(
						'type' => 'textarea',
						'label' => esc_html__( 'Description', 'ndesign' ),
						'default' => '',
					),
				),
				'partial_refresh' => array(
					'services' => array(
						'selector' => '.service-slider-wrap',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Portfolio Section */
		Kirki::add_section(
			'portfolio_section',
			array(
				'title' => esc_html__( 'Portfolio', 'ndesign' ),
				'priority' => 13,
			)
		);
		/* Adding Title Field in Portfolio Section */
		Kirki::add_field(
			'portfolio_title',
			array(
				'type' => 'text',
				'settings' => 'portfolio_title',
				'label' => esc_html__( 'Title', 'ndesign' ),
				'section' => 'portfolio_section',
				'partial_refresh' => array(
					'portfolio_title' => array(
						'selector' => '.portfolio-section .main-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Sub Title Field in Portfolio Section */
		Kirki::add_field(
			'portfolio_subtitle',
			array(
				'type' => 'text',
				'settings' => 'portfolio_subtitle',
				'label' => esc_html__( 'Sub Title', 'ndesign' ),
				'section' => 'portfolio_section',
				'partial_refresh' => array(
					'portfolio_subtitle' => array(
						'selector' => '.portfolio-section .main-subtitle',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Number of Portfolio Fields in Portfolio Section */
		Kirki::add_field(
			'number_of_portfolio',
			array(
				'type' => 'number',
				'settings' => 'number_of_portfolio',
				'label' => esc_html__( 'Number of Portfolio Display (Min: 1, Max:6)', 'ndesign' ),
				'section' => 'portfolio_section',
				'default' => 6,
				'choices' => array(
					'min' => 1,
					'max' => 6,
					'step' => 1,
				),
				'partial_refresh' => array(
					'number_of_portfolio' => array(
						'selector' => '#portfolio',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Contact form section */
		Kirki::add_section(
			'contact_form',
			array(
				'title' => esc_html__( 'Contact Form', 'ndesign' ),
				'priority' => 17,
			)
		);
		Kirki::add_field(
			'contact_form_id',
			array(
				'type' => 'select',
				'settings' => 'contact_form_id',
				'label' => esc_html__( 'Select Contact Form', 'ndesign' ),
				'section' => 'contact_form',
				'default' => '',
				'placeholder' => 'Select Contact Form',
				'multiple' => 1,
				'choices' => Kirki_Helper::get_posts(
					array(
						'posts_per_page' => 10,
						'post_type' => 'wpcf7_contact_form',
					)
				),
				'partial_refresh' => array(
					'number_of_portfolio' => array(
						'selector' => '.footer-contact-form',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Footer Section */
		Kirki::add_section(
			'footer_section',
			array(
				'title' => esc_html__( 'Footer', 'ndesign' ),
				'priority' => 18,
			)
		);
		/* Adding Contact Title Field in Footer section */
		Kirki::add_field(
			'contact_title',
			array(
				'type' => 'text',
				'settings' => 'contact_title',
				'label' => esc_html__( 'Contact Title', 'ndesign' ),
				'section' => 'footer_section',
				'partial_refresh' => array(
					'contact_title' => array(
						'selector' => '.contact-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Contact  Form Title Field in Footer section */
		Kirki::add_field(
			'contact_form_title',
			array(
				'type' => 'text',
				'settings' => 'contact_form_title',
				'label' => esc_html__( 'Contact Form Title', 'ndesign' ),
				'section' => 'footer_section',
				'partial_refresh' => array(
					'contact_form_title' => array(
						'selector' => '.contact-form-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
		/* Adding Social link Title Field in Footer section */
		Kirki::add_field(
			'footer_social_title',
			array(
				'type' => 'text',
				'settings' => 'footer_social_title',
				'label' => esc_html__( 'Social Medial Title', 'ndesign' ),
				'section' => 'footer_section',
				'partial_refresh' => array(
					'footer_social_title' => array(
						'selector' => '.footer-social-title',
						'render_callback' => '__return_false',
					),
				),
			)
		);
	}
}

/**
 * Removing Default Preloader of The Kirki Framework
 *
 * @since 1.0.0
 * @author Niraj Gohel
 *
 * @param Kirki Configuration Object $ndesign_config Default Configuration Object to be modified.
 */
function ndesign_kirki_demo_configuration_sample_styling( $ndesign_config ) {
	return wp_parse_args(
		array(
			'description' => esc_attr__( 'The theme description.', 'ndesign' ),
			'disable_loader' => true,
		),
		$ndesign_config
	);
}

add_filter( 'kirki/config', 'ndesign_kirki_demo_configuration_sample_styling' );



/**
 * Custom function to Upload Image from theme folder to uploads folder
 *
 * @since 1.0.0
 * @author Niraj Gohel
 *
 * @param string $ndesign_image_name Image Name which will be copied from theme to Uploads folder.
 */
function ndesign_upload_ndesign_image( $ndesign_image_name ) {
	$ndesign_file_type = wp_check_filetype( basename( $ndesign_image_name ) );
	$ndesign_wp_upload_dir = wp_upload_dir();
	$ndesign_content = wp_remote_get( get_template_directory_uri() . '/images/' . $ndesign_image_name );
	global $wp_filesystem;
	if ( empty( $wp_filesystem ) ) {
		require_once( ABSPATH . '/wp-admin/includes/file.php' );
		WP_Filesystem();
	}
	if ( ! $wp_filesystem->put_contents( $ndesign_wp_upload_dir['path'] . '/' . $ndesign_image_name, $ndesign_content['body'], FS_CHMOD_FILE ) ) {
		echo 'error saving file!';
	}
	$ndesign_image_id = wp_insert_attachment(
		array(
			'guid' => $ndesign_wp_upload_dir['url'] . '/' . basename( $ndesign_image_name ),
			'post_mime_type' => $ndesign_file_type['type'],
			'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $ndesign_image_name ) ),
			'post_content' => '',
			'post_status' => 'inherit',
		),
		$ndesign_image_name,
		null
	);
	require_once( ABSPATH . 'wp-admin/includes/image.php' );
	$ndesign_metadata = wp_generate_attachment_metadata( $ndesign_image_id, $ndesign_wp_upload_dir['path'] . '/' . $ndesign_image_name );
	wp_update_attachment_metadata( $ndesign_image_id, $ndesign_metadata );
	update_post_meta( $ndesign_image_id, '_wp_attached_file', substr( $ndesign_wp_upload_dir['subdir'], 1 ) . '/' . $ndesign_image_name );
	return $ndesign_image_id;
}



/**
 * Checks if post is already created or not
 *
 * @since 1.0.0
 * @author Niraj Gohel
 *
 * @param string $ndesign_post_slug Slug of the post you want to check if it exists or not.
 * @param string $ndesign_post_type Post type you want to search in.
 */
function ndesign_post_exists_by_slug( $ndesign_post_slug, $ndesign_post_type ) {
	$ndesign_args_posts = array(
		'post_type' => $ndesign_post_type,
		'post_status' => 'any',
		'name' => $ndesign_post_slug,
		'posts_per_page' => 1,
	);
	$ndesign_loop_posts = new WP_Query( $ndesign_args_posts );
	if ( ! $ndesign_loop_posts->have_posts() ) {
		return false;
	} else {
		$ndesign_loop_posts->the_post();
		return $ndesign_loop_posts->post->ID;
	}
}


/**
 * Additional Class Extension for custom navigation menu with multi-level support
 * @since 1.0.7
 *
 * @author Niraj Gohel
 */
class ndesign_Menu_Walker extends Walker {

	var $db_fields = array('parent' => 'menu_item_parent', 'id' => 'db_id');

	function start_lvl(&$output, $depth = 0, $args = array()) {
		$indent = str_repeat("\t", $depth);
		$output .= "\n$indent<ul>\n";
	}

	function end_lvl(&$output, $depth = 0, $args = array()) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent</ul>\n";
	}

	function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {

		global $wp_query;
		$indent = ($depth) ? str_repeat("\t", $depth) : '';
		$class_names = $value = '';
		$classes = empty($item->classes) ? array() : (array) $item->classes;

		/* Add active class */
		if (in_array('current-menu-item', $classes)) {
			$classes[] = 'active';
			unset($classes['current-menu-item']);
		}

		/* Check for children */
		$children = get_posts(array('post_type' => 'nav_menu_item', 'nopaging' => true, 'numberposts' => 1, 'meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $item->ID));
		if (!empty($children)) {
			$classes[] = 'has-sub';
		}

		$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args));
		$class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : '';

		$id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args);
		$id = $id ? ' id="' . esc_attr($id) . '"' : '';

		$output .= $indent . '<li' . $id . $value . $class_names .'>';

		$attributes  = ! empty($item->attr_title) ? ' title="'  . esc_attr($item->attr_title) .'"' : '';
		$attributes .= ! empty($item->target)     ? ' target="' . esc_attr($item->target    ) .'"' : '';
		$attributes .= ! empty($item->xfn)        ? ' rel="'    . esc_attr($item->xfn       ) .'"' : '';
		$attributes .= ! empty($item->url)        ? ' href="'   . esc_attr($item->url       ) .'"' : '';

		$item_output = $args->before;
		$item_output .= '<a'. $attributes;
		if (!empty($children)) {
			$item_output .= 'class="dropdown-toggle"';
		}
		$item_output .= '><span>';
		$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
		$item_output .= '</span></a>';
		$item_output .= $args->after;

		$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
	}

	function end_el(&$output, $item, $depth = 0, $args = array()) {
		$output .= "</li>\n";
	}
}

/**
*
* Function to get first image from post if there is no featured image in a post
* @since 1.1.0
*
* @param $p Post Object
* @author Pratik Malvi
*/
function ndesign_catch_that_image($p = null) {
	global $post, $posts;
	$first_img = '';
	ob_start();
	ob_end_clean();
	if(isset($p)){
		$content = $p->post_content;
	}else{
		$content = $post->post_content;
	}
	$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
	if(empty(array_filter($matches))){
		$first_img='';
	}
	else{
		$first_img = $matches[1][0];
	}
	if(empty($first_img)){
		$first_img='';
	}
	return $first_img;
}

/**
 * Function to get color pallete for the theme
 *
 * @param $ndesign_hex - HEX code of the primary color
 * @param $ndesign_percent - percentage of lightness (positive for light shade, negative for darker shades)
 *
 * @since 1.1.0
 * @author Niraj Gohel
 */
function ndesign_color_luminance( $hexcolor, $percent) {
	if ( strlen( $hexcolor ) < 6 ) {
		$hexcolor = $hexcolor[0] . $hexcolor[0] . $hexcolor[1] . $hexcolor[1] . $hexcolor[2] . $hexcolor[2];
	}
	$hexcolor = array_map('hexdec', str_split( str_pad( str_replace('#', '', $hexcolor), 6, '0' ), 2 ) );

	foreach ($hexcolor as $i => $color) {
		$from = $percent < 0 ? 0 : $color;
		$to = $percent < 0 ? $color : 255;
		$pvalue = ceil( ($to - $from) * $percent );
		$hexcolor[$i] = str_pad( dechex($color + $pvalue), 2, '0', STR_PAD_LEFT);
	}

	return '#' . implode($hexcolor);
}

function ndesign_get_contrast_color($hexColor) {

        // hexColor RGB
	$R1 = hexdec(substr($hexColor, 1, 2));
	$G1 = hexdec(substr($hexColor, 3, 2));
	$B1 = hexdec(substr($hexColor, 5, 2));

        // Black RGB
	$blackColor = "#000000";
	$R2BlackColor = hexdec(substr($blackColor, 1, 2));
	$G2BlackColor = hexdec(substr($blackColor, 3, 2));
	$B2BlackColor = hexdec(substr($blackColor, 5, 2));

         // Calc contrast ratio
	$L1 = 0.2126 * pow($R1 / 255, 2.2) +
	0.7152 * pow($G1 / 255, 2.2) +
	0.0722 * pow($B1 / 255, 2.2);

	$L2 = 0.2126 * pow($R2BlackColor / 255, 2.2) +
	0.7152 * pow($G2BlackColor / 255, 2.2) +
	0.0722 * pow($B2BlackColor / 255, 2.2);

	$contrastRatio = 0;
	if ($L1 > $L2) {
		$contrastRatio = (int)(($L1 + 0.05) / ($L2 + 0.05));
	} else {
		$contrastRatio = (int)(($L2 + 0.05) / ($L1 + 0.05));
	}

        // If contrast is more than 5, return black color
	if ($contrastRatio > 5) {
		return '#000000';
	} else {
            // if not, return white color.
		return '#FFFFFF';
	}
}

function ndesign_hex_to_rgba($hexcode,$opacity=1){
	return 'rgba('.hexdec(substr($hexcode,1,2)).','.hexdec(substr($hexcode,3,4)).','.hexdec(substr($hexcode,5,6)).','.$opacity.')';
}

//add_action( 'after_switch_theme', 'ndesgin_import_data_on_activation' );
function ndesgin_import_data_on_activation(){
    // Create Homepage start
	$home_pages = get_pages(array(
		'meta_key' => '_wp_page_template',
		'meta_value' => 'homepage-template.php'
	));

	if(empty($home_pages[0])){
    	$new_page_title     = __('Ndesign Homepage','ndesign'); // Page's title
    	$new_page_content   = '';                           // Content goes here
    	$new_page_template  = 'homepage-template.php';       // The template to use for the page
    	$page_check = get_page_by_title($new_page_title);   // Check if the page already exists
    	// Store the above data in an array
    	$new_page = array(
    		'post_type'     => 'page',
    		'post_title'    => $new_page_title,
    		'post_content'  => $new_page_content,
    		'post_status'   => 'publish',
    		'post_author'   => 1,
    		'post_slug'     => 'ndesign-homepage'
    	);
    	// If the page doesn't already exist, create it
    	if(!isset($page_check->ID)){
    		$new_page_id = wp_insert_post($new_page);
    		if(!empty($new_page_template)){
    			update_post_meta($new_page_id, '_wp_page_template', $new_page_template);
    		}
    	}
    }
    else{
    	$new_page_id=$home_pages[0]->ID;
    }
    $blog_pages = get_page_by_path('ndesign-blog');
    if(empty($blog_pages)){
    	$new_page_title     = __('Ndesign Blog','ndesign');
    	$new_page_template  = '';
    	$page_check = get_page_by_title($new_page_title);
    	$new_page = array(
    		'post_type'     => 'page',
    		'post_title'    => $new_page_title,
    		'post_status'   => 'publish',
    		'post_author'   => 1,
    		'post_slug'     => 'ndesign-blog'
    	);
    	if(!isset($page_check->ID)){
    		$new_blog_id = wp_insert_post($new_page);
    		if(!empty($new_page_template)){
    			update_post_meta($new_blog_id, '_wp_page_template', $new_page_template);
    		}
    	}
    }
    else{
    	$new_blog_id=$blog_pages->ID;
    }
    // Create Blog page end
    // Function to Set Static page as a Homepage and Post page as Blog page start
    update_option( 'show_on_front', 'page', true );
    update_option( 'page_on_front', $new_page_id, true );
    update_option( 'page_for_posts', $new_blog_id, true );
    // Function to Set Static page as a Homepage and Post page as Blog page end
    // Check if the menu exists
    $menu_name = 'Ndesign Menu';
    $menu_exists = wp_get_nav_menu_object( $menu_name );
	// If it doesn't exist, let's create it.
    if( !$menu_exists){
    	$menu_id = wp_create_nav_menu($menu_name);
    	// Set Menu as a Primary menu start
    	// set_theme_mod('nav_menu_locations', array('primary-menu' => $menu_id));
    	// $global['isMenu'] = 1;
    	// Set Menu as a Primary menu start
    	$locations = get_theme_mod('nav_menu_locations');
    	$locations['primary-menu'] = $menu_id;
    	set_theme_mod( 'nav_menu_locations', $locations );
    	update_option( 'menu_check', true );
    	// Set Menu as a Primary menu start
		// Set up default menu items
    	wp_update_nav_menu_item($menu_id, 0, array(
    	// Home menu link
    		'menu-item-title' =>  __('Home', 'ndesign' ),
    		'menu-item-url' => '#home',
    		'menu-item-status' => 'publish'));
    	// About us menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('About Us', 'ndesign' ),
    		'menu-item-url' => '#about-us',
    		'menu-item-status' => 'publish'));
    	// Services menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Services', 'ndesign' ),
    		'menu-item-url' => '#services',
    		'menu-item-status' => 'publish'));
    	// Portfolio menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Portfolio', 'ndesign' ),
    		'menu-item-url' => '#portfolio',
    		'menu-item-status' => 'publish'));
    	// Team menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Team', 'ndesign' ),
    		'menu-item-url' => '#team',
    		'menu-item-status' => 'publish'));
    	// Testimonial menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Testimonial', 'ndesign'),
    		'menu-item-url' =>  '#testimonial',
    		'menu-item-status' => 'publish'));
    	// Blog menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Blog', 'ndesign' ),
    		'menu-item-url' => '#blog',
    		'menu-item-status' => 'publish'));
    	// Contact Us Menu link
    	wp_update_nav_menu_item($menu_id, 0, array(
    		'menu-item-title' =>  __('Contact Us', 'ndesign' ),
    		'menu-item-url' => '#contact-us',
    		'menu-item-status' => 'publish'));
    	// Set menu as primary menu start
    }
    $nav_menu =  wp_get_nav_menu_object( "Ndesign Menu" );
    $my_theme_defaults = array (
    	0 => false,
    	'is_data_setup'=>1,
    	'nav_menu_locations' => array (
    		'menu-1' => $nav_menu->term_id,
    	),
    	'custom_css_post_id' => -1,
    	'email_link' => esc_attr('mailto:lead@spec-india.com','ndesign'),
    	'youtube_icon' => esc_attr('youtube-play','ndesign'),
    	'phone_icon' => esc_attr('phone','ndesign'),
    	'phone_text' => esc_attr('+91-79-26404031 to 34','ndesign'),
    	'phone_link' => esc_attr('tel:+917926404031','ndesign'),
    	'email_text' => esc_html('lead@spec-india.com','ndesign'),
    	'fb_link' => esc_url('//www.facebook.com/pages/SPEC-INDIA/182501847643','ndesign'),
    	'twitter_link' => esc_url('//twitter.com/infospec_india','ndesign'),
    	'linked_in_link' => esc_url('//www.linkedin.com/company/spec-india','ndesign'),
    	'pinterest_link' => esc_attr('#','ndesign'),
    	'youtube_link' => esc_attr('#','ndesign'),
    	'custom_logo' => ndesign_upload_ndesign_image('ndesign_logo.png'),
    	'footer_logo' => wp_get_attachment_url(ndesign_upload_ndesign_image('ndesign_logo_white.png')),
    	'email_icon' => esc_attr('envelope-o','ndesign'),
    	'fb_icon' => esc_attr('facebook','ndesign'),
    	'twitter_icon' => esc_attr('twitter','ndesign'),
    	'linked_in_icon' => esc_attr('linkedin','ndesign'),
    	'pinterest_icon' => esc_attr('pinterest','ndesign'),
    	'slides' =>
    	array (
    		0 =>
    		array (
    			'title' => esc_html__('Digital Solutions 1','ndesign'),
    			'subtitle' => esc_html__('We Create High Quality','ndesign'),
    			'description' => esc_html__('Share processes and data securely on a need to know basis need for reconciliation it combines. ','ndesign'),
    			'background' => ndesign_upload_ndesign_image('ndesign_banner.png'),
    		),
    		1 =>
    		array (
    			'title' => esc_html__('Digital Solutions 2','ndesign'),
    			'subtitle' => esc_html__('We Create High Quality','ndesign'),
    			'description' => esc_html__('Share processes and data securely on a need to know basis need for reconciliation it combines. ','ndesign'),
    			'background' => ndesign_upload_ndesign_image('ndesign_banner.png'),
    		),
    		2 =>
    		array (
    			'title' => esc_html__('Digital Solutions 3','ndesign'),
    			'subtitle' => esc_html__('We Create High Quality','ndesign'),
    			'description' => esc_html__('Share processes and data securely on a need to know basis need for reconciliation it combines. ','ndesign'),
    			'background' => ndesign_upload_ndesign_image('ndesign_banner.png'),
    		),
    	),
    	'header_textcolor' => esc_attr('blank','ndesign'),
    	'testimonial' =>
    	array (
    		0 =>
    		array (
    			'name' => esc_html__('John Doe','ndesign'),
    			'description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis','ndesign'),
    			'image' => ndesign_upload_ndesign_image('ndesign_testimonial_placeholder.jpg'),
    			'designation' => esc_html__('Designation','ndesign'),
    			'organization' => esc_html__('Organization Name','ndesign'),
    		),
    		1 =>
    		array (
    			'name' => esc_html__('Sage Krik','ndesign'),
    			'description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis','ndesign'),
    			'image' => ndesign_upload_ndesign_image('ndesign_testimonial_placeholder.jpg'),
    			'designation' => esc_html__('Designation','ndesign'),
    			'organization' => esc_html__('Organization Name','ndesign'),
    		),
    		2 =>
    		array (
    			'name' => esc_html__('Albert Dera','ndesign'),
    			'description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis','ndesign'),
    			'image' => ndesign_upload_ndesign_image('ndesign_testimonial_placeholder.jpg'),
    			'designation' => esc_html__('Designation','ndesign'),
    			'organization' => esc_html__('Organization Name','ndesign'),
    		),
    	),
    	'meet_the_team' =>
    	array (
    		0 =>
    		array (
    			'team_name' => esc_html__('Lorriane M Anderson','ndesign'),
    			'team_image' => ndesign_upload_ndesign_image('ndesign_team_placeholder.png'),
    			'team_designation' => esc_html__('Managing Director','ndesign'),
    		),
    		1 =>
    		array (
    			'team_name' => esc_html__('Harry M Lavoie','ndesign'),
    			'team_image' => ndesign_upload_ndesign_image('ndesign_team_placeholder.png'),
    			'team_designation' => esc_html__('Designer','ndesign'),
    		),
    		2 =>
    		array (
    			'team_name' => esc_html__('Thomas Smark','ndesign'),
    			'team_image' => ndesign_upload_ndesign_image('ndesign_team_placeholder.png'),
    			'team_designation' => esc_html__('Software Enginner','ndesign'),
    		),
    		3 =>
    		array (
    			'team_name' => esc_html__('Eric L. Wherry','ndesign'),
    			'team_image' => ndesign_upload_ndesign_image('ndesign_team_placeholder.png'),
    			'team_designation' => esc_html__('CEO','ndesign'),
    		),
    	),
    	'about_title' => esc_html__('About Us','ndesign'),
    	'about_subtitle' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit','ndesign'),
    	'about_des' => wp_kses('<p>Lorem Ipsum is simply dummy text of the printing and ypesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.</p>
    	<p><strong>Who We Are</strong><br>Lorem Ipsum is simply dummy text of the printing and ypesetting industry. Lorem Ipsum</p>
    	<p><strong>Why Choose Us?</strong><br>Lorem Ipsum is simply dummy text of the printing and ypesetting industry. Lorem Ipsum
    	</p>',wp_kses_allowed_html()),
    	'about_video' => esc_url('https://youtu.be/9xwazD5SyVg','ndesign'),
    	'testimonial_title' => esc_html__('Testimonials','ndesign'),
    	'services' =>
    	array (
    		0 =>
    		array (
    			'service_name' => esc_html__('Web Development','ndesign'),
    			'service_image' => ndesign_upload_ndesign_image('ndesign_service_placeholder.png'),
    			'service_description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis.','ndesign'),
    		),
    		1 =>
    		array (
    			'service_name' => esc_html__('Design & branding','ndesign'),
    			'service_image' => ndesign_upload_ndesign_image('ndesign_service_placeholder.png'),
    			'service_description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis.','ndesign'),
    		),
    		2 =>
    		array (
    			'service_name' => esc_html__('Mobile Apps','ndesign'),
    			'service_image' => ndesign_upload_ndesign_image('ndesign_service_placeholder.png'),
    			'service_description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis.','ndesign'),
    		),
    		3 =>
    		array (
    			'service_name' => esc_html__('Native Apps','ndesign'),
    			'service_image' => ndesign_upload_ndesign_image('ndesign_service_placeholder.png'),
    			'service_description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis.','ndesign'),
    		),
    	),
    	'testimonial_subtitle' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing eli','ndesign'),
    	'team_title' => esc_html__('Meet Our Team','ndesign'),
    	'service_subtitle' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing eli','ndesign'),
    	'service_title' => esc_html__('Our Services','ndesign'),
    	'contact_address' => esc_html__('"SPEC House", Parth Complex, Near Swasrik Cross Roads, Navarangpura, Ahmedabad 380009, INDIA.','ndesign'),
    	'blog_title' => esc_html__('Our Blog','ndesign'),
    	'blog_sub_title' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit.','ndesign'),
    	'blog_button_text' =>esc_html__('View All','ndesign'),
    	'blog_dummy_image' => wp_get_attachment_url(ndesign_upload_ndesign_image('ndesign_dummy_image_placeholder.jpg')),
    	'number_of_blog' => esc_attr('3','ndesign'),
    	'display_date' => true,
    	'about_image' => wp_get_attachment_url(ndesign_upload_ndesign_image('ndesign_about_placeholder.jpg')),
    	'site_description' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec blandit dictum lectus eu ultrices. Praesent blandit varius elit non mattis. Proin fringilla eros vitae imperdiet mollis. ','ndesign'),
    	'caddress_icon' => esc_attr('home','ndesign'),
    	'number_of_portfolio' => esc_attr('6','ndesign'),
    	'display_author' => true,
    	'portfolio_title' => esc_html__('Our Latest Project','ndesign'),
    	'portfolio_subtitle' => esc_html__('Our Awesome Work','ndesign'),
    	'contact_form_id' => '',
    	'read_more_button' => true,
    	'team_subtitle' => esc_html__('Lorem ipsum dolor sit amet, consectetur adipiscing elit','ndesign'),
    	'footer_subtitle' => esc_html__('Contact Us','ndesign'),
    	'contact_title' => esc_html__('Contact Us','ndesign'),
    	'contact_form_title' => esc_html__('Quick Contact','ndesign'),
    	'footer_social_title' => esc_html__('Stay Connected','ndesign'),
    );
	if (!get_theme_mod('is_data_setup')) {
		foreach ($my_theme_defaults as $key => $value) {
			set_theme_mod( $key, $value );
		}
// Create Ndesign Post for Blog start
		$author_id = 1;
		$slug = 'ndesign-post';
		$title = 'Ndesign Post';
		$content = '';
		if( !ndesign_post_exists_by_slug($slug,'post') ) {
			$post_id = wp_insert_post(
				array(
					'comment_status'    =>   'closed',
					'ping_status'       =>   'closed',
					'post_author'       =>   $author_id,
					'post_name'         =>   $slug,
					'post_title'        =>   $title,
					'post_content'      =>  $content,
					'post_status'       =>   'publish',
					'post_type'         =>   'post'
				)
			);
			$image_id=ndesign_upload_ndesign_image('ndesign_blog_placeholder.jpg');
			update_post_meta($post_id,'_wp_attached_file',get_post_meta($image_id,'_wp_attached_file',true));
			update_post_meta($post_id,'_thumbnail_id',$image_id);
		}
		require(ABSPATH.'/wp-admin/includes/taxonomy.php');
		$image_id=ndesign_upload_ndesign_image('ndesign_portfolio_placeholder.png');
		for ($i=1; $i <7 ; $i++) {
			$slug_portfolio = 'ndesign-portfolio-'.$i;
			$title_portfolio = 'Ndesign Portfolio '.$i;
			$content_portfolio = '';
			$categories=array('Marketing','Web Design','Branding','Graphic Design','Web Design','Web Design');
			$cat_id=wp_create_category($categories[$i-1]);
			if( !ndesign_post_exists_by_slug($slug_portfolio,'portfolio') ) {
				$post_id = wp_insert_post(
					array(
						'comment_status'    =>   'closed',
						'ping_status'       =>   'closed',
						'post_author'       =>   $author_id,
						'post_name'         =>   $slug_portfolio,
						'post_title'        =>   $title_portfolio,
						'post_content'      =>   $content_portfolio,
						'post_status'       =>   'publish',
						'post_type'         =>   'portfolio',
					)
				);
				wp_set_post_categories($post_id,array($cat_id));
				update_post_meta($post_id,'_wp_attached_file',get_post_meta($image_id,'_wp_attached_file',true));
				update_post_meta($post_id,'_thumbnail_id',$image_id);
			}
		}
	}
}
//  Close function of On switch theme