<?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() {
			// jQuery('.flex-control-thumbs').flexslider({
			// 	animation: "slide",
			// 	controlNav: "thumbnails",
			// 	start: function(slider) {
			// 		jQuery('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_user_to_customer_table($data)
{
	global $wpdb;
	$phone = null;
	if (!empty($_POST['phone'])) {
		$phone = $_POST['phone'];
	}
	// $existUser=$wpdb->get_results( "SELECT * FROM  js_users where `user_login`="$_POST['phone']" OR `user_email`=$data['user_email']");

	$customer = $wpdb->get_row("SELECT user_login FROM js_users WHERE user_login =" . $phone);

	if (empty($customer)) {
		$ref = null;
		$custId = generateJSCustomerCode(8);
		$dataArray = array(
			'name' => $data['user_login'], 'id' => $data['user_login'], 'password' => $data['user_pass'],
			'email' => $data['user_email'], 'member_code' => $custId
		);

		$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' => $custId,
			);
			$sanitize = array('%d', '%s', '%s', '%s', '%s', '%d');
		}
		$wpdb->insert('customer', $dataArray, $sanitize);
		if (!empty($wpdb->insert_id)) {



			$id = $wpdb->insert_id;
			$condition = array('code' => $id);
			$update = array('id' => $id, 'mobile' => $phone);

			$table_name = "customer";
			$wpdb->update($table_name, $update, $condition);

			// send welcome message to customers on SIGNUP
			define("JS_LEAD_BONUS", 0);
			$points = (!empty(JS_LEAD_BONUS) ? JS_LEAD_BONUS : 4000);
			$template = $wpdb->get_row("SELECT * FROM sms_template WHERE code=4", OBJECT);

			$template->template = str_replace("[CUSTOMER_ID]", $custId, $template->template);
			$template->template = str_replace("[NAME]", ucwords($data['user_email']), $template->template);
			$template->template = str_replace("[PASSWORD]", $data['user_pass'], $template->template);
			$template->template = str_replace("[P_POINTS]", $points, $template->template);
			//require_once("../../common_pages/sms1.php");
			$sender_id = 'JSHINE';
			$smsMobile = trim($_POST['phone']);
			$sms_Msg = urldecode(str_replace('	', '', $template->template));
			$encoded_message = urlencode($sms_Msg);
			$templateid = $template->templateid;
			sendWelcomeSms($custId, $_POST['phone'], $template->template, $templateid, 'jshine', '1');
			//pw_consolidate


			if ($points > 0) {

				$insertConsolidate = $wpdb->insert('pw_consolidate', ['userid' => $id, 'amt' => $points, 'remarks' => 'You have received' . $points . ' promotional wallets on signup', 'date' => date("Y-m-d")]);
			}
		}
	}
	$data['user_login'] = trim($_POST['phone']);
	return $data;
}

add_action('woocommerce_new_customer_data', 'add_user_to_customer_table');
// function for moving daily price updates on header 
function wp_daily_price_update()
{ 
	global $wpdb;
	?>
	<marquee class="scroll-text" onmouseover="this.stop();" onmouseout="this.start();">
		<?php 
		$result = $wpdb->get_results ( "SELECT daily_diamond_rate.rate, diamond_type.title FROM `daily_diamond_rate` INNER JOIN diamond_type ON daily_diamond_rate.diamond_type_code=diamond_type.code ORDER BY `daily_diamond_rate`.`c_date` DESC DESC LIMIT 10");
		foreach ($result as $key => $value) {
		?>
		<div class="dailyPriceDiv">
			<span class="dailyPriceDivType"><?php echo $value->title; ?> Diamond :
			</span>₹ <?php echo $value->rate; ?>
		</div>
		<?php };?>
		<?php 
		$result = $wpdb->get_results ( "SELECT daily_metal_rate.*, metal_type.name as title FROM `daily_metal_rate` INNER JOIN metal_type ON daily_metal_rate.metal_type_code=metal_type.code WHERE DATE(daily_metal_rate.c_date) = DATE(NOW())");
		foreach ($result as $key => $value) {
		?>
		<div class="dailyPriceDiv">
			<span class="dailyPriceDivType"><?php echo $value->title; ?>  :
			</span>₹ <?php echo $value->rate; ?>
		</div>
			<?php };?>
		</marquee>
		<?php 	
};


/* ###################
		*  Author: Kantsverma
		*  Method: Used to render the category and its banner section in ladning page
		*  Date:  18-07-22
		* ###################*/

function js_render_random_categories()
{

	// Get all terms
	$terms = get_terms('product_cat', array(
		'taxonomy'      => 'webshops',
		'hide_empty'    => false,
		'hide_empty' 	=> true,
	));

	// Randomize Term Array
	shuffle($terms);
	// Grab Indices 0 - 5, 6 in total
	$jsCategory = array_slice($terms, 0, 4);

	if (!empty($jsCategory) && !is_wp_error($jsCategory)) :
	?>
		<div class="banner-statistics-area">
			<div class="container">
				<div class="row row-20 mtn-20">
					<?php foreach ($jsCategory as $ckey => $catData) :

						$termimageid = get_term_meta($catData->term_id, 'thumbnail_id', true);
						$cat_thumbnail_img = wp_get_attachment_image_src($termimageid, array('545', '250'), true);
						// echo '<pre>';
						// print_r($cat_thumbnail_img['0']);	
						// echo '<pre>';		
					?>
						<div class="col-sm-6">
							<figure class="banner-statistics mt-20">
								<a href="<?= get_term_link($catData->term_id) ?>">
									<img src="<?= $cat_thumbnail_img['0']; ?>" width="640px" height="293px" alt="<?= ucfirst($catData->name) ?>">
								</a>
								<div class="banner-content text-right">
									<h5 class="banner-text1"><?= $catData->name ?></h5>
									<h2 class="banner-text2"><?= $catData->description ?></h2>
									<a href="<?= get_term_link($catData->term_id) ?>" class="btn btn-text">Shop Now</a>
								</div>
							</figure>
						</div>
					<?php endforeach; ?>
				</div>
			</div>
		</div>
	<?php
	endif;
};


/**
 * Function : sendWelcomeSms() is commond funcation to send the auto genrated sms to customer
 * Author: Kantsverma
 * Date:  22-06-20
 * @return \Illuminate\Http\Response
 */
function sendWelcomeSms($cust_id, $mobile, $msg, $templateId,  $senderId = 'jshine', $save = 1)
{
	$sms_Mobile = trim($mobile);
	$sms_Msg = urldecode(str_replace('	', '', $msg));

	if (!empty($sms_Mobile) && !empty($sms_Msg)) {
		$encoded_message = urlencode($sms_Msg);
		$url = 'http://sms.smsdukan.in/app/smsapi/index.php?key=258FB210510A42&campaign=189&routeid=100344&type=text&contacts=' . $sms_Mobile . '&senderid=jshine&msg=' . $encoded_message . '&template_id=' . $templateId;

		if (function_exists('curl_init')) {
			// initialize a new curl resource
			$ch = curl_init();
			// set the url to fetch
			curl_setopt($ch, CURLOPT_URL, $url);
			// don't give me the headers just the content
			curl_setopt($ch, CURLOPT_HEADER, 0);
			// return the value instead of printing the response to browser
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			// use a user agent to mimic a browser
			curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
			$content = curl_exec($ch);
			// remember to always close the session and free all resources 
			curl_close($ch);
		}
	}
}


/**
 * Function: generateMemberCode() is used to create random member code
 * Date:     21-04-22
 * Author:   kantsverma
 * @return \Illuminate\Http\Response
 */
function generateJSCustomerCode($length)
{
	$random = "";
	srand((float)microtime() * 1000000);
	$data = "123456789123456789123456789123456789";
	for ($i = 0; $i < $length; $i++) {
		$random .= substr($data, (rand() % (strlen($data))), 1);
	}
	return $random;
}

/**
 * Function: mycustom_func() is used to change error message
 * Date:     21-04-22
 * Author:   kantsverma
 * @return \Illuminate\Http\Response
 */
add_filter('gettext', 'mycustom_func');
function mycustom_func($translated_text)
{
	if ($translated_text == 'Sorry, that username already exists!') {
		$translated_text = 'An account is already registered with your phone number.';
	}
	return $translated_text;
}


// Change add to cart text on archives depending on product type
add_filter('woocommerce_product_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text');
function custom_woocommerce_product_add_to_cart_text()
{
	global $product;

	$product_type = $product->get_type();
	return __('Add to cart', 'woocommerce');
}

function get_random_products()
{
	global $post; // setup_postdata will not work without this being set (outside of the foreach loop)

	$args = array(
		'posts_per_page'   => 10,
		'orderby'          => 'rand',
		'post_type'        => 'product'
	);

	$random_products = get_posts($args);

	foreach ($random_products as $post) : setup_postdata($post);
		$_product = wc_get_product(get_the_ID());
	?>


		<div class="group-slide-item">
			<div class="group-item">
				<div class="group-item-thumb">
					<a href="product-details.html">
						<?= (has_post_thumbnail($_product->ID) ? get_the_post_thumbnail($_product->ID, 'pri-img') : '<img src="' . get_template_directory_uri() . '/assets/img/product/product-11.jpg" alt="Placeholder" />') ?>
					</a>
				</div>
				<div class="group-item-desc">
					<h5 class="group-product-name"><a href="<?php the_permalink(); ?>">
							<?php the_title(); ?></a></h5>
					<div class="price-box">
						<span class="price-regular"><?php echo $_product->get_price_html() ?></span>
					</div>
				</div>
			</div>
		</div>
	<?php endforeach;
	wp_reset_postdata();
}


function get_on_sale_products()
{
	global $post; // setup_postdata will not work without this being set (outside of the foreach loop)

	$args = array(
		'posts_per_page'    => 1200,
		'no_found_rows'     => 1,
		'post_status'       => 'publish',
		'post_type'         => 'product',
		'meta_query'        => WC()->query->get_meta_query(),
		'post__in'          => array_merge(array(0), wc_get_product_ids_on_sale())
	);

	$random_products = get_posts($args);

	foreach ($random_products as $post) : setup_postdata($post);
		$_product = wc_get_product(get_the_ID());

	?>


		<div class="group-slide-item">
			<div class="group-item">
				<div class="group-item-thumb">
					<a href="product-details.html">
						<?= (has_post_thumbnail($post->post->ID) ? get_the_post_thumbnail($post->post->ID, 'pri-img') : '<img src="' . get_template_directory_uri() . '/assets/img/product/product-11.jpg" alt="Placeholder" />') ?>

					</a>
				</div>
				<div class="group-item-desc">
					<h5 class="group-product-name"><a href="<?php the_permalink(); ?>">
							<?php the_title(); ?></a></h5>
					<div class="price-box">

						<span class="price-regular"><?php echo $_product->get_price_html() ?></span>
						<!-- <span class="price-old"><del><?php echo wc_price($sale); ?></del></span> -->
					</div>
				</div>
			</div>
		</div>
	<?php endforeach;
	wp_reset_postdata();
}


function get_categoies_and_products()
{
	(function_exists('js_render_random_categories') ? js_render_random_categories() : '') ?>

	<section class="product-area section-padding">
		<div class="container">
			<div class="row">
				<div class="col-12">
					<div class="section-title text-center">
						<h2 class="title"> Our products </h2>
						<p class="sub-title">Add our products to weekly lineup</p>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-12">
					<div class="product-container">
						<?php
						$cat_args = array(
							'orderby'    => 'name',
							'order'      => 'asc',
							'hide_empty' => true,
							'parent'   => 0
						);

						$product_categories = get_terms('product_cat', $cat_args);
						//print_r($product_categories);
						if (!empty($product_categories)) { ?>
							<div class="product-tab-menu">
								<ul class="nav justify-content-center">
									<?php $counter = 0;
									foreach ($product_categories as $key => $category) :  $counter++; ?>
										<li><a href="#tab_<?= $category->term_id; ?>" class="<?= ($counter === 1 ? 'active' : '') ?>" data-bs-toggle="tab"><?= $category->name; ?></a></li>
									<?php endforeach; ?>
								</ul>
							</div>
							<div class="tab-content">
								<?php $counter = 0;
								foreach ($product_categories as $key => $category) : $counter++; ?>
									<div class="tab-pane fade show <?= ($counter === 1 ? 'active' : '') ?>" id="tab_<?= $category->term_id; ?>">
										<div class="product-carousel-4 slick-row-10 slick-arrow-style">
											<?php
											 // array($post->ID)
											//$query_args = array('post__not_in' => array(), 'posts_per_page' => 5, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
											$query_args = array('posts_per_page' => 5, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
												array(
													'taxonomy' => 'product_cat',
													'field' => 'id',
													'terms' => $category->term_id
												)
											));

											$r = new WP_Query($query_args);

											if ($r->have_posts()) { ?>
												<?php while ($r->have_posts()) : $r->the_post();
													global $product; 
												?>
													<div class="product-item">
														<figure class="product-thumb">
															<a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>">
																<?= (has_post_thumbnail($product->ID) ? get_the_post_thumbnail($product->ID, 'pri-img') : '<img src="' . get_template_directory_uri() . '/assets/img/product/product-11.jpg" alt="Placeholder" />') ?>
															</a>
															<div class="product-badge">
																<div class="product-label new">
																	<span>new</span>
																</div>
															</div>
															<div class="cart-hover">
																<button class="btn btn-cart">
																	<?php woocommerce_template_loop_add_to_cart($r->post, $product); ?>
																</button>
															</div>
														</figure>
														<div class="product-caption text-center">
															<h6 class="product-name">
																<a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"> <?php the_title(); ?></a>
															</h6>
															<div class="price-box">
																<span class="price-regular"><?php echo $product->get_price_html(); ?></span>
															</div>
														</div>
													</div>
												<?php endwhile; ?>
											<?php  } ?>
										</div>
									</div>
								<?php endforeach; ?>
							</div>
						<?php  } ?>
					</div>
				</div>
			</div>
		</div>
	</section>
	<!-- product area end -->
	<?php
}


function get_static_models()
{
?>
	<div class="banner-slide-item">
		<figure class="banner-statistics">
			<a href="<?= wc_get_page_permalink('shop'); ?>">
				<img src="<?= get_template_directory_uri().'/assets/img/models/jshine-m-1.jpg'; ?>" width="360px" height="431px" alt="product banner">
			</a>
			<div class="banner-content banner-content_style2">
				<h5 class="banner-text3 text-center"><a href="<?= wc_get_page_permalink('shop'); ?>">Elegent Design</a></h5>
			</div>
		</figure>
	</div>
	<div class="banner-slide-item">
		<figure class="banner-statistics">
			<a href="<?= wc_get_page_permalink('shop'); ?>">
				<img src="<?= get_template_directory_uri().'/assets/img/models/jshine-m-2.jpg'; ?>" width="360px" height="431px" alt="product banner">
			</a>
			<div class="banner-content banner-content_style2">
				<h5 class="banner-text3  text-center"><a href="<?= wc_get_page_permalink('shop'); ?>">Antique Finish</a></h5>
			</div>
		</figure>
	</div>
	<div class="banner-slide-item">
		<figure class="banner-statistics">
			<a href="<?= wc_get_page_permalink('shop'); ?>">
				<img src="<?= get_template_directory_uri().'/assets/img/models/jshine-m-3.jpg'; ?>" width="360px" height="431px" alt="product banner">
			</a>
			<div class="banner-content banner-content_style2">
				<h5 class="banner-text3  text-center"><a href="<?= wc_get_page_permalink('shop'); ?>">Valentine Collection</a></h5>
			</div>
		</figure>
	</div>
	<div class="banner-slide-item">
		<figure class="banner-statistics">
			<a href="<?= wc_get_page_permalink('shop'); ?>">
				<img src="<?= get_template_directory_uri().'/assets/img/models/jshine-m-4.jpg'; ?>" width="360px" height="431px" alt="product banner">
			</a>
			<div class="banner-content banner-content_style2">
				<h5 class="banner-text3  text-center"><a href="<?= wc_get_page_permalink('shop'); ?>">Certified Jewellery</a></h5>
			</div>
		</figure>
	</div>			
<?php
}

/**
 * Function: my_remove_variation_price() Disable Variable Product Price Range completely:
 * Date:     27-08-22
 * Author:   kantsverma
 * @return \Illuminate\Http\Response
 */
 
add_filter( 'woocommerce_variable_sale_price_html', 'my_remove_variation_price', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'my_remove_variation_price', 10, 2 );
 
function my_remove_variation_price( $price ) {
	$price = '';
	return $price;
}
/* 
function wp_custom_pagination($args = [], $class = 'pagination') {
    if ($GLOBALS['wp_query']->max_num_pages <= 1) return;

    $args = wp_parse_args( $args, [
            'mid_size'                   => 3,
            'prev_next'                  => false,
			'prev_text' => __( '←', 'textdomain' ),
			'next_text' => __( '→', 'textdomain' ),
            'screen_reader_text' => __('Posts navigation', 'textdomain'),
    ]);

    $links       = paginate_links($args);
    $next_link = get_previous_posts_link($args['next_text']);
    $prev_link = get_next_posts_link($args['prev_text']);
    //$template    = apply_filters( 'navigation_markup_template', '<a href="" class="btn btn-outline-white text-dark">%3$s</a><li>%4$s</li>%5$s', $args, $class);
    $template    = apply_filters( 'navigation_markup_template', '<a class="page-numbers href="javascript:void(0)" current">%3$s</a>%4$s</li>%5$s', $args, $class);

    echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link);
} */
/**
 * 
 * 
 * Blog index.php pagination html
 * http://www.kriesi.at/archives/how-to-build-a-wordpress-post-pagination-without-plugin
 * 
 * 
 */ 

function learnplus_blog_pagination($pages = '', $range = 2)
{  
     $showitems = ($range * 2)+1;  

     global $paged;
     if(empty($paged)) $paged = 1;

     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }   

     if(1 != $pages)
     {
         echo "<nav class='text-center'>\n\n<ul class='page-numbers'>";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link(1)."' aria-label='Previous'><span aria-hidden='true'>←</span></a></li>";
         //if($paged > 1 && $showitems < $pages) echo "<li><a href='".get_pagenum_link($paged - 1)."' aria-label='Previous'><span aria-hidden='true'>←</span></a></li>";
         

         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<li class='current'><span aria-current='page' class='page-numbers current'>".$i."</span></li>" : "<li><a href='".get_pagenum_link($i)."' class='inactive'>".$i."</a></li>";
             }
         }

         if ($paged < $pages && $showitems < $pages) echo "<li><a class='page-numbers' href='".get_pagenum_link($paged + 1)."' aria-label='Previous'><span aria-hidden='true'>→</span></a></li>";  
         //if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<li><a class='page-numbers' href='".get_pagenum_link($pages)."' aria-label='Previous'><span aria-hidden='true'>→</span></a></li>";
         echo "</ul>\n</nav>";
     }
}

function awsm_application_upload_size_limit( $size ) {
	if ( is_singular( 'awsm_job_openings' ) ) {
		$size = 2 * 1024 * 1024; // 1 MB
	}
	return $size;
}
add_filter( 'upload_size_limit', 'awsm_application_upload_size_limit' );

function awsm_job_application_submitting() {
	global $awsm_response;
	if ( count( $awsm_response['error'] ) === 0 && isset( $_FILES ) && count( $_FILES ) > 0 ) {
		$error = false;
		foreach ( $_FILES as $file ) {
			$limit = 2 * 1024 * 1024; // 1 MB
			if ( $file['size'] > $limit ) {
				$error = true;
			}
		}
		if ( $error ) {
			$awsm_response['error'][] = 'The file you have selected is too large';
		}
	}
}
add_action( 'awsm_job_application_submitting', 'awsm_job_application_submitting' );

/* 
function add_css_pagination(){
?>  
    <style type="text/css">
        span.page-numbers.current {
            background: #a8307c;
            color: white;
        }
        button.btn a {
            color: #f4f4f4;
            text-decoration: none;
        }
        button.btn.btn-outline-info a {
            color: darkslategrey;
            font-weight: 600;
        }
        button.btn.btn-outline-info {
            background: unset;
            border: 1px solid turquoise;
            color: darkslategrey;
            font-weight: 600;
        }
    </style>

 <?php
 }
 add_action('wp_head','add_css_pagination'); */