<?php
/**
 * Functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package WordPress
 * @subpackage JShine_Theme
 * @since JShine 1.0
 */

// This theme requires WordPress 5.3 or later.
if ( version_compare( $GLOBALS['wp_version'], '5.3', '<' ) ) {
	require get_template_directory() . '/inc/back-compat.php';
}

if ( ! function_exists( 'JShine_Theme_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.
	 *
	 * @since JShine 1.0
	 *
	 * @return void
	 */
	function JShine_Theme_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on Twenty Twenty-One, use a find and replace
		 * to change 'jshine' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'jshine', 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.
		 * This theme does not use a hard-coded <title> tag in the document head,
		 * WordPress will provide it for us.
		 */
		add_theme_support( 'title-tag' );

		/**
		 * Add post-formats support.
		 */
		add_theme_support(
			'post-formats',
			array(
				'link',
				'aside',
				'gallery',
				'image',
				'quote',
				'status',
				'video',
				'audio',
				'chat',
			)
		);

		/*
		 * 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' );
		set_post_thumbnail_size( 1568, 9999 );

		register_nav_menus(
			array(
				'primary' => esc_html__( 'Primary menu', 'jshine' ),
				'footer'  => __( 'Secondary menu', 'jshine' ),
			)
		);

		/*
		 * Switch default core markup for search form, comment form, and comments
		 * to output valid HTML5.
		 */
		add_theme_support(
			'html5',
			array(
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
				'style',
				'script',
				'navigation-widgets',
			)
		);
		//add_theme_support( 'block-templates' );
		/*
		 * Add support for core custom logo.
		 *
		 * @link https://codex.wordpress.org/Theme_Logo
		 */
		$logo_width  = 300;
		$logo_height = 100;

		add_theme_support(
			'custom-logo',
			array(
				'height'               => $logo_height,
				'width'                => $logo_width,
				'flex-width'           => true,
				'flex-height'          => true,
				'unlink-homepage-logo' => true,
			)
		);

		// Add theme support for selective refresh for widgets.
		add_theme_support( 'customize-selective-refresh-widgets' );

		// Add support for Block Styles.
		add_theme_support( 'wp-block-styles' );

		// Add support for full and wide align images.
		add_theme_support( 'align-wide' );

		// Add support for editor styles.
		add_theme_support( 'editor-styles' );
		$background_color = get_theme_mod( 'background_color', 'D1E4DD' );
		if ( 127 > JShine_Theme_Custom_Colors::get_relative_luminance_from_hex( $background_color ) ) {
			add_theme_support( 'dark-editor-style' );
		}

		$editor_stylesheet_path = './assets/css/style-editor.css';

		// Note, the is_IE global variable is defined by WordPress and is used
		// to detect if the current browser is internet explorer.
		global $is_IE;
		if ( $is_IE ) {
			$editor_stylesheet_path = './assets/css/ie-editor.css';
		}

		// Enqueue editor styles.
		add_editor_style( $editor_stylesheet_path );

		// Add custom editor font sizes.
		add_theme_support(
			'editor-font-sizes',
			array(
				array(
					'name'      => esc_html__( 'Extra small', 'jshine' ),
					'shortName' => esc_html_x( 'XS', 'Font size', 'jshine' ),
					'size'      => 16,
					'slug'      => 'extra-small',
				),
				array(
					'name'      => esc_html__( 'Small', 'jshine' ),
					'shortName' => esc_html_x( 'S', 'Font size', 'jshine' ),
					'size'      => 18,
					'slug'      => 'small',
				),
				array(
					'name'      => esc_html__( 'Normal', 'jshine' ),
					'shortName' => esc_html_x( 'M', 'Font size', 'jshine' ),
					'size'      => 20,
					'slug'      => 'normal',
				),
				array(
					'name'      => esc_html__( 'Large', 'jshine' ),
					'shortName' => esc_html_x( 'L', 'Font size', 'jshine' ),
					'size'      => 24,
					'slug'      => 'large',
				),
				array(
					'name'      => esc_html__( 'Extra large', 'jshine' ),
					'shortName' => esc_html_x( 'XL', 'Font size', 'jshine' ),
					'size'      => 40,
					'slug'      => 'extra-large',
				),
				array(
					'name'      => esc_html__( 'Huge', 'jshine' ),
					'shortName' => esc_html_x( 'XXL', 'Font size', 'jshine' ),
					'size'      => 96,
					'slug'      => 'huge',
				),
				array(
					'name'      => esc_html__( 'Gigantic', 'jshine' ),
					'shortName' => esc_html_x( 'XXXL', 'Font size', 'jshine' ),
					'size'      => 144,
					'slug'      => 'gigantic',
				),
			)
		);

		// Custom background color.
		add_theme_support(
			'custom-background',
			array(
				'default-color' => 'd1e4dd',
			)
		);

		// Editor color palette.
		$black     = '#000000';
		$dark_gray = '#28303D';
		$gray      = '#39414D';
		$green     = '#D1E4DD';
		$blue      = '#D1DFE4';
		$purple    = '#D1D1E4';
		$red       = '#E4D1D1';
		$orange    = '#E4DAD1';
		$yellow    = '#EEEADD';
		$white     = '#FFFFFF';

		add_theme_support(
			'editor-color-palette',
			array(
				array(
					'name'  => esc_html__( 'Black', 'jshine' ),
					'slug'  => 'black',
					'color' => $black,
				),
				array(
					'name'  => esc_html__( 'Dark gray', 'jshine' ),
					'slug'  => 'dark-gray',
					'color' => $dark_gray,
				),
				array(
					'name'  => esc_html__( 'Gray', 'jshine' ),
					'slug'  => 'gray',
					'color' => $gray,
				),
				array(
					'name'  => esc_html__( 'Green', 'jshine' ),
					'slug'  => 'green',
					'color' => $green,
				),
				array(
					'name'  => esc_html__( 'Blue', 'jshine' ),
					'slug'  => 'blue',
					'color' => $blue,
				),
				array(
					'name'  => esc_html__( 'Purple', 'jshine' ),
					'slug'  => 'purple',
					'color' => $purple,
				),
				array(
					'name'  => esc_html__( 'Red', 'jshine' ),
					'slug'  => 'red',
					'color' => $red,
				),
				array(
					'name'  => esc_html__( 'Orange', 'jshine' ),
					'slug'  => 'orange',
					'color' => $orange,
				),
				array(
					'name'  => esc_html__( 'Yellow', 'jshine' ),
					'slug'  => 'yellow',
					'color' => $yellow,
				),
				array(
					'name'  => esc_html__( 'White', 'jshine' ),
					'slug'  => 'white',
					'color' => $white,
				),
			)
		);

		add_theme_support(
			'editor-gradient-presets',
			array(
				array(
					'name'     => esc_html__( 'Purple to yellow', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $purple . ' 0%, ' . $yellow . ' 100%)',
					'slug'     => 'purple-to-yellow',
				),
				array(
					'name'     => esc_html__( 'Yellow to purple', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $yellow . ' 0%, ' . $purple . ' 100%)',
					'slug'     => 'yellow-to-purple',
				),
				array(
					'name'     => esc_html__( 'Green to yellow', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $green . ' 0%, ' . $yellow . ' 100%)',
					'slug'     => 'green-to-yellow',
				),
				array(
					'name'     => esc_html__( 'Yellow to green', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $yellow . ' 0%, ' . $green . ' 100%)',
					'slug'     => 'yellow-to-green',
				),
				array(
					'name'     => esc_html__( 'Red to yellow', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $red . ' 0%, ' . $yellow . ' 100%)',
					'slug'     => 'red-to-yellow',
				),
				array(
					'name'     => esc_html__( 'Yellow to red', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $yellow . ' 0%, ' . $red . ' 100%)',
					'slug'     => 'yellow-to-red',
				),
				array(
					'name'     => esc_html__( 'Purple to red', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $purple . ' 0%, ' . $red . ' 100%)',
					'slug'     => 'purple-to-red',
				),
				array(
					'name'     => esc_html__( 'Red to purple', 'jshine' ),
					'gradient' => 'linear-gradient(160deg, ' . $red . ' 0%, ' . $purple . ' 100%)',
					'slug'     => 'red-to-purple',
				),
			)
		);

		/*
		* Adds starter content to highlight the theme on fresh sites.
		* This is done conditionally to avoid loading the starter content on every
		* page load, as it is a one-off operation only needed once in the customizer.
		*/
		if ( is_customize_preview() ) {
			require get_template_directory() . '/inc/starter-content.php';
			add_theme_support( 'starter-content', JShine_Theme_get_starter_content() );
		}

		// Add support for responsive embedded content.
		add_theme_support( 'responsive-embeds' );

		// Add support for custom line height controls.
		add_theme_support( 'custom-line-height' );

		// Add support for experimental link color control.
		add_theme_support( 'experimental-link-color' );

		// Add support for experimental cover block spacing.
		add_theme_support( 'custom-spacing' );

		// Add support for custom units.
		// This was removed in WordPress 5.6 but is still required to properly support WP 5.5.
		add_theme_support( 'custom-units' );
	}
}
add_action( 'after_setup_theme', 'JShine_Theme_setup' );

/**
 * Register widget area.
 *
 * @since JShine 1.0
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 *
 * @return void
 */
function JShine_Theme_widgets_init() {

	register_sidebar(
		array(
			'name'          => esc_html__( 'Footer About Us', 'jshine' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here to appear in your footer.', 'jshine' ),
			'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', 'JShine_Theme_widgets_init' );

/**
 * Set the content width in pixels, based on the theme's design and stylesheet.
 *
 * Priority 0 to make it available to lower priority callbacks.
 *
 * @since JShine 1.0
 *
 * @global int $content_width Content width.
 *
 * @return void
 */
function JShine_Theme_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( 'JShine_Theme_content_width', 750 );
}
add_action( 'after_setup_theme', 'JShine_Theme_content_width', 0 );

/**
 * Enqueue scripts and styles.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function JShine_Theme_scripts() {
	// Note, the is_IE global variable is defined by WordPress and is used
	// to detect if the current browser is internet explorer.
	global $is_IE, $wp_scripts;
	if ( $is_IE ) {
		// If IE 11 or below, use a flattened stylesheet with static values replacing CSS Variables.
		wp_enqueue_style( 'jshine-themestyle', get_template_directory_uri() . '/assets/css/ie.css', array(), wp_get_theme()->get( 'Version' ) );
	} else {
		// If not IE, use the standard stylesheet.
		wp_enqueue_style( 'jshine-themestyle', get_template_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) );
	}

	// RTL styles.
	wp_style_add_data( 'jshine-themestyle', 'rtl', 'replace' );

	// Print styles.
	//wp_enqueue_style( 'jshine-themeprint-style', get_template_directory_uri() . '/assets/css/print.css', array(), wp_get_theme()->get( 'Version' ), 'print' );
	wp_enqueue_style( 'jshine-theme-bootstrap-min', get_template_directory_uri() . '/assets/css/vendor/bootstrap.min.css');
	wp_enqueue_style( 'jshine-theme-stroke', get_template_directory_uri() . '/assets/css/vendor/pe-icon-7-stroke.css');
	wp_enqueue_style( 'jshine-theme-awesome-min', get_template_directory_uri() . '/assets/css/vendor/font-awesome.min.css');
	wp_enqueue_style( 'jshine-theme-slick', get_template_directory_uri() . '/assets/css/plugins/slick.min.css');
	wp_enqueue_style( 'jshine-theme-animate', get_template_directory_uri() . '/assets/css/plugins/animate.css');
	wp_enqueue_style( 'jshine-theme-nice-select', get_template_directory_uri() . '/assets/css/plugins/nice-select.css');
	wp_enqueue_style( 'jshine-theme-jqueryui', get_template_directory_uri() . '/assets/css/plugins/jqueryui.min.css');
	//wp_enqueue_style( 'jshine-theme-fontawesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css');
	

	// Register js script fils
	wp_enqueue_script(
		'jshine-theme-modernizr',
		get_template_directory_uri() . '/assets/js/vendor/modernizr-3.6.0.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-jquery',
		get_template_directory_uri() . '/assets/js/vendor/jquery-3.6.0.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-bootstrap-bundle',
		get_template_directory_uri() . '/assets/js/vendor/bootstrap.bundle.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-slick-min',
		get_template_directory_uri() . '/assets/js/plugins/slick.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-countdown-min',
		get_template_directory_uri() . '/assets/js/plugins/countdown.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-nice-select',
		get_template_directory_uri() . '/assets/js/plugins/nice-select.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-jqueryui-min',
		get_template_directory_uri() . '/assets/js/plugins/jqueryui.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-image-zoom-min',
		get_template_directory_uri() . '/assets/js/plugins/image-zoom.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	wp_enqueue_script(
		'jshine-theme-imagesloaded',
		get_template_directory_uri() . '/assets/js/plugins/imagesloaded.pkgd.min.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
	// wp_enqueue_script(
	// 	'jshine-theme-google-map-lib',
	// 	'https://maps.googleapis.com/maps/api/js?key=AIzaSyCfmCVTjRI007pC1Yk2o2d_EhgkjTsFVN8',
	// 	false,
	// 	true
	// );

	// wp_enqueue_script(
	// 	'jshine-theme-google-map',
	// 	get_template_directory_uri() . '/assets/js/plugins/google-map.js',
	// 	false,
	// 	true
	// );

	wp_enqueue_script(
		'jshine-theme-main',
		get_template_directory_uri() . '/assets/js/main.js',
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);										

	// Register the IE11 polyfill loader.
	wp_register_script(
		'jshine-themeie11-polyfills',
		null,
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);

	wp_add_inline_script(
		'jshine-themeie11-polyfills',
		wp_get_script_polyfill(
			$wp_scripts,
			array(
				'Element.prototype.matches && Element.prototype.closest && window.NodeList && NodeList.prototype.forEach' => 'jshine-themeie11-polyfills-asset',
			)
		)
	);

	// Main navigation scripts.
	if ( has_nav_menu( 'primary' ) ) {
		wp_enqueue_script(
			'jshine-themeprimary-navigation-script',
			get_template_directory_uri() . '/assets/js/primary-navigation.js',
			array( 'jshine-themeie11-polyfills' ),
			wp_get_theme()->get( 'Version' ),
			true
		);
	}

	// Responsive embeds script.
	// wp_enqueue_script(
	// 	'jshine-themeresponsive-embeds-script',
	// 	get_template_directory_uri() . '/assets/js/responsive-embeds.js',
	// 	array( 'jshine-themeie11-polyfills' ),
	// 	wp_get_theme()->get( 'Version' ),
	// 	true
	// );
}
add_action( 'wp_enqueue_scripts', 'JShine_Theme_scripts' );

/**
 * Enqueue block editor script.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function jshine_block_editor_script() {

	wp_enqueue_script( 'jshine-editor', get_theme_file_uri( '/assets/js/editor.js' ), array( 'wp-blocks', 'wp-dom' ), wp_get_theme()->get( 'Version' ), true );
}

add_action( 'enqueue_block_editor_assets', 'jshine_block_editor_script' );

/**
 * Fix skip link focus in IE11.
 *
 * This does not enqueue the script because it is tiny and because it is only for IE11,
 * thus it does not warrant having an entire dedicated blocking script being loaded.
 *
 * @since JShine 1.0
 *
 * @link https://git.io/vWdr2
 */
function JShine_Theme_skip_link_focus_fix() {

	// If SCRIPT_DEBUG is defined and true, print the unminified file.
	if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
		echo '<script>';
		include get_template_directory() . '/assets/js/skip-link-focus-fix.js';
		echo '</script>';
	}

	// The following is minified via `npx terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
	?>
	<script>
	/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",(function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())}),!1);
	</script>
	<?php
}
add_action( 'wp_print_footer_scripts', 'JShine_Theme_skip_link_focus_fix' );

/**
 * Enqueue non-latin language styles.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function JShine_Theme_non_latin_languages() {
	$custom_css = JShine_Theme_get_non_latin_css( 'front-end' );

	if ( $custom_css ) {
		wp_add_inline_style( 'jshine-themestyle', $custom_css );
	}
}
add_action( 'wp_enqueue_scripts', 'JShine_Theme_non_latin_languages' );

// SVG Icons class.
require get_template_directory() . '/classes/class-jshine-theme-svg-icons.php';

// Custom color classes.
require get_template_directory() . '/classes/class-jshine-theme-custom-colors.php';
new JShine_Theme_Custom_Colors();

// Enhance the theme by hooking into WordPress.
require get_template_directory() . '/inc/template-functions.php';

// Menu functions and filters.
require get_template_directory() . '/inc/menu-functions.php';

// Custom template tags for the theme.
require get_template_directory() . '/inc/template-tags.php';

// Customizer additions.
require get_template_directory() . '/classes/class-jshine-theme-customize.php';
new JShine_Theme_Customize();

// Block Patterns.
require get_template_directory() . '/inc/block-patterns.php';

// Block Styles.
require get_template_directory() . '/inc/block-styles.php';

// Dark Mode.
require_once get_template_directory() . '/classes/class-jshine-theme-dark-mode.php';
new JShine_Theme_Dark_Mode();

/**
 * Enqueue scripts for the customizer preview.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function jshine_customize_preview_init() {
	wp_enqueue_script(
		'jshine-customize-helpers',
		get_theme_file_uri( '/assets/js/customize-helpers.js' ),
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);

	wp_enqueue_script(
		'jshine-customize-preview',
		get_theme_file_uri( '/assets/js/customize-preview.js' ),
		array( 'customize-preview', 'customize-selective-refresh', 'jquery', 'jshine-customize-helpers' ),
		wp_get_theme()->get( 'Version' ),
		true
	);
}
add_action( 'customize_preview_init', 'jshine_customize_preview_init' );

/**
 * Enqueue scripts for the customizer.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function jshine_customize_controls_enqueue_scripts() {

	wp_enqueue_script(
		'jshine-customize-helpers',
		get_theme_file_uri( '/assets/js/customize-helpers.js' ),
		array(),
		wp_get_theme()->get( 'Version' ),
		true
	);
}
add_action( 'customize_controls_enqueue_scripts', 'jshine_customize_controls_enqueue_scripts' );

/**
 * Calculate classes for the main <html> element.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function jshine_the_html_classes() {
	/**
	 * Filters the classes for the main <html> element.
	 *
	 * @since JShine 1.0
	 *
	 * @param string The list of classes. Default empty string.
	 */
	$classes = apply_filters( 'jshine_html_classes', '' );
	if ( ! $classes ) {
		return;
	}
	echo 'class="' . esc_attr( $classes ) . '"';
}

/**
 * Add "is-IE" class to body if the user is on Internet Explorer.
 *
 * @since JShine 1.0
 *
 * @return void
 */
function jshine_add_ie_class() {
	?>
	<script>
	if ( -1 !== navigator.userAgent.indexOf( 'MSIE' ) || -1 !== navigator.appVersion.indexOf( 'Trident/' ) ) {
		document.body.classList.add( 'is-IE' );
	}
	</script>
	
	<?php
}
add_action( 'wp_footer', 'jshine_add_ie_class' );

/* ###################
*  Author: Kantsverma
*  Method: Changed WP nav menu classes
*  Date:  14-12-21
* ###################*/

function new_submenu_class($menu) {    
    $menu = preg_replace('/ class="sub-menu"/','/ class="dropdown" /',$menu);        
    return $menu;      
}

add_filter('wp_nav_menu','new_submenu_class'); 

/* ###################
*  Author: Kantsverma
*  Method: Used to save the additinal data in Generatl Setting tabs like address and social links 
*  Date:  15-12-21
* ###################*/
add_filter('admin_init', 'register_my_general_settings_fields');
function register_my_general_settings_fields()
{
	register_setting('general', 'jshine_address', 'esc_attr');
	add_settings_field('jshine_address', '<label for="jshine_address">'.__('Jshine Address' , 'jshine_address' ).'</label>' , 'general_settings_jshine_address_fields_html', 'general');

	register_setting('general', 'jshine_contacts', 'esc_attr');
	add_settings_field('jshine_contacts', '<label for="jshine_contacts">'.__('Jshine Contacts' , 'jshine_contacts' ).'</label>' , 'general_settings_jshine_contact_fields_html', 'general');

	register_setting('general', 'jshine_facebook', 'esc_attr');
	add_settings_field('jshine_facebook', '<label for="jshine_facebook">'.__('Facebook Url' , 'jshine_facebook' ).'</label>' , 'general_settings_jshine_facebook_url_html', 'general');	

	register_setting('general', 'jshine_instagram', 'esc_attr');
	add_settings_field('jshine_instagram', '<label for="jshine_instagram">'.__('Instagram Url' , 'jshine_instagram' ).'</label>' , 'general_settings_jshine_instagram_url_html', 'general');

	register_setting('general', 'jshine_twitter', 'esc_attr');
	add_settings_field('jshine_twitter', '<label for="jshine_twitter">'.__('Twitter Url' , 'jshine_twitter' ).'</label>' , 'general_settings_jshine_twitter_url_html', 'general');

	register_setting('general', 'jshine_youtube', 'esc_attr');
	add_settings_field('jshine_youtube', '<label for="jshine_youtube">'.__('Youtube Url' , 'jshine_youtube' ).'</label>' , 'general_settings_jshine_youtube_url_html', 'general');	

}

function general_settings_jshine_address_fields_html()
{
	echo '<input type="text" id="jshine_address" name="jshine_address" class="regular-text code" value="' . get_option( 'jshine_address', '' ) . '" />';
}

function general_settings_jshine_contact_fields_html()
{
	echo '<input name="jshine_contacts" type="tel" id="jshine_contacts" class="regular-text code" value="' . get_option( 'jshine_contacts', '' ) . '">';
}

function general_settings_jshine_facebook_url_html()
{
	echo '<input name="jshine_facebook" type="url" id="jshine_facebook" class="regular-text code" value="' . get_option( 'jshine_facebook', '' ) . '">';
}

function general_settings_jshine_instagram_url_html()
{
	echo '<input name="jshine_instagram" type="url" id="jshine_instagram" class="regular-text code" value="' . get_option( 'jshine_instagram', '' ) . '">';
}

function general_settings_jshine_twitter_url_html()
{
	echo '<input name="jshine_twitter" type="url" id="jshine_twitter" class="regular-text code" value="' . get_option( 'jshine_twitter', '' ) . '">';
}

function general_settings_jshine_youtube_url_html()
{
	echo '<input name="jshine_youtube" type="url" id="jshine_youtube" class="regular-text code" value="' . get_option( 'jshine_youtube', '' ) . '">';
}
/* ###################
*  Author: Kantsverma
*  Method: Change WordPress Admin Login Logo and busson styles 
*  Date:  18-12-21
* ###################*/
if ( !function_exists('tf_wp_admin_login_logo') ) :
 
    function tf_wp_admin_login_logo() { ?>
        <style type="text/css">
            body.login div#login h1 a {
                background-image: url('<?php echo get_template_directory_uri()."/assets/img/logo/js_logo.png"; ?>');
                /*Place your Logo URL*/
            }
			.wp-core-ui .button-primary {
				color: #fff;
				font-size: 15px;
				border-radius: 0;
				background-color: #c29958 !important;
				border-color: #c29958 !important;
			}
			.login a {
				color:  #c29958 !important;
			}
			.login #backtoblog a, .login #nav a {
				color:  #c29958 !important;
			}
			.login label {
				font-family: "Lato", sans-serif;
				color: #222222;
				font-weight: 700;
				margin: 0;
				line-height: 1.2;
			}				
        </style>
    <?php }
 
    add_action( 'login_enqueue_scripts', 'tf_wp_admin_login_logo' );
 
endif;
/* ###################
*  Author: Kantsverma
*  Method: Change WordPress Admin Login Logo's Title
*  Date:  20-12-21
* ###################*/
if ( !function_exists('tf_wp_admin_login_logo_title') ) :
 
    function tf_wp_admin_login_logo_title( $headertext ) {
        $headertext = esc_html__( get_bloginfo('name'), 'plugin-textdomain' );
        return $headertext;
    }
    add_filter( 'login_headertext', 'tf_wp_admin_login_logo_title' );
 
endif;
/* ###################
*  Author: Kantsverma
*  Method: Change WordPress Admin Login Logo Link URL
*  Date:  20-12-21
* ###################*/
if ( !function_exists('tf_wp_admin_login_logo_url') ) :
 
    function tf_wp_admin_login_logo_url() {
        return home_url();
    }
    add_filter( 'login_headerurl', 'tf_wp_admin_login_logo_url' );
 
endif;

// add_filter( 'woocommerce_single_product_carousel_options', 'cuswoo_update_woo_flexslider_options' );
// /** 
//  * Filer WooCommerce Flexslider options - Add Navigation Arrows
//  */
// function cuswoo_update_woo_flexslider_options( $options ) {

//     $options['directionNav'] = true;

//     return $options;
// }
/* ###################
*  Author: Kantsverma
*  Method: Load js in wp footer 
*  Date:  26-12-21
* ###################*/
add_action( 'wp_footer', 'my_footer_scripts' );
function my_footer_scripts(){
  ?>
  <script>
		jQuery(window).load(function(){ $('.flex-control-thumbs').flexslider({ animation: "slide", controlNav: "thumbnails", start: function(slider){ $('body').removeClass('loading'); } });

		jQuery( document ).ready(function() {
			console.log( "ready!" );
		});
</script>
<?php
}
/* ###################
*  Author: Kantsverma
*  Method: Use to make product page crousal working left right arrow 
*  Date:  26-12-21
* ###################*/
add_filter( 'woocommerce_single_product_carousel_options', 'customslug_single_product_carousel_options', 99, 1 );
function customslug_single_product_carousel_options( $options ) {
    //$options['animation'] = 'fade';
    $options['animationSpeed'] = 400;
	$options['directionNav'] = true;
    return $options;
}
/* ###################
*  Author: Kantsverma
*  Method: Used to remove the admin bar  from front end 
*  Date:  26-12-21
* ###################*/

add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
	if (!current_user_can('administrator') && !is_admin()) {
		show_admin_bar(false);
	}
}


/**
 * Register Custom Navigation Walker
 */
if ( !function_exists('register_navwalker') ) :
 
    function register_navwalker() {
        //return home_url();
		//wp_bootstrap4-mega-navwalker.php
		require_once get_template_directory() . '/classes/class-wp-bootstrap-navwalker.php';
    }
    add_filter( 'after_setup_theme', 'register_navwalker' );
endif;



  /**
     * Handles resetting the user's password.
     *
     * @param object $user     The user.
     * @param string $new_pass New password for the user in plaintext.
     */
  add_action('password_reset', 'password_reset_action', 10, 2);
  function password_reset_action($user, $new_pass) {
  // user email. $user return full user info
  	$email = $user->data->user_email;
  	// new entered password (plain text)
  	$password = $new_pass;
  	// Do whatever you want...
  	$condition = array(
            'mobile' => $user
                ->data
                ->user_login
        );
        $update = array(
            'password' => $new_pass
        );
        global $wpdb;
        $table_name = "customer";

        $wpdb->update($table_name, $update, $condition);
    }

    // discount for reward points
    add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_total', 25, 1 );
    function discount_based_on_total( $cart ) {
    	if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    	$current_user = wp_get_current_user(); // Getting current user logged in.
    	$user_id      = $current_user->ID;     // Get user ID to use in meta function.
    	$total = $cart->cart_contents_total;
    	global $wpdb;
    	$result = $wpdb->get_results( "SELECT * FROM  pw_consolidate where `userid`=$user_id AND  `status`!=1" );
    	$amnt=0;

    
    	foreach ($result as $key => $value) {
    		$amnt=$amnt+$value->amt;
    	}
    // Add the discount
    	$discount = $amnt;
    	if($discount>0){
    	$cart->add_fee( __('Reward Points', 'woocommerce'), -$discount );
    	}
    }

// adding user in custom table
	    function add_to_affuserr($data)
		{
			global $wpdb;

			$ref = null;
			$dataArray = array(
				'name' => $data['user_login'], 'id' => $data['user_login'], 'password' => $data['user_pass'],
				'email' => $data['user_email'], 'member_code' => rand(100000000, 9999999)
			);

			$sanitize = array('%s', '%s', '%s', '%s', '%d');
			if (!empty($_GET['ref'])) {
				$ref = $_GET['ref'];
				$dataArray = array(
					'sponsor_code' => $ref, 'name' => $data['user_login'], 'id' => $data['user_login'], 'password' => $data['user_pass'],
					'email' => $data['user_email'], 'member_code' => rand(100000000, 9999999)
				);
				$sanitize = array('%d', '%s', '%s', '%s', '%s', '%d');
			}
			$wpdb->insert('customer', $dataArray, $sanitize);

			return $data;
		}

		add_action( 'woocommerce_new_customer_data', 'add_to_affuserr');

    // function for moving daily price updates on header 
    if ( !function_exists('wp_daily_price_update') ) :
    	function wp_daily_price_update() { ?>
    		<marquee onmouseover="this.stop();" style="width: 100%;" onmouseout="this.start();" scrollamount="4">
		<?php 
		global $wpdb;
		$result = $wpdb->get_results ( "SELECT daily_diamond_rate.*, diamond_type.title FROM `daily_diamond_rate` INNER JOIN diamond_type ON daily_diamond_rate.diamond_type_code=diamond_type.code");
		foreach ($result as $key => $value) {
		?>
		<div class="dailyPriceDiv">
			<span class="dailyPriceDivType">24K Gold :
			</span>₹ 5220
			</div>
			<?php };?>
			</marquee>
		<?php } endif;?>
