HEX
Server: LiteSpeed
System: Linux cde2.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: dtptviut (1121)
PHP: 8.0.30
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/dtptviut/domains/morsunivers.dk/public_html/wp-content/themes/mts_dropshipping/functions.php
<?php
/*-----------------------------------------------------------------------------------*/
/*	Do not remove these lines, sky will fall on your head.
/*-----------------------------------------------------------------------------------*/
define( 'MTS_THEME_NAME', 'dropshipping' );
define( 'MTS_THEME_VERSION', '1.0.14' );

require_once( get_theme_file_path( 'theme-options.php' ) );
if ( ! isset( $content_width ) ) {
	$content_width = 870; // article content width without padding.
}

/*-----------------------------------------------------------------------------------*/
/*	Load Options
/*-----------------------------------------------------------------------------------*/
$mts_options = get_option( MTS_THEME_NAME );

/**
 * Register supported theme features, image sizes and nav menus.
 * Also loads translated strings.
 */
function mts_after_setup_theme() {
	if ( ! defined( 'MTS_THEME_WHITE_LABEL' ) ) {
		define( 'MTS_THEME_WHITE_LABEL', false );
	}

	add_theme_support( 'title-tag' );
	add_theme_support( 'automatic-feed-links' );

	load_theme_textdomain( 'dropshipping', get_template_directory() . '/lang' );

	add_theme_support( 'post-thumbnails' );
	set_post_thumbnail_size( 356, 250, true );
	add_image_size( 'dropshipping-featured', 370, 260, true ); // featured.
	add_image_size( 'dropshipping-featuredgrid1', 1170, 500, true ); // featuredgrid1.
	add_image_size( 'dropshipping-featuredgrid2', 570, 340, true ); // featuredgrid2.
	add_image_size( 'dropshipping-featuredfull', 870, 610, true ); // featured full width.
	add_image_size( 'dropshipping-related', 425, 300, true ); // related.
	add_image_size( 'dropshipping-widgetthumb', 75, 65, true ); // widgetthumb.
	add_image_size( 'dropshipping-widgetfull', 300, 200, true ); // sidebar full width.
	add_image_size( 'dropshipping-woo-cat', 277, 277, true ); // woo product category.
	add_image_size( 'dropshipping-woo-cat-big', 575, 575, true ); // woo product category big.
	add_image_size( 'dropshipping-sec-slider', 630, 387, true ); // Product Slider.

	register_nav_menus(
		[
			'top-menu'  => esc_html__( 'Top Menu', 'dropshipping' ),
			'primary'   => esc_html__( 'Primary Menu', 'dropshipping' ),
			'secondary' => esc_html__( 'Secondary Menu', 'dropshipping' ),
			'mobile'    => esc_html__( 'Mobile', 'dropshipping' ),
		]
	);

	add_action( 'init', 'dropshipping_wp_review_thumb_size', 11 );
	/**
	 * Tabs/ Review Image Size
	 */
	function dropshipping_wp_review_thumb_size() {
		add_image_size( 'wp_review_small', 75, 65, true );
		add_image_size( 'wp_review_large', 300, 200, true );
	}

	if ( mts_is_wc_active() ) {
		add_theme_support( 'woocommerce' );
		add_theme_support( 'wc-product-gallery-zoom' );
		add_theme_support( 'wc-product-gallery-lightbox' );
		add_theme_support( 'wc-product-gallery-slider' );
	}
}
add_action( 'after_setup_theme', 'mts_after_setup_theme' );

/**
 * Disable auto-updating the theme.
 */
function mts_disable_auto_update_theme( $update, $item ) {
	if ( isset( $item->slug ) && MTS_THEME_NAME == $item->slug ) {
		return false;
	}
	return $update;
}
add_filter( 'auto_update_theme', 'mts_disable_auto_update_theme', 10, 2 );

/**
 * Disable Google Typography plugin
 */
function mts_deactivate_google_typography_plugin() {
	if ( in_array( 'google-typography/google-typography.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
		deactivate_plugins( 'google-typography/google-typography.php' );
	}
}
add_action( 'admin_init', 'mts_deactivate_google_typography_plugin' );

/**
 * Determines whether the WooCommerce plugin is active or not.
 */
function mts_is_wc_active() {
	return class_exists( 'WooCommerce' );
}

/**
 * MTS icons for use in nav menus and icon select option.
 *
 * @return array
 */
function mts_get_icons() {
	$icons = array(
		__( 'Web Application Icons', 'dropshipping' ) => [
			'address-book', 'address-book-o', 'address-card', 'address-card-o', 'adjust', 'american-sign-language-interpreting', 'anchor', 'archive', 'area-chart', 'arrows', 'arrows-h', 'arrows-v', 'asl-interpreting', 'assistive-listening-systems', 'asterisk', 'at', 'audio-description', 'automobile', 'balance-scale', 'ban', 'bank', 'bar-chart', 'bar-chart-o', 'barcode', 'bars', 'bath', 'bathtub', 'battery', 'battery-0', 'battery-1', 'battery-2', 'battery-3', 'battery-4', 'battery-empty', 'battery-full', 'battery-half', 'battery-quarter', 'battery-three-quarters', 'bed', 'beer', 'bell', 'bell-o', 'bell-slash', 'bell-slash-o', 'bicycle', 'binoculars', 'birthday-cake', 'blind', 'bluetooth', 'bluetooth-b', 'bolt', 'bomb', 'book', 'bookmark', 'bookmark-o', 'braille', 'briefcase', 'bug', 'building', 'building-o', 'bullhorn', 'bullseye', 'bus', 'cab', 'calculator', 'calendar', 'calendar-check-o', 'calendar-minus-o', 'calendar-o', 'calendar-plus-o', 'calendar-times-o', 'camera', 'camera-retro', 'car', 'caret-square-o-down', 'caret-square-o-left', 'caret-square-o-right', 'caret-square-o-up', 'cart-arrow-down', 'cart-plus', 'cc', 'certificate', 'check', 'check-circle', 'check-circle-o', 'check-square', 'check-square-o', 'child', 'circle', 'circle-o', 'circle-o-notch', 'circle-thin', 'clock-o', 'clone', 'close', 'cloud', 'cloud-download', 'cloud-upload', 'code', 'code-fork', 'coffee', 'cog', 'cogs', 'comment', 'comment-o', 'commenting', 'commenting-o', 'comments', 'comments-o', 'compass', 'copyright', 'creative-commons', 'credit-card', 'credit-card-alt', 'crop', 'crosshairs', 'cube', 'cubes', 'cutlery', 'dashboard', 'database', 'deaf', 'deafness', 'desktop', 'diamond', 'dot-circle-o', 'download', 'drivers-license', 'drivers-license-o', 'edit', 'ellipsis-h', 'ellipsis-v', 'envelope', 'envelope-o', 'envelope-open', 'envelope-open-o', 'envelope-square', 'eraser', 'exchange', 'exclamation', 'exclamation-circle', 'exclamation-triangle', 'external-link', 'external-link-square', 'eye', 'eye-slash', 'eyedropper', 'fax', 'feed', 'female', 'fighter-jet', 'file-archive-o', 'file-audio-o', 'file-code-o', 'file-excel-o', 'file-image-o', 'file-movie-o', 'file-pdf-o', 'file-photo-o', 'file-picture-o', 'file-powerpoint-o', 'file-sound-o', 'file-video-o', 'file-word-o', 'file-zip-o', 'film', 'filter', 'fire', 'fire-extinguisher', 'flag', 'flag-checkered', 'flag-o', 'flash', 'flask', 'folder', 'folder-o', 'folder-open', 'folder-open-o', 'frown-o', 'futbol-o', 'gamepad', 'gavel', 'gear', 'gears', 'gift', 'glass', 'globe', 'graduation-cap', 'group', 'hand-grab-o', 'hand-lizard-o', 'hand-paper-o', 'hand-peace-o', 'hand-pointer-o', 'hand-rock-o', 'hand-scissors-o', 'hand-spock-o', 'hand-stop-o', 'handshake-o', 'hard-of-hearing', 'hashtag', 'hdd-o', 'headphones', 'heart', 'heart-o', 'heartbeat', 'history', 'home', 'hotel', 'hourglass', 'hourglass-1', 'hourglass-2', 'hourglass-3', 'hourglass-end', 'hourglass-half', 'hourglass-o', 'hourglass-start', 'i-cursor', 'id-badge', 'id-card', 'id-card-o', 'image', 'inbox', 'industry', 'info', 'info-circle', 'institution', 'key', 'keyboard-o', 'language', 'laptop', 'leaf', 'legal', 'lemon-o', 'level-down', 'level-up', 'life-bouy', 'life-buoy', 'life-ring', 'life-saver', 'lightbulb-o', 'line-chart', 'location-arrow', 'lock', 'low-vision', 'magic', 'magnet', 'mail-forward', 'mail-reply', 'mail-reply-all', 'male', 'map', 'map-marker', 'map-o', 'map-pin', 'map-signs', 'meh-o', 'microchip', 'microphone', 'microphone-slash', 'minus', 'minus-circle', 'minus-square', 'minus-square-o', 'mobile', 'mobile-phone', 'money', 'moon-o', 'mortar-board', 'motorcycle', 'mouse-pointer', 'music', 'navicon', 'newspaper-o', 'object-group', 'object-ungroup', 'paint-brush', 'paper-plane', 'paper-plane-o', 'paw', 'pencil', 'pencil-square', 'pencil-square-o', 'percent', 'phone', 'phone-square', 'photo', 'picture-o', 'pie-chart', 'plane', 'plug', 'plus', 'plus-circle', 'plus-square', 'plus-square-o', 'podcast', 'power-off', 'print', 'puzzle-piece', 'qrcode', 'question', 'question-circle', 'question-circle-o', 'quote-left', 'quote-right', 'random', 'recycle', 'refresh', 'registered', 'remove', 'reorder', 'reply', 'reply-all', 'retweet', 'road', 'rocket', 'rss', 'rss-square', 's15', 'search', 'search-minus', 'search-plus', 'send', 'send-o', 'server', 'share', 'share-alt', 'share-alt-square', 'share-square', 'share-square-o', 'shield', 'ship', 'shopping-bag', 'shopping-basket', 'shopping-cart', 'shower', 'sign-in', 'sign-language', 'sign-out', 'signal', 'signing', 'sitemap', 'sliders', 'smile-o', 'snowflake-o', 'soccer-ball-o', 'sort', 'sort-alpha-asc', 'sort-alpha-desc', 'sort-amount-asc', 'sort-amount-desc', 'sort-asc', 'sort-desc', 'sort-down', 'sort-numeric-asc', 'sort-numeric-desc', 'sort-up', 'space-shuttle', 'spinner', 'spoon', 'square', 'square-o', 'star', 'star-half', 'star-half-empty', 'star-half-full', 'star-half-o', 'star-o', 'sticky-note', 'sticky-note-o', 'street-view', 'suitcase', 'sun-o', 'support', 'tablet', 'tachometer', 'tag', 'tags', 'tasks', 'taxi', 'television', 'terminal', 'thermometer', 'thermometer-0', 'thermometer-1', 'thermometer-2', 'thermometer-3', 'thermometer-4', 'thermometer-empty', 'thermometer-full', 'thermometer-half', 'thermometer-quarter', 'thermometer-three-quarters', 'thumb-tack', 'thumbs-down', 'thumbs-o-down', 'thumbs-o-up', 'thumbs-up', 'ticket', 'times', 'times-circle', 'times-circle-o', 'times-rectangle', 'times-rectangle-o', 'tint', 'toggle-down', 'toggle-left', 'toggle-off', 'toggle-on', 'toggle-right', 'toggle-up', 'trademark', 'trash', 'trash-o', 'tree', 'trophy', 'truck', 'tty', 'tv', 'umbrella', 'universal-access', 'university', 'unlock', 'unlock-alt', 'unsorted', 'upload', 'user', 'user-circle', 'user-circle-o', 'user-o', 'user-plus', 'user-secret', 'user-times', 'users', 'vcard', 'vcard-o', 'video-camera', 'volume-control-phone', 'volume-down', 'volume-off', 'volume-up', 'warning', 'wheelchair', 'wheelchair-alt', 'wifi', 'window-close', 'window-close-o', 'window-maximize', 'window-minimize', 'window-restore', 'wrench'
		],
		__( 'Accessibility Icons', 'dropshipping' ) => [
			'american-sign-language-interpreting', 'asl-interpreting', 'assistive-listening-systems', 'audio-description', 'blind', 'braille', 'cc', 'deaf', 'deafness', 'hard-of-hearing', 'low-vision', 'question-circle-o', 'sign-language', 'signing', 'tty', 'universal-access', 'volume-control-phone', 'wheelchair', 'wheelchair-alt'
		],
		__( 'Hand Icons', 'dropshipping' ) => [
			'hand-grab-o', 'hand-lizard-o', 'hand-o-down', 'hand-o-left', 'hand-o-right', 'hand-o-up', 'hand-paper-o', 'hand-peace-o', 'hand-pointer-o', 'hand-rock-o', 'hand-scissors-o', 'hand-spock-o', 'hand-stop-o', 'thumbs-down', 'thumbs-o-down', 'thumbs-o-up', 'thumbs-up'
		],
		__( 'Transportation Icons', 'dropshipping' ) => [
			'ambulance', 'automobile', 'bicycle', 'bus', 'cab', 'car', 'fighter-jet', 'motorcycle', 'plane', 'rocket', 'ship', 'space-shuttle', 'subway', 'taxi', 'train', 'truck', 'wheelchair', 'wheelchair-alt'
		],
		__( 'Gender Icons', 'dropshipping' ) => [
			'genderless', 'intersex', 'mars', 'mars-double', 'mars-stroke', 'mars-stroke-h', 'mars-stroke-v', 'mercury', 'neuter', 'transgender', 'transgender-alt', 'venus', 'venus-double', 'venus-mars'
		],
		__( 'File Type Icons', 'dropshipping' ) => [
			'file', 'file-archive-o', 'file-audio-o', 'file-code-o', 'file-excel-o', 'file-image-o', 'file-movie-o', 'file-o', 'file-pdf-o', 'file-photo-o', 'file-picture-o', 'file-powerpoint-o', 'file-sound-o', 'file-text', 'file-text-o', 'file-video-o', 'file-word-o', 'file-zip-o'
		],
		__( 'Spinner Icons', 'dropshipping' ) => [
			'circle-o-notch', 'cog', 'gear', 'refresh', 'spinner'
		],
		__( 'Form Control Icons', 'dropshipping' ) => [
			'check-square', 'check-square-o', 'circle', 'circle-o', 'dot-circle-o', 'minus-square', 'minus-square-o', 'plus-square', 'plus-square-o', 'square', 'square-o'
		],
		__( 'Payment Icons', 'dropshipping' ) => [
			'cc-amex', 'cc-diners-club', 'cc-discover', 'cc-jcb', 'cc-mastercard', 'cc-paypal', 'cc-stripe', 'cc-visa', 'credit-card', 'credit-card-alt', 'google-wallet', 'paypal'
		],
		__( 'Chart Icons', 'dropshipping' ) => [
			'area-chart', 'bar-chart', 'bar-chart-o', 'line-chart', 'pie-chart'
		],
		__( 'Currency Icons', 'dropshipping' ) => [
			'bitcoin', 'btc', 'cny', 'dollar', 'eur', 'euro', 'gbp', 'gg', 'gg-circle', 'ils', 'inr', 'jpy', 'krw', 'money', 'rmb', 'rouble', 'rub', 'ruble', 'rupee', 'shekel', 'sheqel', 'try', 'turkish-lira', 'usd', 'won', 'yen'
		],
		__( 'Text Editor Icons', 'dropshipping' ) => [
			'align-center', 'align-justify', 'align-left', 'align-right', 'bold', 'chain', 'chain-broken', 'clipboard', 'columns', 'copy', 'cut', 'dedent', 'eraser', 'file', 'file-o', 'file-text', 'file-text-o', 'files-o', 'floppy-o', 'font', 'header', 'indent', 'italic', 'link', 'list', 'list-alt', 'list-ol', 'list-ul', 'outdent', 'paperclip', 'paragraph', 'paste', 'repeat', 'rotate-left', 'rotate-right', 'save', 'scissors', 'strikethrough', 'subscript', 'superscript', 'table', 'text-height', 'text-width', 'th', 'th-large', 'th-list', 'underline', 'undo', 'unlink'
		],
		__( 'Directional Icons', 'dropshipping' ) => [
			'angle-double-down', 'angle-double-left', 'angle-double-right', 'angle-double-up', 'angle-down', 'angle-left', 'angle-right', 'angle-up', 'arrow-circle-down', 'arrow-circle-left', 'arrow-circle-o-down', 'arrow-circle-o-left', 'arrow-circle-o-right', 'arrow-circle-o-up', 'arrow-circle-right', 'arrow-circle-up', 'arrow-down', 'arrow-left', 'arrow-right', 'arrow-up', 'arrows', 'arrows-alt', 'arrows-h', 'arrows-v', 'caret-down', 'caret-left', 'caret-right', 'caret-square-o-down', 'caret-square-o-left', 'caret-square-o-right', 'caret-square-o-up', 'caret-up', 'chevron-circle-down', 'chevron-circle-left', 'chevron-circle-right', 'chevron-circle-up', 'chevron-down', 'chevron-left', 'chevron-right', 'chevron-up', 'exchange', 'hand-o-down', 'hand-o-left', 'hand-o-right', 'hand-o-up', 'long-arrow-down', 'long-arrow-left', 'long-arrow-right', 'long-arrow-up', 'toggle-down', 'toggle-left', 'toggle-right', 'toggle-up'
		],
		__( 'Video Player Icons', 'dropshipping' ) => [
			'arrows-alt', 'backward', 'compress', 'eject', 'expand', 'fast-backward', 'fast-forward', 'forward', 'pause', 'pause-circle', 'pause-circle-o', 'play', 'play-circle', 'play-circle-o', 'random', 'step-backward', 'step-forward', 'stop', 'stop-circle', 'stop-circle-o', 'youtube-play'
		],
		__( 'Brand Icons', 'dropshipping' ) => [
			'500px', 'adn', 'amazon', 'android', 'angellist', 'apple', 'bandcamp', 'behance', 'behance-square', 'bitbucket', 'bitbucket-square', 'bitcoin', 'black-tie', 'bluetooth', 'bluetooth-b', 'btc', 'buysellads', 'cc-amex', 'cc-diners-club', 'cc-discover', 'cc-jcb', 'cc-mastercard', 'cc-paypal', 'cc-stripe', 'cc-visa', 'chrome', 'codepen', 'codiepie', 'connectdevelop', 'contao', 'css3', 'dashcube', 'delicious', 'deviantart', 'digg', 'dribbble', 'dropbox', 'drupal', 'edge', 'eercast', 'empire', 'envira', 'etsy', 'expeditedssl', 'fa', 'facebook', 'facebook-f', 'facebook-official', 'facebook-square', 'firefox', 'first-order', 'flickr', 'font-awesome', 'fonticons', 'fort-awesome', 'forumbee', 'foursquare', 'free-code-camp', 'ge', 'get-pocket', 'gg', 'gg-circle', 'git', 'git-square', 'github', 'github-alt', 'github-square', 'gitlab', 'gittip', 'glide', 'glide-g', 'google', 'google-plus', 'google-plus-circle', 'google-plus-official', 'google-plus-square', 'google-wallet', 'gratipay', 'grav', 'hacker-news', 'houzz', 'html5', 'imdb', 'instagram', 'internet-explorer', 'ioxhost', 'joomla', 'jsfiddle', 'lastfm', 'lastfm-square', 'leanpub', 'linkedin', 'linkedin-square', 'linode', 'linux', 'maxcdn', 'meanpath', 'medium', 'meetup', 'mixcloud', 'modx', 'odnoklassniki', 'odnoklassniki-square', 'opencart', 'openid', 'opera', 'optin-monster', 'pagelines', 'paypal', 'pied-piper', 'pied-piper-alt', 'pied-piper-pp', 'pinterest', 'pinterest-p', 'pinterest-square', 'product-hunt', 'qq', 'quora', 'ra', 'ravelry', 'rebel', 'reddit', 'reddit-alien', 'reddit-square', 'renren', 'resistance', 'safari', 'scribd', 'sellsy', 'share-alt', 'share-alt-square', 'shirtsinbulk', 'simplybuilt', 'skyatlas', 'skype', 'slack', 'slideshare', 'snapchat', 'snapchat-ghost', 'snapchat-square', 'soundcloud', 'spotify', 'stack-exchange', 'stack-overflow', 'steam', 'steam-square', 'stumbleupon', 'stumbleupon-circle', 'superpowers', 'telegram', 'tencent-weibo', 'themeisle', 'trello', 'tripadvisor', 'tumblr', 'tumblr-square', 'twitch', 'twitter', 'twitter-square', 'usb', 'viacoin', 'viadeo', 'viadeo-square', 'vimeo', 'vimeo-square', 'vine', 'vk', 'wechat', 'weibo', 'weixin', 'whatsapp', 'wikipedia-w', 'windows', 'wordpress', 'wpbeginner', 'wpexplorer', 'wpforms', 'xing', 'xing-square', 'y-combinator', 'y-combinator-square', 'yahoo', 'yc', 'yc-square', 'yelp', 'yoast', 'youtube', 'youtube-play', 'youtube-square'
		],
		__( 'Medical Icons', 'dropshipping' ) => [
			'ambulance', 'h-square', 'heart', 'heart-o', 'heartbeat', 'hospital-o', 'medkit', 'plus-square', 'stethoscope', 'user-md', 'wheelchair', 'wheelchair-alt'
		]
	);

	return $icons;
}

/**
 * Create pages on Theme Activation
 */
if ( isset( $_GET['activated'] ) && is_admin() ) {
	$pages_to_add = array(
		array(
			'post_type'     => 'page',
			'post_title'    => esc_html__('Wishlist', 'dropshipping'),
			'post_content'  => '',
			'page_template' => 'page-wishlist.php',
			'post_status'   => 'publish',
			'post_author'   => 1,
		),
		array(
			'post_type'     => 'page',
			'post_title'    => esc_html__('Blog', 'dropshipping'),
			'post_content'  => '',
			'page_template' => 'page-blog.php',
			'post_status'   => 'publish',
			'post_author'   => 1,
		)
	);
	foreach ( $pages_to_add as $page_settings ) {
		$page_check = get_page_by_title( $page_settings['post_title'] );
		if ( ! isset( $page_check->ID ) ) {
			$new_page_id = wp_insert_post( $page_settings );
			if ( ! empty( $page_settings['page_template'] ) ) {
				update_post_meta( $new_page_id, '_wp_page_template', $page_settings['page_template'] );
			}
			$page_id = $new_page_id;
		} else {
			$page_id = $page_check->ID;
		}
	}
}


/**
 * Get the current post's thumbnail URL.
 *
 * @param string $size
 *
 * @return string
 */
function mts_get_thumbnail_url( $size = 'full' ) {
	$post_id = get_the_ID() ;
	if (has_post_thumbnail( $post_id ) ) {
		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size );
		return $image[0];
	}

	// use first attached image
	$images = get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post_id );
	if (! empty($images)) {
		$image = reset($images);
		$image_data = wp_get_attachment_image_src( $image->ID, $size );
		return $image_data[0];
	}

	// use no preview fallback
	if ( file_exists( get_template_directory().'/images/nothumb-' . $size . '.png' ) ) {
		return get_template_directory_uri().'/images/nothumb-' . $size . '.png';
	}

	return '';
}

/**
 * Create and show column for featured in portfolio items list admin page.
 * @param $post_ID
 *
 * @return string url
 */
function mts_get_featured_image( $post_ID ) {
	$post_thumbnail_id = get_post_thumbnail_id( $post_ID );
	if ($post_thumbnail_id) {
		$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'dropshipping-widgetfull' );
		return $post_thumbnail_img[0];
	}
}

/**
 * Adds a `Featured Image` column header in the item list admin page.
 *
 * @param array $defaults
 *
 * @return array
 */
function mts_columns_head( $defaults ) {
	if ( get_post_type() == 'post' ) {
		$defaults['featured_image'] = __( 'Featured Image', 'dropshipping' );
	}

	return $defaults;
}
add_filter('manage_posts_columns', 'mts_columns_head');

/**
 * Adds a `Featured Image` column row value in the item list admin page.
 *
 * @param string $column_name The name of the column to display.
 * @param int $post_ID The ID of the current post.
 */
function mts_columns_content( $column_name, $post_ID ) {
	if ( $column_name == 'featured_image' ) {
		$post_featured_image = mts_get_featured_image($post_ID);
		if ( $post_featured_image ) {
			echo '<img width="150" height="100" src="' . esc_url( $post_featured_image ) . '" />';
		}
	}
}
add_action('manage_posts_custom_column', 'mts_columns_content', 10, 2);

/**
 * Admin styles
 */
function mts_columns_css() {
	echo '<style type="text/css">.posts .column-featured_image img { max-width: 100%; height: auto }</style>';
}
add_action( 'admin_print_styles', 'mts_columns_css' );

/**
 * Change the HTML markup of the post thumbnail.
 *
 * @param string $html
 * @param int $post_id
 * @param string $post_image_id
 * @param int $size
 * @param string $attr
 *
 * @return string
 */
function mts_post_image_html( $html, $post_id, $post_image_id, $size, $attr ) {
	if ( has_post_thumbnail( $post_id ) || 'shop_thumbnail' === $size )
		return $html;

	// use first attached image
	$images = get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post_id );
	if ( ! empty( $images ) ) {
		$image = reset( $images );
		return wp_get_attachment_image( $image->ID, $size, false, $attr );
	}

	// use no preview fallback.
	if ( file_exists( get_template_directory() . '/images/nothumb-' . $size . '.png' ) ) {
		$placeholder     = get_template_directory_uri() . '/images/nothumb-' . $size . '.png';
		$placeholder_src = $placeholder;
		$layzr_attr      = '';

		$placeholder_classs = 'attachment-' . $size . ' wp-post-image';
		return '<img src="' . esc_url( $placeholder_src ) . '" class="' . esc_attr( $placeholder_classs ) . '" alt="' . esc_html( get_the_title() ) . '"' . $layzr_attr . '>';
	}
	return '';
}
add_filter( 'post_thumbnail_html', 'mts_post_image_html', 10, 5 );

/**
 * Enable Widgetized sidebar and Footer
 */
function mts_register_sidebars() {
	$mts_options = get_option( MTS_THEME_NAME );

	// Default sidebar
	register_sidebar( array(
		'name'          => esc_html__( 'Sidebar', 'dropshipping' ),
		'description'   => esc_html__( 'Default sidebar.', 'dropshipping' ),
		'id'            => 'sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	// Header Ad sidebar
	register_sidebar(array(
		'name'          => esc_html__( 'Header Ad', 'dropshipping' ),
		'description'   => esc_html__( '728x90 Ad Area', 'dropshipping' ),
		'id'            => 'widget-header',
		'before_widget' => '<div id="%1$s" class="widget-header">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	));

	// Newsletter Widget
	register_sidebar(array(
		'name'          => esc_html__( 'Newsletter Widget', 'dropshipping' ),
		'description'   => esc_html__( 'Set up a WP Subscribe widget in this widget area to display newsletter ', 'dropshipping' ),
		'id'            => 'widget-subscribe',
		'before_widget' => '<div id="%1$s" class="widget %2$s">',
		'after_widget'  => '</div>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	));

	// Top level footer widget areas
	if ( ! empty( $mts_options['mts_first_footer'] ) ) {
		if ( empty( $mts_options['mts_first_footer_num'] ) ) $mts_options['mts_first_footer_num'] = 4;
		register_sidebars( $mts_options['mts_first_footer_num'], array(
			'name'          => esc_html__( 'Footer %d', 'dropshipping' ),
			'description'   => esc_html__( 'Appears at the top of the footer.', 'dropshipping' ),
			'id'            => 'footer-first',
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}

	// Custom sidebars
	if ( ! empty( $mts_options['mts_custom_sidebars'] ) && is_array( $mts_options['mts_custom_sidebars'] )) {
		foreach( $mts_options['mts_custom_sidebars'] as $sidebar ) {
			if ( ! empty( $sidebar['mts_custom_sidebar_id'] ) && ! empty( $sidebar['mts_custom_sidebar_id'] ) && $sidebar['mts_custom_sidebar_id'] != 'sidebar-' ) {
				register_sidebar( array( 'name' => '' . $sidebar['mts_custom_sidebar_name'] . '', 'id' => '' . sanitize_title( strtolower( $sidebar['mts_custom_sidebar_id'] )) . '', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>' ));
			}
		}
	}

	if ( mts_is_wc_active() ) {
		// Register WooCommerce Shop and Single Product Sidebar
		register_sidebar( array(
			'name'          => esc_html__( 'Shop Page Sidebar', 'dropshipping' ),
			'description'   => esc_html__( 'Appears on Shop main page and product archive pages.', 'dropshipping' ),
			'id'            => 'shop-sidebar',
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
		register_sidebar( array(
			'name'          => esc_html__( 'WC Single Page Sidebar', 'dropshipping' ),
			'description'   => esc_html__( 'Appears on woocommerce single pages, where sidebar option is selected', 'dropshipping' ),
			'id'            => 'product-sidebar',
			'before_widget' => '<div id="%1$s" class="widget %2$s">',
			'after_widget'  => '</div>',
			'before_title'  => '<h3 class="widget-title">',
			'after_title'   => '</h3>',
		) );
	}
}

add_action( 'widgets_init', 'mts_register_sidebars' );

/**
 * Retrieve the ID of the sidebar to use on the active page.
 *
 * @return string
 */
function mts_custom_sidebar() {
	$mts_options = get_option( MTS_THEME_NAME );

	// Default sidebar.
	$sidebar = 'sidebar';

	if ( is_home() && ! empty( $mts_options['mts_sidebar_for_home'] )) $sidebar = $mts_options['mts_sidebar_for_home'];
	if ( is_single() && ! empty( $mts_options['mts_sidebar_for_post'] )) $sidebar = $mts_options['mts_sidebar_for_post'];
	if ( is_page() && ! empty( $mts_options['mts_sidebar_for_page'] )) $sidebar = $mts_options['mts_sidebar_for_page'];

	// Archives.
	if ( is_archive() && ! empty( $mts_options['mts_sidebar_for_archive'] )) $sidebar = $mts_options['mts_sidebar_for_archive'];
	if ( is_category() && ! empty( $mts_options['mts_sidebar_for_category'] )) $sidebar = $mts_options['mts_sidebar_for_category'];
	if ( is_tag() && ! empty( $mts_options['mts_sidebar_for_tag'] )) $sidebar = $mts_options['mts_sidebar_for_tag'];
	if ( is_date() && ! empty( $mts_options['mts_sidebar_for_date'] )) $sidebar = $mts_options['mts_sidebar_for_date'];
	if ( is_author() && ! empty( $mts_options['mts_sidebar_for_author'] )) $sidebar = $mts_options['mts_sidebar_for_author'];

	// Other.
	if ( is_search() && ! empty( $mts_options['mts_sidebar_for_search'] )) $sidebar = $mts_options['mts_sidebar_for_search'];
	if ( is_404() && ! empty( $mts_options['mts_sidebar_for_notfound'] )) $sidebar = $mts_options['mts_sidebar_for_notfound'];

	// Woocommerce.
	if ( mts_is_wc_active() ) {
		if ( is_shop() || is_product_taxonomy() ) {
			$sidebar = 'shop-sidebar';
			if ( ! empty( $mts_options['mts_sidebar_for_shop'] )) {
				$sidebar = $mts_options['mts_sidebar_for_shop'];
			}
		}
		if ( is_cart() || is_checkout() || is_account_page() ) {
			$sidebar = 'product-sidebar';
			if ( ! empty( $mts_options['mts_sidebar_for_product'] )) {
				$sidebar = $mts_options['mts_sidebar_for_product'];
			}
		}
	}

	// Page/post specific custom sidebar-
	if ( is_page() || is_single() ) {
		wp_reset_postdata();
		global $wp_registered_sidebars;
		$custom = get_post_meta( get_the_ID(), '_mts_custom_sidebar', true );
		if ( ! empty( $custom ) && array_key_exists( $custom, $wp_registered_sidebars ) || 'mts_nosidebar' == $custom ) {
			$sidebar = $custom;
		}
	}

	// Posts page
	if ( is_home() && ! is_front_page() && 'page' == get_option( 'show_on_front' ) ) {
		wp_reset_postdata();
		global $wp_registered_sidebars;
		$custom = get_post_meta( get_option( 'page_for_posts' ), '_mts_custom_sidebar', true );
		if ( ! empty( $custom ) && array_key_exists( $custom, $wp_registered_sidebars ) || 'mts_nosidebar' == $custom ) {
			$sidebar = $custom;
		}
	}

	return $sidebar;
}

/*-----------------------------------------------------------------------------------*/
/*  Load Widgets, Actions and Libraries
/*-----------------------------------------------------------------------------------*/

// Add the 125x125 Ad Block Custom Widget.
include_once( get_theme_file_path( "functions/widget-ad125.php" ) );

// Add the 300x250 Ad Block Custom Widget.
include_once( get_theme_file_path( "functions/widget-ad300.php" ) );

// Add the 728x90 Ad Block Custom Widget.
include_once( get_theme_file_path( "functions/widget-ad728.php" ) );

// Add the Latest Tweets Custom Widget.
include_once( get_theme_file_path( "functions/widget-tweets.php" ) );

// Add Recent Posts Widget.
include_once( get_theme_file_path( "functions/widget-recentposts.php" ) );

// Add Related Posts Widget.
include_once( get_theme_file_path( "functions/widget-relatedposts.php" ) );

// Add Author Posts Widget.
include_once( get_theme_file_path( "functions/widget-authorposts.php" ) );

// Add Popular Posts Widget.
include_once( get_theme_file_path( "functions/widget-popular.php" ) );

// Add Facebook Like box Widget.
include_once( get_theme_file_path( "functions/widget-fblikebox.php" ) );

// Add Social Profile Widget.
include_once( get_theme_file_path( "functions/widget-social.php" ) );

// Add Category Posts Widget.
include_once( get_theme_file_path( "functions/widget-catposts.php" ) );

// Add Category Posts Widget.
include_once( get_theme_file_path( "functions/widget-postslider.php" ) );

// Add Welcome message.
include_once( get_theme_file_path( "functions/welcome-message.php" ) );

// Template Functions.
include_once( get_theme_file_path( "functions/theme-actions.php" ) );

// Post/page editor meta boxes.
include_once( get_theme_file_path( "functions/metaboxes.php" ) );

// TGM Plugin Activation.
include_once( get_theme_file_path( "functions/plugin-activation.php" ) );

// AJAX Contact Form - `mts_contact_form()`.
include_once( get_theme_file_path( 'functions/contact-form.php' ) );

// Custom menu walker.
include_once( get_theme_file_path( 'functions/nav-menu.php' ) );

// Rank Math SEO.
include_once( get_theme_file_path( 'functions/rank-math-notice.php' ) );

/*-----------------------------------------------------------------------------------*/
/* RTL
/*-----------------------------------------------------------------------------------*/
if ( ! empty( $mts_options['mts_rtl'] ) ) {
	/**
	 * RTL language support
	 *
	 * @see mts_load_footer_scripts()
	 */
	function mts_rtl() {
		if ( is_admin() ) {
			return;
		}
		global $wp_locale, $wp_styles;
		$wp_locale->text_direction = 'rtl';
		if ( ! is_a( $wp_styles, 'WP_Styles' ) ) {
			$wp_styles = new WP_Styles();
			$wp_styles->text_direction = 'rtl';
		}
	}
	add_action( 'init', 'mts_rtl' );
}

/**
 * Replace `no-js` with `js` from the body's class name.
 */
function mts_nojs_js_class() {
	echo '<script type="text/javascript">document.documentElement.className = document.documentElement.className.replace( /\bno-js\b/,\'js\' );</script>';
}
add_action( 'wp_head', 'mts_nojs_js_class', 1 );

/**
 * Enqueue .js files.
 */
function mts_add_scripts() {
	$mts_options = get_option( MTS_THEME_NAME );

	wp_enqueue_script( 'jquery' );

	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	wp_register_script( 'customscript', get_template_directory_uri() . '/js/customscript.js', true );
	if ( ! empty( $mts_options['mts_show_primary_nav'] ) && ! empty( $mts_options['mts_show_secondary_nav'] ) ) {
		$nav_menu = 'both';
	} else {
		$nav_menu = 'none';
		if ( ! empty( $mts_options['mts_show_primary_nav'] ) ) {
			$nav_menu = 'primary';
		} elseif ( ! empty( $mts_options['mts_show_secondary_nav'] ) ) {
			$nav_menu = 'secondary';
		}
	}
	wp_localize_script(
		'customscript',
		'mts_customscript',
		array(
			'responsive' => ( empty( $mts_options['mts_responsive'] ) ? false : true ),
			'nav_menu'   => $nav_menu
		)
	);
	wp_enqueue_script( 'customscript' );

	// Slider
	wp_enqueue_script('owl-carousel', get_template_directory_uri() . '/js/owl.carousel.min.js', array(), null, true);
	wp_localize_script('owl-carousel', 'slideropts', array('rtl_support' => $mts_options['mts_rtl']));

	// Animated single post/page header
	if ( is_singular() ) {
		$header_animation = mts_get_post_header_effect();
		if ( 'parallax' == $header_animation ) {
			wp_enqueue_script( 'jquery-parallax', get_template_directory_uri() . '/js/parallax.js', array( 'jquery' ) );
		} else if ( 'zoomout' == $header_animation ) {
			wp_enqueue_script( 'jquery-zoomout', get_template_directory_uri() . '/js/zoomout.js', array( 'jquery' ) );
		}
	}

	// Lightbox.
	if ( ! empty( $mts_options['mts_lightbox'] ) || ( mts_is_wc_active() && is_product() ) ) {
		wp_enqueue_script( 'magnificPopup', get_template_directory_uri() . '/js/jquery.magnific-popup.min.js', array( 'jquery' ), false, true );
	}

	// Sticky Nav.
	if ( ! empty( $mts_options['mts_sticky_nav'] ) ) {
		wp_enqueue_script( 'StickyNav', get_template_directory_uri() . '/js/sticky.js', array( 'jquery' ), false, true );
	}

	// Ajax Load More and Search Results
	wp_register_script( 'mts_cookie', get_template_directory_uri() . '/js/jquery.cookie.js', true );
	wp_register_script( 'mts_ajax', get_template_directory_uri() . '/js/ajax.js', array( 'jquery' ), false, true );
	if ( ! empty( $mts_options['mts_pagenavigation_type'] ) && $mts_options['mts_pagenavigation_type'] >= 2 || ( ! is_singular() || is_page_template( 'page-blog.php' ) ) ) {
		wp_enqueue_script( 'mts_ajax' );

		wp_enqueue_script( 'historyjs', get_template_directory_uri() . '/js/history.js' );

		// Add parameters for the JS
		global $wp_query;
		$max = $wp_query->max_num_pages;
		$paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
		if ( $max == 0 ) {
            $my_query = new WP_Query(
                array(
                    'post_type'   => 'post',
                    'post_status' => 'publish',
					'paged'       => $paged,
					// sticky posts.
                    'ignore_sticky_posts'=> 1
                )
            );
            $max = $my_query->max_num_pages;
            wp_reset_postdata();
        }
        $autoload = ( $mts_options['mts_pagenavigation_type'] == 3 );
		wp_localize_script(
			'mts_ajax',
			'mts_ajax_loadposts',
			array(
				'startPage'     => $paged,
				'maxPages'      => $max,
				'nextLink'      => next_posts( $max, false ),
				'autoLoad'      => $autoload,
				'i18n_loadmore' => esc_html__( 'Load More Posts', 'dropshipping' ),
				'i18n_loading'  => esc_html__( 'Loading...', 'dropshipping' ),
				'i18n_nomore'   => esc_html__( 'No more posts.', 'dropshipping' )
			 )
		);
	}
	if ( ! empty( $mts_options['mts_ajax_search'] ) ) {
		wp_enqueue_script( 'mts_ajax' );
		wp_localize_script(
			'mts_ajax',
			'mts_ajax_search',
			array(
				'url'         => admin_url( 'admin-ajax.php' ),
				'ajax_search' => '1',
			 )
		);
	}
	if ( mts_is_wc_active() && isset( $mts_options['mts_wishlist'] ) && ! empty( $mts_options['mts_wishlist'] ) ) {
		wp_enqueue_script( 'mts_cookie' );
		wp_enqueue_script( 'mts_ajax' );
		wp_localize_script(
			'mts_ajax',
			'mts_ajax_wishlist',
			array(
				'url' => admin_url( 'admin-ajax.php' ),
			)
		);
	}
	if ( mts_is_wc_active() && is_home() ) {
        wp_enqueue_script('mts_ajax');
        wp_localize_script(
            'mts_ajax',
            'mts_ajax_tabs',
            array(
                //'mts_nonce' => wp_create_nonce( 'mts_nonce' ),
                'ajax_url' => admin_url( 'admin-ajax.php' ),
            )
        );
    }
    if ( mts_is_wc_active() ) {
        wp_enqueue_script( 'magnificPopup' );
        wp_enqueue_script('mts_ajax');
        wp_localize_script(
            'mts_ajax',
            'mts_ajax_popup',
            array(
                'loading_text' => esc_html__( 'Loading...', 'dropshipping' ),
                'ajax_url'     => admin_url( 'admin-ajax.php' ),
            )
        );
    }
}
add_action( 'wp_enqueue_scripts', 'mts_add_scripts' );

/**
 * Load CSS files.
 */
function mts_enqueue_css() {
	$mts_options = get_option( MTS_THEME_NAME );

	wp_enqueue_style( 'dropshipping-stylesheet', get_stylesheet_uri() );

	// Slider
	wp_register_style('owl-carousel', get_template_directory_uri() . '/css/owl.carousel.css', array(), null);
	wp_enqueue_style('owl-carousel');

	$handle = 'dropshipping-stylesheet';

	// RTL
	if ( ! empty( $mts_options['mts_rtl'] ) ) {
		wp_enqueue_style( 'mts_rtl', get_template_directory_uri() . '/css/rtl.css', array( $handle ) );
	}

	// Responsive
	if ( ! empty( $mts_options['mts_responsive'] ) ) {
		wp_enqueue_style( 'responsive', get_template_directory_uri() . '/css/responsive.css', array( $handle ) );
	}

	// WooCommerce
	if ( mts_is_wc_active() ) {
		if ( empty( $mts_options['mts_optimize_wc'] ) || ( ! empty( $mts_options['mts_optimize_wc'] ) && ( is_woocommerce() || is_cart() || is_checkout() || is_account_page() || is_home() || mts_is_wishlist_page() ) )) {
			wp_enqueue_style( 'woocommerce', get_template_directory_uri() . '/css/woocommerce2.css' );
			$handle = 'woocommerce';
		}
	}

	// Lightbox
	if ( ! empty( $mts_options['mts_lightbox'] ) ) {
		wp_enqueue_style( 'magnificPopup', get_template_directory_uri() . '/css/magnific-popup.css' );
	}

	// Font Awesome
	wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/css/font-awesome.min.css' );

	$mts_sclayout = '';
	$mts_author = '';
	$mts_top_header1 = '';
	$mts_header_section = '';
	$mts_header_section2 = '';
	$mts_header_section3 = '';
	$mts_bottom_header_section1 = '';
	$mts_bottom_header_section2 = '';
	$mts_sidebar_location = '';
	$mts_tags    = '';
	$mts_cta_btn = '';

	if ( is_page() || is_single() ) {
		$mts_sidebar_location = get_post_meta( get_the_ID(), '_mts_sidebar_location', true );
	}
	if ( $mts_sidebar_location != 'right' && ( $mts_options['mts_layout'] == 'sclayout' || $mts_sidebar_location == 'left' )) {
		$mts_sclayout = '.article { float: right }
		.sidebar.c-4-12 { float: left }';
	}
	if ( empty( $mts_options['mts_top_description'] ) ) {
		$mts_top_header1 = '.header-social { float: left }';
	}
	if ( empty( $mts_options['mts_header_section2'] ) ) {
		$mts_header_section = '.logo-wrap { display: none }';
	}
	if ( empty( $mts_options['mts_header_section2'] ) && empty( $mts_options['mts_header_search'] ) && empty( $mts_options['mts_login_register'] ) && empty( $mts_options['mts_header_wishlist'] ) && empty( $mts_options['mts_header_cart'] ) ) {
		$mts_header_section2 = '#header { min-height: 0 }';
	}
	if ( empty( $mts_options['mts_header_search'] ) ) {
		$mts_header_section3 = '@media screen and (max-width: 1024px) { .header-carts { float: right; clear: none; padding-top: 0; } } @media screen and (max-width: 720px) { #header { min-height: 90px; } .header-carts { float: none; clear: both; padding-top: 20px; } }';
	}
	if ( empty( $mts_options['mts_show_secondary_nav'] ) && ( empty( $mts_options['mts_header_buttons_section'] ) || empty( $mts_options['mts_header_buttons'] ) ) && ( empty($mts_options['mts_nav_title']) || empty($mts_options['mts_nav_text']) ) ) {
		$mts_bottom_header_section2 = '#secondary-nav-container { border: 0 }';
	}
	if ( ! empty( $mts_options['mts_author_comment'] ) ) {
		$mts_author = '.bypostauthor .fn:after { content: "' . esc_html__( 'Author', 'dropshipping' ).'"; font-size: 12px; padding: 0 10px; margin-left: 5px; line-height: 20px; display: inline-block; color: #fff; font-weight: bold; text-transform: uppercase; background: #ef7d5f; }';
	}
	$tags = get_the_tags();
	if ( empty( $tags ) || is_wp_error( $tags ) || empty( $mts_options['mts_author_comment'] ) ) {
		$mts_tags = '.shareit { float: left }';
	}
	// Cta Buttons.
	if ( ! empty( $mts_options['mts_call_to_action_buttons'] ) && is_array( $mts_options['mts_call_to_action_buttons'] ) ) {
		$buttons = $mts_options['mts_call_to_action_buttons'];
		$i       = 0;
		foreach ( $buttons as $button ) {
			++$i;
			$button_bg    = $button['mts_call_to_action_button_bg'];
			$button_color = $button['mts_call_to_action_button_color'];
			// button border color.
			$button_border_color = $button['mts_call_to_action_button_border'];
			$mts_cta_btn .= '.mts-call-to-action-button.button-' . $i . ' a.button { background: '. $button_bg .'; color: '. $button_color .'; border-color: '. $button_border_color .'; }';
		}
	}
	// Custom CSS.
	$mts_bg = mts_get_background_styles( 'mts_background' );
	//Header Background
	$mts_top_header_background    = mts_get_background_styles( 'mts_top_header_background' );
	$mts_header_background        = mts_get_background_styles( 'mts_header_background' );
	$mts_bottom_header_background = mts_get_background_styles( 'mts_bottom_header_background' );
	$mts_bottom_header_color      = '#'.mts_darken_color($mts_options['mts_bottom_header_background']['color'],2);
	//Homepage Background
	$mts_featured_cat_background   = mts_get_background_styles( 'mts_featured_cat_background' );
	$mts_featured_tabs_background  = mts_get_background_styles( 'mts_featured_tabs_background' );
	$mts_product_slider_background = mts_get_background_styles( 'mts_product_slider_background' );
	$mts_call_to_action_bg         = mts_get_background_styles( 'mts_call_to_action_bg' );
	$mts_newsletter_box_bg         = mts_get_background_styles( 'mts_newsletter_box_bg' );
	$mts_home_blog_background      = mts_get_background_styles( 'mts_home_blog_background' );
	$mts_brands_carousel_bg        = mts_get_background_styles( 'mts_brands_carousel_bg' );
	$mts_footer_carousel_bg        = mts_get_background_styles( 'mts_footer_carousel_bg' );
	$mts_footer_background         = mts_get_background_styles( 'mts_footer_background' );
	//Title Background
	$mts_blog_title_background        = mts_get_background_styles( 'mts_blog_title_background' );
	$mts_shop_title_background        = mts_get_background_styles( 'mts_shop_title_background' );
	$mts_shop_single_title_background = mts_get_background_styles( 'mts_shop_single_title_background' );
	// dark color.
	$dark_color = '#'.mts_darken_color($mts_options['mts_color_scheme'],4);
	$custom_css = "
		body {{$mts_bg}}
		.top-header, .top-header .navigation .sub-menu {{$mts_top_header_background}}
		#header {{$mts_header_background}}
		#secondary-nav-container, .navigation.mobile-menu-wrapper, #secondary-navigation .sub-menu, #primary-navigation {{$mts_bottom_header_background}}
		#primary-navigation .navigation ul li:hover > a {background: {$mts_bottom_header_color}}

		.featured-categories-products {{$mts_featured_cat_background}}
		.featured-product-tabs {{$mts_featured_tabs_background}}
		.product-slider-container {{$mts_product_slider_background}}
		.call-to-action {{$mts_call_to_action_bg}}
		.mts-dropshipping-newsletter {{$mts_newsletter_box_bg}}
		.homepage-blog-section {{$mts_home_blog_background}}
		.brands-carousel-container {{$mts_brands_carousel_bg}}
		.footer-carousel-section {{$mts_footer_carousel_bg}}
		#site-footer {{$mts_footer_background}}
		.blog-background {{$mts_blog_title_background}}
		.shop-background {{$mts_shop_title_background}}
		.shop-single-background {{$mts_shop_single_title_background}}

		a:hover, .woocommerce ul.products li.product .price, .woocommerce .upsells .product-data .price, .woocommerce .related-products .product-data .price, .cross-sells .product-data .price, .woocommerce a.button.mts-add-to-wishlist.added, .woocommerce-page a.button.mts-add-to-wishlist.added, #primary-navigation .current-menu-item a, #secondary-navigation .current-menu-item a, .readMore a, .mts-header-button-wrap .mts-cart-content .amount, .mts-header-button-wrap .mts-cart-content .mts-cart-amount .amount, .woocommerce div.product p.price, .woocommerce div.product span.price, .woocommerce div.product p.price ins, .woocommerce div.product span.price ins, .latestPost .title a:hover, #secondary-navigation a:hover, #primary-navigation .sub-menu a:hover, .reply a, .single-prev-next a:hover .title, .single-prev-next a:hover i, td.product-subtotal, .order-total strong, .woocommerce-error a, .woocommerce-info a, .woocommerce-message a, #site-header .header-button a:hover, .mts-product-popup .product-title a:hover, .woocommerce-form-login p.lost_password a, .product_meta > div a:hover { color: {$mts_options['mts_color_scheme']}; }

		.pace .pace-progress,
		#mobile-menu-wrapper ul li a:hover,
		.ball-pulse > div,
		.mts-nav-title,
		.woocommerce a.button.add_to_cart_button,
		.woocommerce-page a.button.add_to_cart_button,
		.woocommerce a.button.ajax_add_to_cart,
		.woocommerce-page a.button.ajax_add_to_cart,
		.woocommerce div.product form.cart button.single_add_to_cart_button[type='submit'],
		.woocommerce-page div.product form.cart button.single_add_to_cart_button[type='submit'],
		.woocommerce span.onsale,
		.woocommerce-page span.onsale,
		.mts-dropshipping-newsletter .widget .wp-subscribe input.submit,
		.latestPost .thecat-inner,
		.single_post .thecat-inner,
		.mts-wishlist-link-count.count,
		.mts-header-cart-button .count,
		.latestPost-review-wrapper,
		#wpmm-megamenu .review-total-only,
		html .review-type-circle.latestPost-review-wrapper,
		.widget .review-total-only.large-thumb,
		.page-numbers.current,
		.single .pagination > span.current,
		.widget .wp_review_tab_widget_content .tab_title.selected a,
		.widget .wpt_widget_content .tab_title.selected a,
		.widget .wpt_widget_content #tags-tab-content ul li a,
		body .bypostauthor .fn:after,
		input[type='submit'],
		.woocommerce-form-login button[type='submit'],
		.woocommerce div.product .woocommerce-tabs ul.tabs li a:after,
		.woocommerce button.button,
		.woocommerce-page button.button,
		.woocommerce input.button,
		.woocommerce-page input.button,
		.woocommerce #respond input#submit,
		.woocommerce-page #respond input#submit,
		.woocommerce #content input.button,
		.woocommerce-page #content input.button,
		#header a.button.mts-cart-button.mts-checkout-button,
		.related-products h4:after,
		.upsells h4:after,
		.cross-sells h4:after,
		.mts-category-nav .category-name:after,
		.mts-product-popup.woocommerce #content div.product div.images .mts-view-details,
		.tagcloud a,
		.featured-product-tabs li.tab a:after,
		.tags a:hover:after,
		.woocommerce span.onsale,
		.woocommerce-page span.onsale,
		.onsale-badge,
		#add_payment_method .wc-proceed-to-checkout a.checkout-button,
		.woocommerce-cart .wc-proceed-to-checkout a.checkout-button,
		.woocommerce-checkout .wc-proceed-to-checkout a.checkout-button,
		.woocommerce #respond input#submit.alt,
		.woocommerce a.button.alt,
		.woocommerce button.button.alt,
		.woocommerce input.button.alt,
		.woocommerce a.button,
		.woocommerce-page a.button,
		.woocommerce button.button,
		.woocommerce-page button.button,
		.woocommerce input.button,
		.woocommerce-page input.button,
		.woocommerce #respond input#submit,
		.woocommerce-page #respond input#submit,
		.woocommerce #content input.button,
		.woocommerce-page #content input.button,
		.widget .wp-subscribe,
		.pagination .nav-previous a,
		.pagination .nav-next a,
		#load-posts a,
		.woocommerce nav.woocommerce-pagination ul li span.current,
		.woocommerce-page nav.woocommerce-pagination ul li span.current,
		.woocommerce #content nav.woocommerce-pagination ul li span.current,
		.woocommerce-page #content nav.woocommerce-pagination ul li span.current,
		.woocommerce .added_to_cart.wc-forward,
		.woocommerce-page .added_to_cart.wc-forward,
		.woocommerce .button.wc-forward,
		.woocommerce-page .button.wc-forward,
		form.wp-review-comment-form input#submit,
		.woocommerce-product-search button[type='submit'],
		.woocommerce .woocommerce-widget-layered-nav-dropdown__submit,
		.product-buttons .button.product_type_simple,
		.product-buttons .button.product_type_grouped,
		.product-buttons .button.product_type_external {
			background: {$mts_options['mts_color_scheme']};
		}

		.tags a:hover, .mts-footer-carousel-link { border-color: {$mts_options['mts_color_scheme']}; }

		.header-login-register, .mts-wishlist a, .mts-header-cart-button { color: {$mts_options['mts_header_links']}; }

		#copyright-note a { color: {$mts_options['mts_copyright_link_color']}; }

		.woocommerce button.button:hover, .woocommerce-page button.button:hover, .woocommerce input.button:hover, .woocommerce-page input.button:hover, .woocommerce #respond input#submit:hover, .woocommerce-page #respond input#submit:hover, .woocommerce #content input.button:hover, .woocommerce-page #content input.button:hover, #header a.button.mts-cart-button.mts-checkout-button:hover, .woocommerce div.product form.cart button.single_add_to_cart_button[type='submit']:hover, .woocommerce-page div.product form.cart button.single_add_to_cart_button[type='submit']:hover, .mts-product-popup.woocommerce #content div.product div.images .mts-view-details:hover, .woocommerce a.button.add_to_cart_button:hover, .woocommerce-page a.button.add_to_cart_button:hover, .woocommerce a.button.ajax_add_to_cart:hover, .woocommerce-page a.button.ajax_add_to_cart:hover, .woocommerce div.product form.cart button.single_add_to_cart_button[type='submit']:hover, .woocommerce-page div.product form.cart button.single_add_to_cart_button[type='submit']:hover, input[type='submit']:hover, .woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover, .mts-checkout-item.active a:after, input[type='submit']:hover, .mts-dropshipping-newsletter .widget .wp-subscribe input.submit:hover, .tagcloud a:hover, .widget .wp-subscribe input.submit, .widget .wpt_widget_content #tags-tab-content ul li a:hover, .widget_shopping_cart .buttons .btn-cart:hover, .widget_shopping_cart .buttons .btn-cart:focus, .widget_price_filter .price_slider_amount .button:hover, .widget_price_filter .price_slider_amount .button:focus, .pagination .nav-previous a:hover, .pagination .nav-next a:hover, #load-posts a:hover, .woocommerce .added_to_cart.wc-forward:hover, .woocommerce-page .added_to_cart.wc-forward:hover, .woocommerce .button.wc-forward:hover, .woocommerce-page .button.wc-forward:hover, .woocommerce a.button:hover, .woocommerce-page a.button:hover, .woocommerce button.button:hover, .woocommerce-page button.button:hover, .woocommerce input.button:hover, .woocommerce-page input.button:hover, .woocommerce #respond input#submit:hover, .woocommerce-page #respond input#submit:hover, .woocommerce #content input.button:hover, .woocommerce-page #content input.button:hover, form.wp-review-comment-form input#submit:hover, .widget_product_search button[type='submit']:hover, .woocommerce .woocommerce-widget-layered-nav-dropdown__submit:hover { background-color: {$dark_color} }


		{$mts_sclayout}
		{$mts_author}
		{$mts_top_header1}
		{$mts_header_section}
		{$mts_header_section2}
		{$mts_header_section3}
		{$mts_bottom_header_section1}
		{$mts_bottom_header_section2}
		{$mts_tags}
		{$mts_cta_btn}
		{$mts_options['mts_custom_css']}
			";
	wp_add_inline_style( $handle, $custom_css );
}
add_action( 'wp_enqueue_scripts', 'mts_enqueue_css', 99 );

/**
 * Wrap videos in .responsive-video div
 *
 * @param $html
 * @param $url
 * @param $attr
 *
 * @return string
 */
function mts_responsive_video( $html, $url, $attr ) {

	// Only video embeds
	$video_providers = array(
		'youtube',
		'vimeo',
		'dailymotion',
		'wordpress.tv',
		'vine.co',
		'animoto',
		'blip.tv',
		'collegehumor.com',
		'funnyordie.com',
		'hulu.com',
		'revision3.com',
		'ted.com',
	);

	// Allow user to wrap other embeds
	$providers = apply_filters('mts_responsive_video', $video_providers );

	foreach ( $providers as $provider ) {
		if ( strstr($url, $provider) ) {
			$html = '<div class="flex-video flex-video-' . sanitize_html_class( $provider ) . '">' . $html . '</div>';
			break;// Break if video found
		}
	}

	return $html;
}
add_filter( 'embed_oembed_html', 'mts_responsive_video', 99, 3 );

if ( ! function_exists( 'mts_comments' ) ) {
	/**
	 * Custom comments template.
	 * @param $comment
	 * @param $args
	 * @param $depth
	 */
	function mts_comments( $comment, $args, $depth ) {
		$GLOBALS['comment'] = $comment;
		$mts_options = get_option( MTS_THEME_NAME ); ?>
		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
			<?php
			switch( $comment->comment_type ) :
				case 'pingback':
				case 'trackback': ?>
					<div id="comment-<?php comment_ID(); ?>" class="comment-list">
						<div class="comment-author vcard">
							<?php esc_html_e( 'Pingback:', 'dropshipping' ); ?> <?php comment_author_link(); ?>
							<?php echo '<span class="says">' . esc_html__( 'says:', 'dropshipping' ) . '</span>'; ?>
							<span class="comment-meta">
								<?php edit_comment_link( esc_html__( '( Edit )', 'dropshipping' ), '  ', '' ); ?>
							</span>
						</div>
						<?php if ( ! empty( $mts_options['mts_comment_date'] ) ) { ?>
							<div class="ago"><?php comment_date( get_option( 'date_format' ) ); ?><?php _e(' at ','dropshipping'); ?><?php comment_time( get_option( 'time_format' ) ); ?></div>
						<?php } ?>
						<?php if ( $comment->comment_approved == '0' ) : ?>
							<em><?php esc_html_e( 'Your comment is awaiting moderation.', 'dropshipping' ) ?></em>
							<br />
						<?php endif; ?>
					</div>
				<?php
					break;

				default: ?>
					<div id="comment-<?php comment_ID(); ?>" class="comment-list" itemscope itemtype="http://schema.org/UserComments">
						<?php echo get_avatar( $comment->comment_author_email, 74 ); ?>
						<div class="comment-author vcard">
							<?php printf( '<span class="fn" itemprop="creator" itemscope itemtype="http://schema.org/Person"><span itemprop="name">%s</span></span>', get_comment_author_link() ); ?>
							<?php echo '<span class="says">' . esc_html__( 'says:', 'dropshipping' ) . '</span>'; ?>
							<span class="comment-meta">
								<?php edit_comment_link( esc_html__( '( Edit )', 'dropshipping' ), '  ', '' ); ?>
							</span>
						</div>
						<?php if ( ! empty( $mts_options['mts_comment_date'] ) ) { ?>
							<div class="ago"><?php comment_date( get_option( 'date_format' ) ); ?><?php _e( ' at ','dropshipping' ); ?><?php comment_time( get_option( 'time_format' ) ); ?></div>
						<?php } ?>
						<?php if ( $comment->comment_approved == '0' ) : ?>
							<em><?php esc_html_e( 'Your comment is awaiting moderation.', 'dropshipping' ); ?></em>
							<br />
						<?php endif; ?>
						<div class="commenttext" itemprop="commentText">
							<?php comment_text(); ?>
							<div class="reply">
								<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
							</div>
						</div>
					</div>
				<?php
				   break;
			 endswitch; ?>
		<!-- WP adds </li> -->
	<?php }
}

/**
 * Increase excerpt length to 100.
 *
 * @param $length
 *
 * @return int
 */
function mts_excerpt_length( $length ) {
	return 100;
}
add_filter( 'excerpt_length', 'mts_excerpt_length', 20 );

/**
 * Remove [...] and shortcodes
 *
 * @param $output
 *
 * @return string
 */
function mts_custom_excerpt( $output ) {
  return preg_replace( '/\[[^\]]*]/', '', $output );
}
add_filter( 'get_the_excerpt', 'mts_custom_excerpt' );

/**
 * Truncate string to x letters/words.
 *
 * @param $str
 * @param int $length
 * @param string $units
 * @param string $ellipsis
 *
 * @return string
 */
function mts_truncate( $str, $length = 40, $units = 'letters', $ellipsis = '&nbsp;&hellip;' ) {
	if ( $units == 'letters' ) {
		if ( mb_strlen( $str ) > $length ) {
			return mb_substr( $str, 0, $length ) . $ellipsis;
		} else {
			return $str;
		}
	} else {
		return wp_trim_words( $str, $length, $ellipsis );
	}
}

if ( ! function_exists( 'mts_excerpt' ) ) {
	/**
	 * Get HTML-escaped excerpt up to the specified length.
	 *
	 * @param int $limit
	 *
	 * @return string
	 */
	function mts_excerpt( $limit = 40 ) {
	  return esc_html( mts_truncate( get_the_excerpt(), $limit, 'words' ) );
	}
}

/**
 * Change the "read more..." link to "".
 * @param $more_link
 * @param $more_link_text
 *
 * @return string
 */
function mts_remove_more_link( $more_link, $more_link_text ) {
	return '';
}
add_filter( 'the_content_more_link', 'mts_remove_more_link', 10, 2 );

if ( ! function_exists( 'mts_post_has_moretag' ) ) {
	/**
	 * Shorthand function to check for more tag in post.
	 *
	 * @return bool|int
	 */
	function mts_post_has_moretag() {
		$post = get_post();
		return preg_match( '/<!--more(.*?)?-->/', $post->post_content );
	}
}

if ( ! function_exists( 'mts_readmore' ) ) {
	/**
	 * Display a "read more" link.
	 */
	function mts_readmore() {
		?>
		<div class="readMore">
			<a href="<?php echo esc_url( get_the_permalink() ); ?>" title="<?php echo esc_html( get_the_title() ); ?>">
				<?php esc_html_e( 'Continue Reading', 'dropshipping' ); ?>
			</a>
		</div>
		<?php
	}
}

/**
 * Exclude trackbacks from the comment count.
 *
 * @param $count
 *
 * @return int
 */
function mts_comment_count( $count ) {
	if ( ! is_admin() ) {
		global $id;
		$comments = get_comments( 'status=approve&post_id=' . $id );
		$comments_by_type = separate_comments( $comments );
		return count( $comments_by_type['comment'] );
	} else {
		return $count;
	}
}
add_filter( 'get_comments_number', 'mts_comment_count', 0 );

/**
 * Add `has_thumb` to the post's class name if it has a thumbnail.
 *
 * @param $classes
 *
 * @return array
 */
function has_thumb_class( $classes ) {
	if( has_post_thumbnail( get_the_ID() ) ) { $classes[] = 'has_thumb'; }
		return $classes;
}
add_filter( 'post_class', 'has_thumb_class' );

/*-----------------------------------------------------------------------------------*/
/* Add the title tag for compability with older WP versions.
/*-----------------------------------------------------------------------------------*/
if ( ! function_exists( '_wp_render_title_tag' ) ) {
	function theme_slug_render_title() { ?>
	   <title><?php wp_title( '|', true, 'right' ); ?></title>
	<?php }
	add_action( 'wp_head', 'theme_slug_render_title' );
}

/**
 * Handle AJAX search queries.
 */
function ajax_mts_search() {
	$query = $_REQUEST['q']; // It goes through esc_sql() in WP_Query
	$search_query = new WP_Query( array( 's' => $query, 'posts_per_page' => 3, 'post_status' => 'publish' ));
	$search_count = new WP_Query( array( 's' => $query, 'posts_per_page' => -1, 'post_status' => 'publish' ));
	$search_count = $search_count->post_count;
	if ( ! empty( $query ) && $search_query->have_posts() ) :
		//echo '<h5>Results for: '. $query.'</h5>';
		echo '<ul class="ajax-search-results">';
		while ( $search_query->have_posts() ) : $search_query->the_post();
			?><li>
				<a href="<?php echo esc_url( get_the_permalink() ); ?>">
					<?php if ( has_post_thumbnail() ) {
						$attr = [
							'title' => esc_attr( get_the_title() ),
							'alt'   => esc_attr( get_the_title() ),
						];
						the_post_thumbnail( 'dropshipping-widgetthumb', $attr );
					} else { ?>
						<img class="wp-post-image" src="<?php echo get_template_directory_uri() . '/images/nothumb-dropshipping-widgetthumb.png'; ?>" alt="<?php echo esc_html( get_the_title() ); ?>"/>
					<?php } ?>
					<?php the_title(); ?>
				</a>
				<div class="meta">
					<span class="thetime"><?php the_time( 'F j, Y' ); ?></span>
				</div> <!-- / .meta -->
			</li>
			<?php
		endwhile;
		echo '</ul>';
		echo '<div class="ajax-search-meta"><span class="results-count">'.$search_count.' '.__( 'Results', 'dropshipping' ).'</span><a href="'.esc_url( get_search_link( $query ) ).'" class="results-link">'.__('Show all results.', 'dropshipping' ).'</a></div>';
	else:
		echo '<div class="no-results">'.__( 'No results found.', 'dropshipping' ).'</div>';
	endif;
	wp_reset_postdata();
	exit; // required for AJAX in WP
}
if( ! empty( $mts_options['mts_ajax_search'] )) {
	add_action( 'wp_ajax_mts_search', 'ajax_mts_search' );
	add_action( 'wp_ajax_nopriv_mts_search', 'ajax_mts_search' );
}

/**
 *  Filters that allow shortcodes in Text Widgets
 */
add_filter( 'widget_text', 'shortcode_unautop' );
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'the_content_rss', 'do_shortcode' );

if ( trim( $mts_options['mts_feedburner'] ) !== '' ) {
	/**
	 * Redirect feed to FeedBurner if a FeedBurner URL has been set.
	 */
	function mts_rss_feed_redirect() {
		$mts_options = get_option( MTS_THEME_NAME );
		global $feed;
		$new_feed = $mts_options['mts_feedburner'];
		if ( !is_feed() ) {
				return;
		}
		if ( preg_match( '/feedburner/i', $_SERVER['HTTP_USER_AGENT'] )){
				return;
		}
		if ( $feed != 'comments-rss2' ) {
				if ( function_exists( 'status_header' )) status_header( 302 );
				header( "Location:" . $new_feed );
				header( "HTTP/1.1 302 Temporary Redirect" );
				exit();
		}
	}
	add_action( 'template_redirect', 'mts_rss_feed_redirect' );
}

/**
 * Single Post Pagination - Numbers + Previous/Next.
 *
 * @param $args
 *
 * @return mixed
 */
function mts_wp_link_pages_args( $args ) {
	global $page, $numpages, $more, $pagenow;
	if ( $args['next_or_number'] != 'next_and_number' ) {
		return $args;
	}

	$args['next_or_number'] = 'number';

	if ( !$more ) {
		return $args;
	}

	if( $page-1 ) {
		$args['before'] .= _wp_link_page( $page-1 )
						. $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>';
	}

	if ( $page<$numpages ) {
		$args['after'] = _wp_link_page( $page+1 )
						 . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
						 . $args['after'];
	}

	return $args;
}
add_filter( 'wp_link_pages_args', 'mts_wp_link_pages_args' );

/**
 * Remove hentry class from pages
 *
 * @param $classes
 *
 * @return array
 */
function mts_remove_hentry( $classes ) {
	if ( is_page() ) {
		$classes = array_diff( $classes, array( 'hentry' ) );
	}
	return $classes;
}
add_filter( 'post_class','mts_remove_hentry' );

/*-----------------------------------------------------------------------------------*/
/* WooCommerce
/*-----------------------------------------------------------------------------------*/
if ( mts_is_wc_active() ) {
	if ( !function_exists( 'mts_loop_columns' )) {
		/**
		 * Change number or products per row to 3
		 *
		 * @return int
		 */
		function mts_loop_columns() {
			return 3; // 3 products per row
		}
	}
	add_filter( 'loop_shop_columns', 'mts_loop_columns' );

	/**
	 * Redefine woocommerce_output_related_products()
	 */
    function woocommerce_output_related_products() {
		$mts_options = get_option( MTS_THEME_NAME );
		// Related product Number.
		$mts_no_related_products = ! empty( $mts_options['mts_related_products_num'] ) ? $mts_options['mts_related_products_num'] : '8';
        $args = array(
            'posts_per_page' => $mts_no_related_products,
            'columns'        => 1,
        );
        woocommerce_related_products( $args ); // Display all products in carousel
    }

	global $pagenow;
	if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
		/**
		 * Define WooCommerce image sizes.
		 */
		function mts_woocommerce_image_dimensions() {
			$catalog = array(
				'width'  => '278',	// px
				'height' => '316',	// px
				'crop'	 => 1 		// true
			);
			$single = array(
				'width'  => '432',	// px
				'height' => '494',	// px
				'crop'	 => 1 		// true
			);
			$thumbnail = array(
				'width'  => '124',	// px
				'height' => '144',	// px
				'crop'	 => 1 		// false
			);
			// Image sizes
			update_option( 'shop_catalog_image_size', $catalog ); 		// Product category thumbs
			update_option( 'shop_single_image_size', $single ); 		// Single product image
			update_option( 'shop_thumbnail_image_size', $thumbnail ); 	// Image gallery thumbs
		}
		add_action( 'init', 'mts_woocommerce_image_dimensions', 1 );
	}


	/**
	 * Change the number of product thumbnails to show per row to 4.
	 *
	 * @return int
	 */
	function mts_thumb_cols() {
		return 4; // .last class applied to every 4th thumbnail
	}
	add_filter( 'woocommerce_product_thumbnails_columns', 'mts_thumb_cols' );

	/**
	 * Change the number of WooCommerce products to show per page.
	 *
	 * @return mixed
	 */
	function mts_products_per_page() {
		$mts_options = get_option( MTS_THEME_NAME );
		return $mts_options['mts_shop_products'];
	}
	add_filter( 'loop_shop_per_page', 'mts_products_per_page', 20 );

	// Change add to cart text on single products
    // add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text', 10, 2 );
    function woo_custom_cart_button_text($text, $product) {
    	_deprecated_function( __FUNCTION__, '1.0.7' );
        if ( ! is_single() ) return $text;
        return $product->is_type( 'external' ) ? esc_html__( 'Buy Now', 'dropshipping' ) : esc_html__( 'Add to Cart', 'dropshipping' );
    }

    // Change add to cart text on archive products
    // add_filter( 'woocommerce_product_add_to_cart_text', 'mts_archive_add_to_cart_text' );
	function mts_archive_add_to_cart_text() {
		_deprecated_function( __FUNCTION__, '1.0.7' );
		return esc_html__( 'Add to cart', 'woocommerce' );
	}

	/**
	 * Optimize WooCommerce Scripts
	 * Updated for WooCommerce 2.0+
	 * Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
	 */
	function mts_child_manage_woocommerce_styles() {
		//remove generator meta tag
		remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );

		//first check that woo exists to prevent fatal errors
		if ( function_exists( 'is_woocommerce' ) ) {
			//dequeue scripts and styles
			if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() && ! is_account_page() && ! is_home() && !mts_is_wishlist_page() ) {
				wp_dequeue_style( 'woocommerce-layout' );
				wp_dequeue_style( 'woocommerce-smallscreen' );
				wp_dequeue_style( 'woocommerce-general' );
				wp_dequeue_style( 'wc-bto-styles' ); //Composites Styles
				wp_dequeue_script( 'wc-add-to-cart' );
				wp_dequeue_script( 'wc-cart-fragments' );
				wp_dequeue_script( 'woocommerce' );
				wp_dequeue_script( 'jquery-blockui' );
				wp_dequeue_script( 'jquery-placeholder' );
			}
		}
	}
	if ( ! empty( $mts_options['mts_optimize_wc'] ) ) {
		add_action( 'wp_enqueue_scripts', 'mts_child_manage_woocommerce_styles', 99 );
	}

	// Remove WooCommerce generator tag.
	remove_action('wp_head', 'wc_generator_tag');

	// Add extra classes to body
	add_filter( 'body_class', 'mts_body_classes' );
	function mts_body_classes( $classes ) {
		$mts_options = get_option( MTS_THEME_NAME );
		if ( ! isset( $mts_options['mts_wishlist'] ) || empty( $mts_options['mts_wishlist'] ) ) {
			$classes[] = 'wishlist-disabled';
		 }	return $classes;
	}
	// Remove link, rating and default button in products loop
    remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );

    //Remove breadcrumb from single product
    add_action('template_redirect', 'remove_shop_breadcrumbs' );
	function remove_shop_breadcrumbs() {
		if (is_single()) {
			remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
		}
	}

    /**
     * Show the subcategory title in the product loop.
     */
    function woocommerce_template_loop_category_title( $category ) {
        ?>
        <div class="product-category-info">
            <h3 class="product-category-title"><?php echo esc_html( $category->name ); ?></h3>
            <?php if ( $category->count > 0 ) echo apply_filters( 'woocommerce_subcategory_count_html', '<div class="product-number">' . $category->count . esc_html__( ' Products', 'dropshipping' ) . '</div>', $category ); ?>
        </div>
        <?php
    }
    // Remove product ordering form from default location in shop archives, it's called from "woocommerce/archive-product.php" instead
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

	/**
     * Single Product
     */
    // Move badges inside "images" div
    remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10 );
    add_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_sale_flash', 10 );

    // Replace default woocommerce_default_product_tabs function ( just to mark review count )
    function woocommerce_default_product_tabs( $tabs = array() ) {
        global $product, $post, $mts_options;
        // Description tab - shows product content
        if ( $post->post_content ) {
            $tabs['description'] = array(
                'title'    => esc_html__( 'Description', 'dropshipping' ),
                'priority' => 10,
                'callback' => 'woocommerce_product_description_tab'
            );
        }

       // Additional information tab - shows attributes
        if ( $product && ( $product->has_attributes() || apply_filters( 'wc_product_enable_dimensions_display', $product->has_weight() || $product->has_dimensions() ) ) ) {
            $tabs['additional_information'] = array(
                'title'    => esc_html__( 'Additional Information', 'dropshipping' ),
                'priority' => 20,
                'callback' => 'woocommerce_product_additional_information_tab'
            );
        }

        // Reviews tab - shows comments
        if ( comments_open() ) {
            $tabs['reviews'] = array(
                'title'    => sprintf( __( 'Reviews <span>(%d)</span>', 'dropshipping' ), $product->get_review_count() ),
                'priority' => 30,
                'callback' => 'comments_template'
            );
        }

        // About Brands - shows brands
        if ( ! empty($mts_options['mts_about_brand_content']) ) {
            $tabs['about_brand'] = array(
                'title'    => esc_html__( 'About Brand', 'dropshipping' ),
                'priority' => 40,
                'callback' => 'mts_about_brand_content'
           );
        }

        // Shipping & Delivery - shows shipping and delivery methods
        if ( ! empty($mts_options['mts_shipping_delivery_content']) ) {
            $tabs['shipping_delivery'] = array(
                'title'    => esc_html__( 'Shipping & Delivery', 'dropshipping' ),
                'priority' => 50,
                'callback' => 'mts_shipping_delivery_content'
        	);
        }
        return $tabs;
    }

    function mts_about_brand_content() {
    	global $mts_options;
		// About Brand Content content
		echo $mts_options['mts_about_brand_content'];
	}

	function mts_shipping_delivery_content() {
		global $mts_options;
		// About Brand Content content
		echo $mts_options['mts_shipping_delivery_content'];
	}

	// Reorder single product tabs
	add_filter( 'woocommerce_product_tabs', 'mts_woo_product_tabs', 98 );
	function mts_woo_product_tabs( $tabs ) {

		$mts_options = get_option( MTS_THEME_NAME );

		if ( ! isset( $mts_options['mts_single_product_tabs'] ) || !is_array( $mts_options['mts_single_product_tabs'] ) ) {
			return $tabs;
		}

		// Remove disab l esc_html_e first
		if ( array_key_exists( 'disabled', $mts_options['mts_single_product_tabs'] ) ) {
			foreach ( $mts_options['mts_single_product_tabs']['disabled'] as $tab => $title ) {
				if ( isset( $tabs[ $tab ] ) ) {
					unset( $tabs[ $tab ] );
				}
			}
		}

		// Resort enabled default tabs ( swap priority key of default tabs in case some plugin is depending on it )
		if ( array_key_exists( 'enabled', $mts_options['mts_single_product_tabs'] ) ) {

			$tabs_order = $mts_options['mts_single_product_tabs']['enabled'];

			if ( empty( $tabs_order ) ) return $tabs; // Just in case

			$default_tabs_priority = [];

			foreach ( $tabs_order as $key => $value ) {
				if ( isset( $tabs[ $key ] ) ) { // might be removed by some plugin
					$default_tabs_priority[ $tabs[ $key ]['priority'] ] = $key;
				}
			}

			$default_tabs_priority_1 = $default_tabs_priority;
			ksort( $default_tabs_priority );
			$new = array_combine( array_flip( $default_tabs_priority ), $default_tabs_priority_1 );

			foreach ( $new as $priority => $tab ) {
				if ( isset( $tabs[ $tab ] ) ) { // might be removed by some plugin
					$tabs[ $tab ]['priority'] = $priority;
				}
			}

			return $tabs;
		}

		return $tabs;
	}

    /**
     * Output placeholders for the single variation.
     */
    function woocommerce_single_variation() {
        echo '<div class="single_variation clear"></div>';
    }
    /**
     * Output the add to cart button for variations.
     */
    function woocommerce_single_variation_add_to_cart_button() {
        global $product;
        ?>
        <div class="woocommerce-variation-add-to-cart variations_button">
            <?php do_action( 'woocommerce_before_add_to_cart_quantity' );?>
            <?php woocommerce_quantity_input( array( 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) ); ?>
            <?php do_action( 'woocommerce_after_add_to_cart_quantity' ); ?>
            <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?>
            <button type="submit" class="single_add_to_cart_button button alt"><?php echo $product->single_add_to_cart_text(); ?></button>
            <?php do_action( 'woocommerce_after_add_to_cart_button' ); ?>
            <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
            <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
            <input type="hidden" name="variation_id" class="variation_id" value="" />
        </div>
        <?php
    }

	add_action( 'woocommerce_after_add_to_cart_button', 'mts_wc_single_product_wishlist' );
	function mts_wc_single_product_wishlist() {
		echo '<div class="single-wishlist-button">';
		echo mts_single_wishlist_button();
		echo '</div>';
	}

	add_action( 'woocommerce_product_meta_end', 'mts_wc_single_product_share' );
	function mts_wc_single_product_share() {
		echo mts_product_social_buttons();
	}

	function mts_get_wishlist_page_url() {
		$wishlist_page = get_page_by_title( 'Wishlist' );
		$wishlist_page_id = apply_filters( 'mts_wishlist_page_id', $wishlist_page->ID );
		return get_page_link( $wishlist_page_id );
	}

	function mts_is_wishlist_page() {
		$wishlist_page = get_page_by_title( 'Wishlist' );
		$wishlist_page_id = apply_filters( 'mts_wishlist_page_id', $wishlist_page->ID );
		return is_page( $wishlist_page_id );
	}

	function mts_product_in_wishlist( $id ) {
		$wishlist_items = ! empty( $_COOKIE['mts_wishlist'] ) ? explode(',', $_COOKIE['mts_wishlist']) : [];
		return in_array( $id, $wishlist_items );
	}

	add_action('wp_ajax_mts_wishlist_page_loop', 'mts_wishlist_page_loop');
	add_action('wp_ajax_nopriv_mts_wishlist_page_loop', 'mts_wishlist_page_loop');
	function mts_wishlist_page_loop() {
		global $mts_options;
		if ( ! isset( $mts_options['mts_wishlist'] ) || empty( $mts_options['mts_wishlist'] ) ) {
			echo '<p class="wishlist-disabled">' . esc_html_e( 'Wishlist feature is disabled', 'dropshipping' ).'</p>';
			return;
		}
		echo '<table class="shop_table cart mts-wishlist-table" cellspacing="0">';
			echo '<tbody>';
			echo '<thead>';
			echo '<tr>';
			echo '<th class="product-remove">&nbsp;</th>';
			echo '<th class="product-thumbnail">&nbsp;</th>';
			echo '<th class="product-name">' . esc_html__( 'Product Name', 'dropshipping' ).'</th>';
			echo '<th class="product-price">' . esc_html__( 'Unit Price', 'dropshipping' ).'</th>';
			echo '<th class="product-status">' . esc_html__( 'Stock Status', 'dropshipping' ).'</th>';
			echo '<th class="product-cart">&nbsp;</th>';
			echo '</tr>';
			echo '</thead>';
			$wishlist_items = ! empty( $_COOKIE['mts_wishlist'] ) ? explode(',', $_COOKIE['mts_wishlist']) : [];
			if ( ! empty( $wishlist_items ) ) {
				$args = array(
					'post_type'		      => 'product',
					'post_status'		  => 'publish',
					'ignore_sticky_posts' => 1,
					'posts_per_page'	  => -1,
					'post__in'			  => $wishlist_items
				);
				$wishlist_query = new WP_Query( apply_filters( 'mts_wishlist_query', $args ) );

				while ( $wishlist_query->have_posts() ) : $wishlist_query->the_post();
					global $product;
					$pr_id = get_the_ID(); ?>
					<tr class="mts-wishlist-table-row">
						<td class="product-remove">
							<a href="#" data-product-id="<?php echo $pr_id; ?>" class="mts-remove-from-wishlist remove" title="<?php _e( 'Remove this product', 'dropshipping' ) ?>">&times;</a>
						</td>
						<td class="product-thumbnail">
							<?php $thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $product->get_image() );
							if ( ! $product->is_visible() )
								echo $thumbnail;
							else
								printf( '<a href="%s">%s</a>', $product->get_permalink(), $thumbnail );
							?>
						</td>
						<td class="product-name">
							<a href="<?php echo esc_url( get_permalink( apply_filters( 'woocommerce_in_cart_product', $pr_id ) ) ) ?>"><?php echo apply_filters( 'woocommerce_in_cartproduct_obj_title', $product->get_title(), $product ) ?></a>
						</td>
						<td class="product-price" data-title="<?php _e('Unit Price:', 'dropshipping' ); ?>">
							<?php woocommerce_template_loop_price(); ?>
						</td>
						<td class="product-stock-status">
							<?php mts_stock_catalog(); ?>
						</td>
						<td class="product-add-to-cart">
							<?php woocommerce_template_loop_add_to_cart(); ?>
						</td>
					</tr>
				<?php
				endwhile; wp_reset_postdata();
			} else {
				echo '<tr><td colspan="6" class="mts-wishlist-empty">' . esc_html__( 'Your wishlist is empty', 'dropshipping' ).'</td></tr>';
			}
			echo '</tbody>';
		echo '</table>';
		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) die();
	}
	add_action('wp_ajax_mts_wishlist_count', 'mts_wishlist_count');
	add_action('wp_ajax_nopriv_mts_wishlist_count', 'mts_wishlist_count');
	function mts_wishlist_count() {
		$wishlist_items = ! empty( $_COOKIE['mts_wishlist'] ) ? explode(',', $_COOKIE['mts_wishlist']) : [];
		echo count( $wishlist_items );

		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) die();
	}

	//* Add stock status to archive pages
	function mts_stock_catalog() {
	    global $product;
	    if ( $product->is_in_stock() ) {
	        echo '<span class="stock" >' . esc_html__( ' In Stock', 'dropshipping' ) . '</span>';
	    } else {
	        echo '<span class="out-of-stock" >' . esc_html__( 'Out of Stock', 'dropshipping' ) . '</span>';
	    }
	}

    // Home tabs
    add_action('wp_ajax_mts_homepage_tabs', 'mts_ajax_homepage_tabs');
    add_action('wp_ajax_nopriv_mts_homepage_tabs', 'mts_ajax_homepage_tabs');
    function mts_ajax_homepage_tabs() {
        mts_homepage_tab( $_POST['home_tab'] );
        die();
    }
    if ( ! function_exists( 'mts_homepage_tab' ) ) {
        function mts_homepage_tab( $tab ) {

		$mts_options  = get_option( MTS_THEME_NAME );
    	$tab_num_post = $mts_options['mts_home_tabs_products'];
            if ( 'new_arrivals' === $tab ) {
                $new_arrivals_args = array( 'posts_per_page' => $tab_num_post, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' );
                // $new_arrivals_args['meta_query'] = WC()->query->get_meta_query();
                $new_arrivals_query = new WP_Query( apply_filters( 'dropshipping_homepage_tab_args', $new_arrivals_args, 'new_arrivals' ) );
                if ( $new_arrivals_query->have_posts() ) {
                    echo '<ul class="products woocommerce">';
                    while ( $new_arrivals_query->have_posts() ) {
                        $new_arrivals_query->the_post();
                        wc_get_template( 'content-product-featured-tab.php' );
                    }
                    echo '</ul>';
                }
                wp_reset_postdata();
            } else if ( 'top_rated' === $tab )  {
                add_filter( 'posts_clauses',  array( WC()->query, 'order_by_rating_post_clauses' ) );
                $top_rated_args = array('posts_per_page' => $tab_num_post, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product' );
                $top_rated_args['meta_query'] = WC()->query->get_meta_query();

                $top_rated_query = new WP_Query( apply_filters( 'dropshipping_homepage_tab_args', $top_rated_args, 'top_rated' ) );
                if ( $top_rated_query->have_posts() ) {
                    echo '<ul class="products woocommerce">';
                    while ( $top_rated_query->have_posts() ) {
                        $top_rated_query->the_post();
                        wc_get_template( 'content-product-featured-tab.php' );
                    }
                    echo '</ul>';
                }
                wp_reset_postdata();
            } else if ( 'best_sellers' === $tab )  {
                $best_sellers_args = array( 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num','posts_per_page' => $tab_num_post, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product');
                $best_sellers_args['meta_query'] = WC()->query->get_meta_query();
                $best_sellers_query = new WP_Query( apply_filters( 'dropshipping_homepage_tab_args', $best_sellers_args, 'best_sellers' ) );

                if ( $best_sellers_query->have_posts() ) {

                    echo '<ul class="products woocommerce">';

                    while ( $best_sellers_query->have_posts() ) {
                        $best_sellers_query->the_post();
                        wc_get_template( 'content-product-featured-tab.php' );
                    }

                    echo '</ul>';
                }

                wp_reset_postdata();
            }
        }
    }

    // Reorder Homepage product tabs
	//add_filter( 'wp_ajax_mts_homepage_tabs', 'mts_home_product_tabs', 98 );
	//add_action('wp_ajax_nopriv_mts_homepage_tabs', 'mts_ajax_homepage_tabs');
	function mts_home_product_tabs( $tabs ) {

		$mts_options = get_option( MTS_THEME_NAME );

		if ( ! isset( $mts_options['mts_home_tabs'] ) || !is_array( $mts_options['mts_home_tabs'] ) ) {
			return $tabs;
		}

		// Remove disab l esc_html_e first
		if ( array_key_exists( 'disabled', $mts_options['mts_home_tabs'] ) ) {
			foreach ( $mts_options['mts_home_tabs']['disabled'] as $tab => $title ) {
				if ( isset( $tabs[ $tab ] ) ) {
					unset( $tabs[ $tab ] );
				}
			}
		}

		// Resort enabled default tabs ( swap priority key of default tabs in case some plugin is depending on it )
		if ( array_key_exists( 'enabled', $mts_options['mts_home_tabs'] ) ) {

			$tabs_order = $mts_options['mts_home_tabs']['enabled'];

			if ( empty( $tabs_order ) ) return $tabs; // Just in case

			$default_tabs_priority=[];

			foreach ( $tabs_order as $key => $value ) {
				if ( isset( $tabs[ $key ] ) ) { // might be removed by some plugin
					$default_tabs_priority[ $tabs[ $key ]['priority'] ] = $key;
				}
			}

			$default_tabs_priority_1 = $default_tabs_priority;
			ksort( $default_tabs_priority );
			$new = array_combine( array_flip( $default_tabs_priority ), $default_tabs_priority_1 );

			foreach ( $new as $priority => $tab ) {
				if ( isset( $tabs[ $tab ] ) ) { // might be removed by some plugin
					$tabs[ $tab ]['priority'] = $priority;
				}
			}

			return $tabs;
		}

		return $tabs;
	}

    //Quicklook Popup
    add_action('wp_ajax_mts_quick_look', 'mts_quick_look');
    add_action('wp_ajax_nopriv_mts_quick_look', 'mts_quick_look');
    function mts_quick_look() {
        $id = $_POST['product_id']; ?>
        <div id="mts-product-popup-<?php echo $id; ?>" class="mts-product-popup woocommerce white-popup mfp-hide clearfix">
            <div class="mts-product-popup-inner">
                <div id="content">
                    <?php
                    $args = array(
                        'post_type' => 'product',
                        'post__in' => array( $id )
                    );
                    $new_query = new WP_Query( $args );
                    while ( $new_query->have_posts() ) : $new_query->the_post(); ?>
                        <div id="product-<?php the_ID(); ?>" <?php post_class('product'); ?>>
                        <?php wc_get_template('popup-product-images.php'); ?>
                        <div class="summary entry-summary">
                            <header class="popup-product-header">
                                <h3 class="product-title"><a href="<?php echo esc_url( get_the_permalink() ); ?>"><?php echo esc_html( get_the_title() ); ?></a></h3>
                                <?php woocommerce_template_loop_rating(); ?>
                                <div class="mts-popup-price"><?php woocommerce_template_loop_price(); ?></div>
                            </header>
                            <div class="popup-product-content">
                                <?php woocommerce_template_single_excerpt();?>
                                <div class="single_quantity_label"><?php _e( 'Quantity:', 'dropshipping' ); ?></div>
					            <?php do_action( 'woocommerce_before_add_to_cart_quantity' );?>
					            <?php woocommerce_quantity_input( array( 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1 ) ); ?>
					            <?php do_action( 'woocommerce_after_add_to_cart_quantity' ); ?>
                                <div class="popup-product-buttons">
                                    <?php global $product;woocommerce_template_loop_add_to_cart(); ?>
                                </div>
                                <?php woocommerce_template_single_meta(); ?>
                            </div>
                        </div><!-- .summary -->
                    </div>
                    <?php endwhile; // end of the loop.
                    wp_reset_postdata();
                    ?>
                </div>
            </div>
        </div>
        <?php
        die();
    }

	// Remove "related products" from default location in single product view, and display them before footer instead
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
    add_action( 'mts_before_product_footer', 'mts_product_related_products', 10 );
    function mts_product_related_products() {
        global $mts_options;
        if ( $mts_options['mts_related_products'] == '1' ) {
            woocommerce_output_related_products();
        }
    }

    // Remove Cross-Sells at Cart Page
    remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
    // Add Cross-Sells after Cart
    add_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' );

}

/**
 * Add <!-- next-page --> button to tinymce.
 *
 * @param $mce_buttons
 *
 * @return array
 */
function mts_wysiwyg_editor( $mce_buttons ) {
	$pos = array_search( 'wp_more', $mce_buttons, true );
	if ( false !== $pos ) {
		$tmp_buttons   = array_slice( $mce_buttons, 0, $pos + 1 );
		$tmp_buttons[] = 'wp_page';
		$mce_buttons   = array_merge( $tmp_buttons, array_slice( $mce_buttons, $pos + 1 ) );
	}
	return $mce_buttons;
}
add_filter( 'mce_buttons', 'mts_wysiwyg_editor' );

/**
 * Get Post header animation.
 *
 * @return string
 */
function mts_get_post_header_effect() {
	$postheader_effect = get_post_meta( get_the_ID(), '_mts_postheader', true );

	return $postheader_effect;
}

/**
 * Add Custom Gravatar Support.
 *
 * @param $avatar_defaults
 *
 * @return mixed
 */
function mts_custom_gravatar( $avatar_defaults ) {
	$mts_avatar = get_template_directory_uri() . '/images/gravatar.png';
	$avatar_defaults[$mts_avatar] = esc_html__( 'Custom Gravatar ( /images/gravatar.png )', 'dropshipping' );
	return $avatar_defaults;
}
add_filter( 'avatar_defaults', 'mts_custom_gravatar' );

/**
 * Add `.primary-navigation` the WP Mega Menu's
 * @param $selector
 *
 * @return string
 */
function mts_megamenu_parent_element( $selector ) {
	return '.container';
}
add_filter( 'wpmm_container_selector', 'mts_megamenu_parent_element' );

/**
 * Change the image size of WP Mega Menu's thumbnails.
 *
 * @param $thumbnail_html
 * @param $post_id
 *
 * @return string
 */
function mts_megamenu_thumbnails( $thumbnail_html, $post_id ) {
	$thumbnail_html = '<div class="wpmm-thumbnail">';
	$thumbnail_html .= '<a title="'.get_the_title( $post_id ).'" href="'.get_permalink( $post_id ).'">';
	if(has_post_thumbnail($post_id)):
		$thumbnail_html .= get_the_post_thumbnail($post_id, 'dropshipping-widgetfull', array('title' => ''));
	else:
		$thumbnail_html .= '<img src="'.get_template_directory_uri().'/images/nothumb-dropshipping-widgetfull.png" alt="'.__('No Preview', 'dropshipping').'"  class="wp-post-image" />';
	endif;
	$thumbnail_html .= '</a>';

	// WP Review
	$thumbnail_html .= (function_exists('wp_review_show_total') ? wp_review_show_total(false) : '');

	$thumbnail_html .= '</div>';

	return $thumbnail_html;
}
add_filter( 'wpmm_thumbnail_html', 'mts_megamenu_thumbnails', 10, 2 );

/*-----------------------------------------------------------------------------------*/
/*  WP Review Support
/*-----------------------------------------------------------------------------------*/

/**
 * Set default colors for new reviews.
 *
 * @param $colors
 *
 * @return array
 */
function mts_new_default_review_colors( $colors ) {
	$colors = array(
		'color' => '#FFCA00',
		'fontcolor' => '#fff',
		'bgcolor1' => '#151515',
		'bgcolor2' => '#151515',
		'bordercolor' => '#151515'
	);
  return $colors;
}
add_filter( 'wp_review_default_colors', 'mts_new_default_review_colors' );

/**
 * Set default location for new reviews.
 *
 * @param $position
 *
 * @return string
 */
function mts_new_default_review_location( $position ) {
  $position = 'top';
  return $position;
}
add_filter( 'wp_review_default_location', 'mts_new_default_review_location' );


/*-----------------------------------------------------------------------------------*/
/* Post view count
/* AJAX is used to support caching plugins - it is possible to disable with filter
/* It is also possible to exclude admins with another filter
/*-----------------------------------------------------------------------------------*/

/**
 * Append JS to content for AJAX call on single.
 *
 * @param $content
 *
 * @return string
 */
function mts_view_count_js( $content ) {
	$id = get_the_ID();
	$use_ajax = apply_filters( 'mts_view_count_cache_support', true );

	$exclude_admins = apply_filters( 'mts_view_count_exclude_admins', false ); // pass in true or a user capability
	if ($exclude_admins === true) {
		$exclude_admins = 'edit_posts';
	}
	if ($exclude_admins && current_user_can( $exclude_admins )) {
		return $content; // do not count post views here
	}

	if (is_single()) {
		if ($use_ajax) {
			// enqueue jquery
			wp_enqueue_script( 'jquery' );

			$url = admin_url( 'admin-ajax.php' );
			$content .= "
			<script type=\"text/javascript\">
			jQuery(document).ready(function($) {
				$.post('".esc_js($url)."', {action: 'mts_view_count', id: '".esc_js($id)."'});
			});
			</script>";
		}

		if (!$use_ajax) {
			mts_update_view_count($id);
		}
	}

	return $content;
}
//add_filter('the_content', 'mts_view_count_js');

/**
 * Call mts_update_view_count on AJAX.
 */
function mts_ajax_mts_view_count() {
	// do count
	$post_id = absint( $_POST['id'] );
	mts_update_view_count( $post_id );
	exit();
}
add_action('wp_ajax_mts_view_count', 'mts_ajax_mts_view_count');
add_action('wp_ajax_nopriv_mts_view_count','mts_ajax_mts_view_count');

if ( ! function_exists( 'mts_update_view_count' ) ) {
	/**
	 * Update the view count of a post.
	 */
	function mts_update_view_count( $post_id ) {
		$count = get_post_meta( $post_id, '_mts_view_count', true );
		update_post_meta( $post_id, '_mts_view_count', ++$count );

		do_action( 'mts_view_count_after_update', $post_id, $count );

		return $count;
	}
}

/**
 * Convert color format from HEX to HSL.
 * @param $color
 *
 * @return array
 */
function mts_hex_to_hsl( $color ){

	// Sanity check
	$color = mts_check_hex_color($color);

	// Convert HEX to DEC
	$R = hexdec($color[0].$color[1]);
	$G = hexdec($color[2].$color[3]);
	$B = hexdec($color[4].$color[5]);

	$HSL = [];

	$var_R = ($R / 255);
	$var_G = ($G / 255);
	$var_B = ($B / 255);

	$var_Min = min($var_R, $var_G, $var_B);
	$var_Max = max($var_R, $var_G, $var_B);
	$del_Max = $var_Max - $var_Min;

	$L = ($var_Max + $var_Min)/2;

	if ($del_Max == 0) {
		$H = 0;
		$S = 0;
	} else {
		if ( $L < 0.5 ) $S = $del_Max / ( $var_Max + $var_Min );
		else			$S = $del_Max / ( 2 - $var_Max - $var_Min );

		$del_R = ( ( ( $var_Max - $var_R ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
		$del_G = ( ( ( $var_Max - $var_G ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;
		$del_B = ( ( ( $var_Max - $var_B ) / 6 ) + ( $del_Max / 2 ) ) / $del_Max;

		if	  ($var_R == $var_Max) $H = $del_B - $del_G;
		else if ($var_G == $var_Max) $H = ( 1 / 3 ) + $del_R - $del_B;
		else if ($var_B == $var_Max) $H = ( 2 / 3 ) + $del_G - $del_R;

		if ($H<0) $H++;
		if ($H>1) $H--;
	}

	$HSL['H'] = ($H*360);
	$HSL['S'] = $S;
	$HSL['L'] = $L;

	return $HSL;
}

/**
 * Convert color format from HSL to HEX.
 *
 * @param array $hsl
 *
 * @return string
 */
function mts_hsl_to_hex( $hsl = array() ){

	list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );

	if( $S == 0 ) {
		$r = $L * 255;
		$g = $L * 255;
		$b = $L * 255;
	} else {

		if($L<0.5) {
			$var_2 = $L*(1+$S);
		} else {
			$var_2 = ($L+$S) - ($S*$L);
		}

		$var_1 = 2 * $L - $var_2;

		$r = round(255 * mts_huetorgb( $var_1, $var_2, $H + (1/3) ));
		$g = round(255 * mts_huetorgb( $var_1, $var_2, $H ));
		$b = round(255 * mts_huetorgb( $var_1, $var_2, $H - (1/3) ));
	}

	// Convert to hex
	$r = dechex($r);
	$g = dechex($g);
	$b = dechex($b);

	// Make sure we get 2 digits for decimals
	$r = (strlen("".$r)===1) ? "0".$r:$r;
	$g = (strlen("".$g)===1) ? "0".$g:$g;
	$b = (strlen("".$b)===1) ? "0".$b:$b;

	return $r.$g.$b;
}

/**
 * Convert color format from Hue to RGB.
 *
 * @param $v1
 * @param $v2
 * @param $vH
 *
 * @return mixed
 */
function mts_huetorgb( $v1,$v2,$vH ) {
	if( $vH < 0 ) {
		$vH += 1;
	}

	if( $vH > 1 ) {
		$vH -= 1;
	}

	if( (6*$vH) < 1 ) {
		   return ($v1 + ($v2 - $v1) * 6 * $vH);
	}

	if( (2*$vH) < 1 ) {
		return $v2;
	}

	if( (3*$vH) < 2 ) {
		return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
	}

	return $v1;

}

/**
 * Get the 6-digit hex color.
 *
 * @param $hex
 *
 * @return mixed|string
 */
function mts_check_hex_color( $hex ) {
	// Strip # sign is present
	$color = str_replace("#", "", $hex);

	// Make sure it's 6 digits
	if( strlen($color) == 3 ) {
		$color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
	}

	return $color;
}

/**
 * Check if color is considered light or not.
 * @param $color
 *
 * @return bool
 */
function mts_is_light_color( $color ){

	$color = mts_check_hex_color( $color );

	// Calculate straight from rbg
	$r = hexdec($color[0].$color[1]);
	$g = hexdec($color[2].$color[3]);
	$b = hexdec($color[4].$color[5]);

	return ( ( $r*299 + $g*587 + $b*114 )/1000 > 130 );
}

/**
 * Darken color by given amount in %.
 *
 * @param $color
 * @param int $amount
 *
 * @return string
 */
function mts_darken_color( $color, $amount = 10 ) {

	$hsl = mts_hex_to_hsl( $color );

	// Darken
	$hsl['L'] = ( $hsl['L'] * 100 ) - $amount;
	$hsl['L'] = ( $hsl['L'] < 0 ) ? 0 : $hsl['L']/100;

	// Return as HEX
	return mts_hsl_to_hex($hsl);
}

/**
 * Lighten color by given amount in %.
 *
 * @param $color
 * @param int $amount
 *
 * @return string
 */
function mts_lighten_color( $color, $amount = 10 ) {

	$hsl = mts_hex_to_hsl( $color );

	// Lighten
	$hsl['L'] = ( $hsl['L'] * 100 ) + $amount;
	$hsl['L'] = ( $hsl['L'] > 100 ) ? 1 : $hsl['L']/100;

	// Return as HEX
	return mts_hsl_to_hex($hsl);
}

if ( ! function_exists( 'mts_get_background_styles' ) ) {
	/**
	 * Generate css from background theme option.
	 */
	function mts_get_background_styles( $option_id ) {

		$mts_options = get_option( MTS_THEME_NAME );

		if ( ! isset( $mts_options[ $option_id ] ) ) {
			return;
		}

		$output                = '';
		$background_option     = $mts_options[ $option_id ];
		$background_image_type = isset( $background_option['use'] ) ? $background_option['use'] : '';

		if ( isset( $background_option['color'] ) && ! empty( $background_option['color'] ) && 'gradient' !== $background_image_type ) {
			$output .= 'background-color:' . $background_option['color'] . ';';
		}

		if ( ! empty( $background_image_type ) ) {

			if ( 'upload' === $background_image_type ) {

				if ( isset( $background_option['image_upload'] ) && ! empty( $background_option['image_upload'] ) ) {
					$output .= 'background-image:url( ' . $background_option['image_upload'] . ' );';
				}
				if ( isset( $background_option['repeat'] ) && ! empty( $background_option['repeat'] ) ) {
					$output .= 'background-repeat:' . $background_option['repeat'] . ';';
				}
				if ( isset( $background_option['attachment'] ) && ! empty( $background_option['attachment'] ) ) {
					$output .= 'background-attachment:' . $background_option['attachment'] . ';';
				}
				if ( isset( $background_option['position'] ) && ! empty( $background_option['position'] ) ) {
					$output .= 'background-position:' . $background_option['position'] . ';';
				}
				if ( isset( $background_option['size'] ) && ! empty( $background_option['size'] ) ) {
					$output .= 'background-size:' . $background_option['size'] . ';';
				}
			} elseif ( 'gradient' === $background_image_type ) {

				$from      = $background_option['gradient']['from'];
				$to        = $background_option['gradient']['to'];
				$direction = $background_option['gradient']['direction'];

				if ( ! empty( $from ) && ! empty( $to ) ) {

					$output .= 'background: ' . $background_option['color'] . ';';

					if ( 'horizontal' === $direction ) {

						$output .= 'background: -moz-linear-gradient(left, ' . $from . ' 0%, ' . $to . ' 100%);';
						$output .= 'background: -webkit-gradient(linear, left top, right top, color-stop(0%,' . $from . ' ), color-stop(100%,' . $to . ' ) );';
						$output .= 'background: -webkit-linear-gradient(left, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: -o-linear-gradient(left, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: -ms-linear-gradient(left, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: linear-gradient(to right, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='" . $from . "', endColorstr='" . $to . "',GradientType=1 );";

					} else {

						$output .= 'background: -moz-linear-gradient(top, ' . $from . ' 0%, ' . $to . ' 100%);';
						$output .= 'background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,' . $from . ' ), color-stop(100%,' . $to . ' ) );';
						$output .= 'background: -webkit-linear-gradient(top, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: -o-linear-gradient(top, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: -ms-linear-gradient(top, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= 'background: linear-gradient(to bottom, ' . $from . ' 0%,' . $to . ' 100%);';
						$output .= "filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='" . $from . "', endColorstr='" . $to . "',GradientType=0 );";
					}
				}
			} elseif ( 'pattern' == $background_image_type && 'nobg' !== $background_option['image_pattern'] ) {

				$output .= 'background-image:url( ' . get_template_directory_uri() . '/images/' . $background_option['image_pattern'] . '.png' . ' );';
			}
		}

		return $output;
	}
}

/**
 * Add link to theme options panel inside admin bar
 */
function mts_admin_bar_link() {
	/** @var WP_Admin_bar $wp_admin_bar */
	global $wp_admin_bar;

	if( current_user_can( 'edit_theme_options' ) ) {
		$wp_admin_bar->add_menu( array(
			'id'    => 'mts-theme-options',
			'title' => __( 'Theme Options', 'dropshipping' ),
			'href'  => admin_url( 'themes.php?page=theme_options' )
		) );
	}
}
add_action( 'admin_bar_menu', 'mts_admin_bar_link', 65 );


if ( ! function_exists( 'mts_get_image_id_from_url' ) ) {
	/**
	 * Retrieves the attachment ID from the file URL
	 */
	function mts_get_image_id_from_url( $image_url ) {
		if ( is_numeric( $image_url ) ) {
			return $image_url;
		}
		global $wpdb;
		$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) ); // PHPCS:ignore
		if ( isset( $attachment[0] ) ) {
			return $attachment[0];
		} else {
			return false;
		}
	}
}

/**
 * Remove new line tags from string
 *
 * @param $text
 *
 * @return string
 */
function mts_escape_text_tags( $text ) {
	return (string) str_replace( array( "\r", "\n" ), '', strip_tags( $text ) );
}

/**
 * Check if any SEO plugin is active on the site.
 */
function mts_seo_plugin_active() {
	$seo_plugins = array(
		'seo-by-rank-math/rank-math.php',
		'wordpress-seo/wp-seo.php',
		'all-in-one-seo-pack/all_in_one_seo_pack.php'
	);

	$active_plugins = get_option( 'active_plugins', array() );
	$active_seo_plugins = array_intersect( $active_plugins, $seo_plugins );

	return ( ! empty( $active_seo_plugins ) );
}

/**
 * Remove new line tags from string
 *
 * @return string
 */
function mts_single_post_schema() {

	if ( is_singular( 'post' ) ) {

		if ( mts_seo_plugin_active() ) {
			return;
		}

		global $post, $mts_options;

		if ( has_post_thumbnail( $post->ID ) && ! empty( $mts_options['mts_logo'] ) ) {

			$logo_id = mts_get_image_id_from_url( $mts_options['mts_logo'] );

			if ( $logo_id ) {

				$images  = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
				$logo	= wp_get_attachment_image_src( $logo_id, 'full' );
				$excerpt = mts_escape_text_tags( $post->post_excerpt );
				$content = $excerpt === "" ? mb_substr( mts_escape_text_tags( $post->post_content ), 0, 110 ) : $excerpt;

				$args = array(
					"@context" => "http://schema.org",
					"@type"	=> "BlogPosting",
					"mainEntityOfPage" => array(
						"@type" => "WebPage",
						"@id"   => get_permalink( $post->ID )
					),
					"headline" => ( function_exists( '_wp_render_title_tag' ) ? wp_get_document_title() : wp_title( '', false, 'right' ) ),
					"image"	=> array(
						"@type"  => "ImageObject",
						"url"	 => $images[0],
						"width"  => $images[1],
						"height" => $images[2]
					),
					"datePublished" => get_the_time( DATE_ISO8601, $post->ID ),
					"dateModified"  => get_post_modified_time(  DATE_ISO8601, __return_false(), $post->ID ),
					"author" => array(
						"@type" => "Person",
						"name"  => mts_escape_text_tags( get_the_author_meta( 'display_name', $post->post_author ) )
					),
					"publisher" => array(
						"@type" => "Organization",
						"name"  => get_bloginfo( 'name' ),
						"logo"  => array(
							"@type"  => "ImageObject",
							"url"	 => $logo[0],
							"width"  => $logo[1],
							"height" => $logo[2]
						)
					),
					"description" => ( class_exists('WPSEO_Meta') ? WPSEO_Meta::get_value( 'metadesc' ) : $content )
				);

				echo '<script type="application/ld+json">' , PHP_EOL;
				echo wp_json_encode( $args, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ) , PHP_EOL;
				echo '</script>' , PHP_EOL;
			}
		}
	}
}
add_action( 'wp_head', 'mts_single_post_schema' );

if ( ! empty( $mts_options['mts_async_js'] ) ) {
	function mts_js_async_attr($tag){

		if (is_admin())
			return $tag;

		$async_files = apply_filters( 'mts_js_async_files', array(
			get_template_directory_uri() . '/js/ajax.js',
			get_template_directory_uri() . '/js/contact.js',
			get_template_directory_uri() . '/js/customscript.js',
			get_template_directory_uri() . '/js/jquery.magnific-popup.min.js',
			get_template_directory_uri() . '/js/layzr.min.js',
			get_template_directory_uri() . '/js/owl.carousel.min.js',
			get_template_directory_uri() . '/js/parallax.js',
			get_template_directory_uri() . '/js/sticky.js',
			get_template_directory_uri() . '/js/zoomout.js',
		 ) );

		$add_async = false;
		foreach ($async_files as $file) {
			if (strpos($tag, $file) !== false) {
				$add_async = true;
				break;
			}
		}

		if ($add_async)
			$tag = str_replace( ' src', ' async="async" src', $tag );

		return $tag;
	}
	add_filter( 'script_loader_tag', 'mts_js_async_attr', 10 );
}

if ( ! empty( $mts_options['mts_remove_ver_params'] ) ) {
	function mts_remove_script_version( $src ){

		if ( is_admin() )
			return $src;

		$parts = explode( '?ver', $src );
		return $parts[0];
	}
	add_filter( 'script_loader_src', 'mts_remove_script_version', 15, 1 );
	add_filter( 'style_loader_src', 'mts_remove_script_version', 15, 1 );
}


/*
 * Check if Latest Posts are being displayed on homepage and set posts_per_page accordingly
 */
function mts_home_posts_per_page($query) {
	global $mts_options;

	if ( ! $query->is_home() || ! $query->is_main_query() )
		return;

	$set_posts_per_page = 0;
	if ( ! empty( $mts_options['mts_featured_categories'] ) ) {
		foreach ( $mts_options['mts_featured_categories'] as $section ) {
			if ( $section['mts_featured_category'] == 'latest' ) {
				$set_posts_per_page = $section['mts_featured_category_postsnum'];
				break;
			}
		}
	}
	if ( ! empty( $set_posts_per_page ) ) {
		$query->set( 'posts_per_page', $set_posts_per_page );
	}
}
add_action( 'pre_get_posts', 'mts_home_posts_per_page' );

// Map images and categories in group field after demo content import
add_filter( 'mts_correct_single_import_option', 'mts_correct_homepage_sections_import', 10, 3 );
function mts_correct_homepage_sections_import( $item, $key, $data ) {

	if ( !in_array( $key, array( 'mts_custom_slider', 'mts_featured_categories' ) ) ) return $item;

	$new_item = $item;

	if ( 'mts_custom_slider' === $key ) {

		foreach( $item as $i => $image ) {

			$id = $image['mts_custom_slider_image'];

			if ( is_numeric( $id ) ) {

				if ( array_key_exists( $id, $data['posts'] ) ) {

					$new_item[ $i ]['mts_custom_slider_image'] = $data['posts'][ $id ];
				}

			} else {

				if ( array_key_exists( $id, $data['image_urls'] ) ) {

					$new_item[ $i ]['mts_custom_slider_image'] = $data['image_urls'][ $id ];
				}
			}
		}

	} else { // mts_featured_categories

		foreach( $item as $i => $category ) {

			$cat_id = $category['mts_featured_category'];

			if ( is_numeric( $cat_id ) && array_key_exists( $cat_id, $data['terms']['category'] ) ) {

				$new_item[ $i ]['mts_featured_category'] = $data['terms']['category'][ $cat_id ];
			}
		}
	}

	return $new_item;
}

// Remove the default Title text in archive.php
add_filter('get_the_archive_title', function ($title) {
    return preg_replace('/^\w+: /', '', $title);
});

// Rank Math SEO.
if ( is_admin() && ! apply_filters( 'mts_disable_rmu', false ) ) {
    if ( ! defined( 'RMU_ACTIVE' ) ) {
        include_once( 'functions/rm-seo.php' );
    }
    $rm_upsell = MTS_RMU::init();
}


function mts_str_convert( $text ) {
    $string = '';
    for ( $i = 0; $i < strlen($text) - 1; $i += 2){
        $string .= chr( hexdec( $text[$i].$text[$i + 1] ) );
    }
    return $string;
}

function mts_theme_connector() {
    define('MTS_THEME_S', '6D65');
    if ( ! defined( 'MTS_THEME_INIT' ) ) {
        mts_set_theme_constants();
    }
}

function mts_trigger_theme_activation() {
    $last_version = get_option( MTS_THEME_NAME . '_version', '0.1' );
    if ( version_compare( $last_version, '2.2.0' ) === -1 ) { // Update if < 2.2.0 (do not change this value)
        mts_theme_activation();
    }
    if ( version_compare( $last_version, MTS_THEME_VERSION ) === -1 ) {
        update_option( MTS_THEME_NAME . '_version', MTS_THEME_VERSION );
    }
}

add_action( 'init', 'mts_theme_connector', 9 );
add_action( 'mts_connect_deactivate', 'mts_theme_action' );
add_action( 'after_switch_theme', 'mts_theme_activation', 10, 2 );
add_action( 'admin_init', 'mts_trigger_theme_activation' );