<?php
/**
 * Nebula Ocean functions and definitions
 *
 * @package Nebula Ocean
 */

/* Breadcrumb Begin */
function vw_newspaper_the_breadcrumb() {
	if (!is_home()) {
		echo '<a href="';
			echo esc_url( home_url() );
		echo '">';
			bloginfo('name');
		echo "</a> ";
		if (is_category() || is_single()) {
			the_category(',');
			if (is_single()) {
				echo "<span> ";
					the_title();
				echo "</span> ";
			}
		} elseif (is_page()) {
			echo "<span> ";
				the_title();
		}
	}
}

/* Theme Setup */
if ( ! function_exists( 'vw_newspaper_setup' ) ) :
 
function vw_newspaper_setup() {

	$GLOBALS['content_width'] = apply_filters( 'vw_newspaper_content_width', 640 );
	
	load_theme_textdomain( 'vw-newspaper', get_template_directory() . '/languages' );
	add_theme_support( 'automatic-feed-links' );
	add_theme_support( 'woocommerce' );
	add_theme_support( 'wc-product-gallery-zoom' );
	add_theme_support( 'wc-product-gallery-slider' ); 
	add_theme_support( 'wc-product-gallery-lightbox' );
	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'title-tag' );
	add_theme_support( 'align-wide' );
	add_theme_support( 'wp-block-styles' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'html5', array( 'comment-list', 'search-form', 'comment-form', ) );
	add_theme_support( 'custom-logo', array(
		'height'      => 240,
		'width'       => 240,
		'flex-height' => true,
	) );
	add_image_size('vw-newspaper-homepage-thumb',240,145,true);
	
    register_nav_menus( array(
		'primary' => __( 'Primary Menu', 'vw-newspaper' ),
	) );

	add_theme_support( 'custom-background', array(
		'default-color' => 'ffffff'
	) );

	//selective refresh for sidebar and widgets
	add_theme_support( 'customize-selective-refresh-widgets' );

	/*
	 * Enable support for Post Formats.
	 *
	 * See: https://codex.wordpress.org/Post_Formats
	 */
	add_theme_support( 'post-formats', array('image','video','gallery','audio',) );

	/*
	 * This theme styles the visual editor to resemble the theme style,
	 * specifically font, colors, icons, and column width.
	 */
	add_editor_style( array( 'css/editor-style.css', vw_newspaper_font_url() ) );

	// Theme Activation Notice
	global $pagenow;

	if (
		is_admin()
		&&
		('themes.php' == $pagenow)
		// &&
		// isset( $_GET['activated'] )
	) {
		add_action('admin_notices', 'vw_newspaper_activation_notice');
	}
}
endif;

add_action( 'after_setup_theme', 'vw_newspaper_setup' );

// Notice after Theme Activation

function vw_newspaper_activation_notice() {
		$vw_newspaper_meta = get_option( 'vw_newspaper_admin_notice' );

	if (!$vw_newspaper_meta) {
	echo '<div id="vw_newspaper-welcome-notice" class="notice notice-success is-dismissible welcome-notice">';
		echo '<div class="notice-row">';
			echo '<div class="notice-text">';
				echo '<p class="welcome-text1">'. esc_html__( '🎉 Welcome to Nebula Ocean,', 'nebula-ocean' ) .'</p>';
				echo '<p class="welcome-text2">'. esc_html__( 'Your dark cinematic publishing theme is active.', 'nebula-ocean' ) .'</p>';
				echo '<p class="welcome-text3">'. esc_html__( 'Use the theme customizer, widgets, menus, and Nebula Ocean shortcodes to build your pages.', 'nebula-ocean' ) .'</p>';
				echo '<span class="import-btn"><a href="'. esc_url( admin_url( 'themes.php?page=vw_newspaper_guide' ) ) .'" class="button button-primary">'. esc_html__( 'GET STARTED', 'vw-newspaper' ) .'</a></span>';
			echo '</div>';
			echo '<div class="notice-img1">';
				echo '<img src="' . esc_url( get_template_directory_uri() . '/inc/getstart/images/arrow-notice.png' ) . '" width="180" alt="' . esc_attr__( 'Nebula Ocean', 'vw-newspaper' ) . '" />';
			echo '</div>';
			echo '<div class="notice-img2">';
				echo '<img src="' . esc_url( get_template_directory_uri() . '/inc/getstart/images/bundle-notice.png' ) . '" width="180" alt="' . esc_attr__( 'Nebula Ocean', 'vw-newspaper' ) . '" />';
			echo '</div>';	
		echo '</div>';	
	echo '</div>';
}
}

/* Theme Widgets Setup */

function vw_newspaper_widgets_init() {
	
	register_sidebar( array(
		'name'          => __( 'Blog Sidebar', 'vw-newspaper' ),
		'description'   => __( 'Appears on blog page sidebar', 'vw-newspaper' ),
		'id'            => 'sidebar-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
	
	register_sidebar( array(
		'name'          => __( 'Page Sidebar', 'vw-newspaper' ),
		'description'   => __( 'Appears on page sidebar', 'vw-newspaper' ),
		'id'            => 'sidebar-2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Sidebar 3', 'vw-newspaper' ),
		'description'   => __( 'Appears on blog page sidebar', 'vw-newspaper' ),
		'id'            => 'sidebar-3',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer Navigation 1', 'vw-newspaper' ),
		'description'   => __( 'Appears on footer 1', 'vw-newspaper' ),
		'id'            => 'footer-1',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer Navigation 2', 'vw-newspaper' ),
		'description'   => __( 'Appears on footer 2', 'vw-newspaper' ),
		'id'            => 'footer-2',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer Navigation 3', 'vw-newspaper' ),
		'description'   => __( 'Appears on footer 3', 'vw-newspaper' ),
		'id'            => 'footer-3',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Footer Navigation 4', 'vw-newspaper' ),
		'description'   => __( 'Appears on footer 4', 'vw-newspaper' ),
		'id'            => 'footer-4',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Social Icon', 'vw-newspaper' ),
		'description'   => __( 'Appears on footer', 'vw-newspaper' ),
		'id'            => 'social-icon',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Shop Page Sidebar', 'vw-newspaper' ),
		'description'   => __( 'Appears on shop page', 'vw-newspaper' ),
		'id'            => 'woocommerce-shop-sidebar',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );

	register_sidebar( array(
		'name'          => __( 'Single Product Sidebar', 'vw-newspaper' ),
		'description'   => __( 'Appears on single product page', 'vw-newspaper' ),
		'id'            => 'woocommerce-single-sidebar',
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h3 class="widget-title">',
		'after_title'   => '</h3>',
	) );
}
add_action( 'widgets_init', 'vw_newspaper_widgets_init' );

/* Theme Font URL */
function vw_newspaper_font_url() {
	$font_family   = array(

		'ABeeZee:ital@0;1',
	 	'Abril Fatface',
	 	'Acme',
	 	'Alfa Slab One',
	 	'Allura',
	 	'Anton', 
	 	'Architects Daughter',
	 	'Archivo:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Arimo:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700',
	 	'Arsenal:ital,wght@0,400;0,700;1,400;1,700',
	 	'Arvo:ital,wght@0,400;0,700;1,400;1,700',
	 	'Alegreya Sans:ital,wght@0,100;0,300;0,400;0,500;0,700;0,800;0,900;1,100;1,300;1,400;1,500;1,700;1,800;1,900',
	 	'Asap:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Assistant:wght@200;300;400;500;600;700;800',
	 	'Averia Serif Libre:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700',
	 	'Bangers',
	 	'Boogaloo',
	 	'Bad Script',
	 	'Barlow Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Bitter:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Bree Serif',
	 	'BenchNine:wght@300;400;700',
	 	'Cabin:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700',
	 	'Cardo:ital,wght@0,400;0,700;1,400',
	 	'Courgette',
	 	'Caveat Brush',
	 	'Cherry Swash:wght@400;700',
	 	'Cormorant Garamond:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700',
	 	'Crimson Text:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700',
	 	'Cuprum:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700',
	 	'Cookie',
	 	'Coming Soon',
	 	'Charm:wght@400;700',
	 	'Chewy',
	 	'Days One',
	 	'DM Serif Display:ital@0;1',
	 	'Dosis:wght@200;300;400;500;600;700;800',
	 	'EB Garamond:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400;1,500;1,600;1,700;1,800',
	 	'Economica:ital,wght@0,400;0,700;1,400;1,700',
	 	'Exo 2:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Fira Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Fredoka One',
	 	'Fjalla One',
	 	'Frank Ruhl Libre:wght@300;400;500;700;900',
	 	'Gabriela',
	 	'Gloria Hallelujah',
	 	'Great Vibes',
	 	'Handlee',
	 	'Hammersmith One',
	 	'Heebo:wght@100;200;300;400;500;600;700;800;900',
	 	'Hind:wght@300;400;500;600;700',
	 	'Inconsolata:wght@200;300;400;500;600;700;800;900',
	 	'Indie Flower',
	 	'IM Fell English SC',
	 	'Julius Sans One',
	 	'Jomhuria',
	 	'Josefin Slab:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700',
	 	'Josefin Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700',
	 	'Jost:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Kanit:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Kaushan Script',
	 	'Krub:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700',
	 	'Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900',
	 	'Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700',
	 	'Libre Baskerville:ital,wght@0,400;0,700;1,400',
	 	'Literata:ital,opsz,wght@0,7..72,200;0,7..72,300;0,7..72,400;0,7..72,500;0,7..72,600;0,7..72,700;0,7..72,800;0,7..72,900;1,7..72,200;1,7..72,300;1,7..72,400;1,7..72,500;1,7..72,600;1,7..72,700;1,7..72,800;1,7..72,900',
	 	'Lobster',
	 	'Lobster Two:ital,wght@0,400;0,700;1,400;1,700',
	 	'Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900',
	 	'Marck Script',
	 	'Marcellus',
	 	'Merienda One',
	 	'Monda:wght@400;700',
	 	'Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Mulish:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;0,1000;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900;1,1000',
	 	'Noto Serif:ital,wght@0,400;0,700;1,400;1,700',
	 	'Nunito Sans:ital,wght@0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,600;1,700;1,800;1,900',
	 	'Open Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800',
	 	'Overpass:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Overpass Mono:wght@300;400;500;600;700',
	 	'Oxygen:wght@300;400;700',
	 	'Oswald:wght@200;300;400;500;600;700',
	 	'Orbitron:wght@400;500;600;700;800;900',
	 	'Patua One',
	 	'Pacifico',
	 	'Padauk:wght@400;700',
	 	'Playball',
	 	'Playfair Display:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Prompt:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'PT Sans:ital,wght@0,400;0,700;1,400;1,700',
	 	'PT Serif:ital,wght@0,400;0,700;1,400;1,700',
	 	'Philosopher:ital,wght@0,400;0,700;1,400;1,700',
	 	'Permanent Marker',
	 	'Poiret One',
	 	'Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Prata',
	 	'Quicksand:wght@300;400;500;600;700',
	 	'Quattrocento Sans:ital,wght@0,400;0,700;1,400;1,700',
	 	'Raleway:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900',
	 	'Roboto Condensed:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700',
	 	'Rokkitt:wght@100;200;300;400;500;600;700;800;900',
	 	'Ropa Sans:ital@0;1',
	 	'Russo One',
	 	'Righteous',
	 	'Saira:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Satisfy',
	 	'Sen:wght@400;700;800',
	 	'Source Sans Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900',
	 	'Shadows Into Light Two',
	 	'Shadows Into Light',
	 	'Sacramento',
	 	'Sail',
	 	'Shrikhand',
	 	'Staatliches',
	 	'Stylish',
	 	'Tangerine:wght@400;700',
	 	'Titillium Web:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700',
	 	'Trirong:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700',
	 	'Unica One',
	 	'VT323',
	 	'Varela Round',
	 	'Vampiro One',
	 	'Vollkorn:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Volkhov:ital,wght@0,400;0,700;1,400;1,700',
	 	'Work Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900',
	 	'Yanone Kaffeesatz:wght@200;300;400;500;600;700',
	 	'ZCOOL XiaoWei'
	);
	
	$query_args = array(
		'family'	=> rawurlencode(implode('|',$font_family)),
	);
	$font_url = add_query_arg($query_args,'//fonts.googleapis.com/css');
	return $font_url;
	$contents = vw_newspaper_wptt_get_webfont_url( esc_url_raw( $fonts_url ) );
}

/* Theme enqueue scripts */
function vw_newspaper_scripts() {
	wp_enqueue_style( 'vw-newspaper-font', vw_newspaper_font_url(), array() );
	wp_enqueue_style( 'block-style', get_theme_file_uri('/css/blocks.css') );
	wp_enqueue_style( 'vw-newspaper-block-patterns-style-frontend', get_theme_file_uri('/inc/block-patterns/css/block-frontend.css') );
	wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/css/bootstrap.css' );
	wp_enqueue_style( 'vw-newspaper-basic-style', get_stylesheet_uri() );
	require get_parent_theme_file_path( '/inline-style.php' );
	wp_add_inline_style( 'vw-newspaper-basic-style',$vw_newspaper_custom_css );	
	wp_enqueue_style( 'vw-newspaper-effect', get_template_directory_uri().'/css/effect.css' );
	wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/css/fontawesome-all.css' );
	wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() . '/js/bootstrap.js', array('jquery') ,'',true);
	wp_enqueue_script( 'jquery-superfish-js', get_template_directory_uri() . '/js/jquery.superfish.js', array('jquery') ,'',true);
	wp_enqueue_script( 'vw-newspaper-custom-scripts', get_template_directory_uri() . '/js/custom.js', array('jquery') );
	wp_enqueue_style( 'owl-carousel-css', get_template_directory_uri().'/css/owl.carousel.css' );
	wp_enqueue_script( 'owl-carousel-js', get_template_directory_uri() . '/js/owl.carousel.js', array('jquery'), '', true);

	if (get_theme_mod('vw_newspaper_animation', true) == true){
		wp_enqueue_script( 'jquery-wow', get_template_directory_uri() . '/js/wow.js', array('jquery') );
		wp_enqueue_style( 'animate-css', get_template_directory_uri().'/css/animate.css' );
	}
	
	if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
		wp_enqueue_script( 'comment-reply' );
	}

	/* Enqueue the Dashicons script */
	wp_enqueue_style( 'dashicons' );
}
add_action( 'wp_enqueue_scripts', 'vw_newspaper_scripts' );

/**
 * Enqueue block editor style
 */
function vw_newspaper_block_editor_styles() {
	wp_enqueue_style( 'vw-newspaper-font', vw_newspaper_font_url(), array() );
    wp_enqueue_style( 'vw-newspaper-block-patterns-style-editor', get_theme_file_uri( '/inc/block-patterns/css/block-editor.css' ), false, '1.0', 'all' );
    wp_enqueue_style( 'bootstrap-style', get_template_directory_uri().'/css/bootstrap.css' );
    wp_enqueue_style( 'font-awesome-css', get_template_directory_uri().'/css/fontawesome-all.css' );
}
add_action( 'enqueue_block_editor_assets', 'vw_newspaper_block_editor_styles' );

/*radio button sanitization*/

function vw_newspaper_sanitize_choices( $input, $setting ) {
    global $wp_customize; 
    $control = $wp_customize->get_control( $setting->id ); 
    if ( array_key_exists( $input, $control->choices ) ) {
        return $input;
    } else {
        return $setting->default;
    }
}

function vw_newspaper_sanitize_float( $input ) {
	return filter_var($input, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}

function vw_newspaper_sanitize_number_range( $number, $setting ) {
	$number = absint( $number );
	$atts = $setting->manager->get_control( $setting->id )->input_attrs;
	$min = ( isset( $atts['min'] ) ? $atts['min'] : $number );
	$max = ( isset( $atts['max'] ) ? $atts['max'] : $number );
	$step = ( isset( $atts['step'] ) ? $atts['step'] : 1 );
	return ( $min <= $number && $number <= $max && is_int( $number / $step ) ? $number : $setting->default );
}

/* Excerpt Limit Begin */
function vw_newspaper_string_limit_words($string, $word_limit) {
	$words = explode(' ', $string, ($word_limit + 1));
	if(count($words) > $word_limit)
	array_pop($words);
	return implode(' ', $words);
}



// Change number or products per row to 3
add_filter('loop_shop_columns', 'vw_newspaper_loop_columns');
	if (!function_exists('vw_newspaper_loop_columns')) {
	function vw_newspaper_loop_columns() {
		return get_theme_mod( 'vw_newspaper_products_per_row', '3' ); 
		// 3 products per row
	}
}

function vw_newspaper_sanitize_phone_number( $phone ) {
	return preg_replace( '/[^\d+]/', '', $phone );
}

//Change number of products that are displayed per page (shop page)
add_filter( 'loop_shop_per_page', 'vw_newspaper_products_per_page' );
function vw_newspaper_products_per_page( $cols ) {
  	return  get_theme_mod( 'vw_newspaper_products_per_page',9);
}

function vw_newspaper_logo_title_hide_show(){
	if(get_theme_mod('vw_newspaper_logo_title_hide_show') == '1' ) {
		return true;
	}
	return false;
}

function vw_newspaper_tagline_hide_show(){
	if(get_theme_mod('vw_newspaper_tagline_hide_show', 0) == '1' ) {
		return true;
	}
	return false;
}

function vw_newspaper_blog_post_featured_image_dimension(){
	if(get_theme_mod('vw_newspaper_blog_post_featured_image_dimension') == 'custom' ) {
		return true;
	}
	return false;
}

/* Starter Content */
	add_theme_support( 'starter-content', array(
		'widgets' => array(
			'footer-1' => array(
				'categories',
			),
			'footer-2' => array(
				'archives',
			),
			'footer-3' => array(
				'meta',
			),
			'footer-4' => array(
				'search',
			),
		),
    ));

// edit

if (!function_exists('vw_newspaper_edit_link')) :

    function vw_newspaper_edit_link($view = 'default')
    {
        global $post;
            edit_post_link(
                sprintf(
                    wp_kses(
                    /* translators: %s: Name of current post. Only visible to screen readers */
                        __('Edit <span class="screen-reader-text">%s</span>', 'vw-newspaper'),
                        array(
                            'span' => array(
                                'class' => array(),
                            ),
                        )
                    ),
                    get_the_title()
                ),
                '<span class="edit-link"><i class="fas fa-edit"></i>',
                '</span>'
            );

    }
endif;

/* Implement the Custom Header feature. */
require get_template_directory() . '/inc/custom-header.php';

function vw_newspaper_init_setup() {
	/* Custom template tags for this theme. */
	require get_template_directory() . '/inc/template-tags.php';

	/* Customizer additions. */
	require get_template_directory() . '/inc/customizer.php';

	/* Social Custom Widgets */
	require get_template_directory() . '/inc/themes-widgets/social-icon.php';

	/* Customizer additions. */
	require get_template_directory() . '/inc/themes-widgets/about-us-widget.php';

	/* Customizer additions. */
	require get_template_directory() . '/inc/themes-widgets/contact-us-widget.php';

	/* Plugin Activation */
	require get_template_directory() . '/inc/getstart/plugin-activation.php';

	/* Implement the About theme page */
	require get_template_directory() . '/inc/getstart/getstart.php';

	/* typography */
	require get_template_directory() . '/inc/typography/ctypo.php';

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

	/* TGM Plugin Activation */
	require get_template_directory() . '/inc/tgm/tgm.php';

	/* Webfonts */
	require get_template_directory() . '/inc/wptt-webfont-loader.php';

	define('VW_NEWSPAPER_FREE_THEME_DOC',__('https://storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_SUPPORT',__('https://wordpress.org/support/theme/vw-newspaper/','vw-newspaper'));
	define('VW_NEWSPAPER_REVIEW',__('https://wordpress.org/support/theme/vw-newspaper/reviews','vw-newspaper'));
	define('VW_NEWSPAPER_BUY_NOW',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_LIVE_DEMO',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_PRO_DOC',__('https://storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_FAQ',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_CONTACT',__('https://www.storytimeandconfessions.com/contact/','vw-newspaper'));
	define('VW_NEWSPAPER_CHILD_THEME',__('https://developer.wordpress.org/themes/advanced-topics/child-themes/','vw-newspaper'));
	define('VW_NEWSPAPER_COPYRIGHT_CREDIT',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_CREDIT',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_THEME_BUNDLE_BUY_NOW',__('https://www.storytimeandconfessions.com/','vw-newspaper'));
	define('VW_NEWSPAPER_THEME_BUNDLE_DOC',__('https://storytimeandconfessions.com/','vw-newspaper'));

	if ( ! function_exists( 'vw_newspaper_credit' ) ) {
		function vw_newspaper_credit(){
			echo esc_html__( 'Nebula Ocean', 'nebula-ocean' );
		}
	}
}
add_action( 'after_setup_theme', 'vw_newspaper_init_setup' );	

// Admin notice code START
function vw_newspaper_dismissed_notice() {
	update_option( 'vw_newspaper_admin_notice', true );
}
add_action( 'wp_ajax_vw_newspaper_dismissed_notice', 'vw_newspaper_dismissed_notice' );


//After Switch theme function
add_action('after_switch_theme', 'vw_newspaper_getstart_setup_options');
function vw_newspaper_getstart_setup_options () {
    update_option('vw_newspaper_admin_notice', false );
}
// Admin notice code END

/* =========================================================
   StoryTime And Confessions - Fixed Footer Social Share Row
   Purpose: hide broken oversized loose social icons and add
   small, horizontal, clickable social share icons on inner pages.
   Added safely at the end of functions.php.
   ========================================================= */
if ( ! function_exists( 'stc_fixed_footer_social_share_row' ) ) {
	function stc_fixed_footer_social_share_row() {
		if ( is_front_page() || is_home() || is_admin() ) {
			return;
		}
		?>
		<style id="stc-fixed-footer-social-share-row-css">
			/* Hide the broken loose Font Awesome social icons that appear huge/vertical in the footer. */
			body:not(.home) footer i.fab,
			body:not(.home) footer i.fa-brands,
			body:not(.home) footer i.fa-facebook,
			body:not(.home) footer i.fa-facebook-f,
			body:not(.home) footer i.fa-twitter,
			body:not(.home) footer i.fa-x-twitter,
			body:not(.home) footer i.fa-pinterest,
			body:not(.home) footer i.fa-pinterest-p,
			body:not(.home) footer i.fa-linkedin,
			body:not(.home) footer i.fa-linkedin-in,
			body:not(.home) .site-footer i.fab,
			body:not(.home) .site-footer i.fa-brands,
			body:not(.home) .site-footer i.fa-facebook,
			body:not(.home) .site-footer i.fa-facebook-f,
			body:not(.home) .site-footer i.fa-twitter,
			body:not(.home) .site-footer i.fa-x-twitter,
			body:not(.home) .site-footer i.fa-pinterest,
			body:not(.home) .site-footer i.fa-pinterest-p,
			body:not(.home) .site-footer i.fa-linkedin,
			body:not(.home) .site-footer i.fa-linkedin-in {
				display: none !important;
				visibility: hidden !important;
				font-size: 0 !important;
				line-height: 0 !important;
				width: 0 !important;
				height: 0 !important;
				max-width: 0 !important;
				max-height: 0 !important;
				margin: 0 !important;
				padding: 0 !important;
				overflow: hidden !important;
			}

			/* The new clean row. */
			.stc-footer-share-row {
				display: flex !important;
				flex-direction: row !important;
				flex-wrap: nowrap !important;
				align-items: center !important;
				justify-content: center !important;
				gap: 12px !important;
				width: 100% !important;
				max-width: 100% !important;
				margin: 16px auto 10px auto !important;
				padding: 0 !important;
				text-align: center !important;
				line-height: 1 !important;
				clear: both !important;
			}

			.stc-footer-share-row a.stc-footer-share-link {
				display: inline-flex !important;
				align-items: center !important;
				justify-content: center !important;
				width: 32px !important;
				height: 32px !important;
				min-width: 32px !important;
				min-height: 32px !important;
				max-width: 32px !important;
				max-height: 32px !important;
				padding: 0 !important;
				margin: 0 !important;
				border-radius: 50% !important;
				box-sizing: border-box !important;
				background: rgba(0, 0, 0, 0.88) !important;
				border: 1px solid rgba(255, 255, 255, 0.45) !important;
				color: #ffffff !important;
				text-decoration: none !important;
				overflow: hidden !important;
				vertical-align: middle !important;
				box-shadow: none !important;
				transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease !important;
			}

			.stc-footer-share-row a.stc-footer-share-link:hover,
			.stc-footer-share-row a.stc-footer-share-link:focus {
				background: #ff1493 !important;
				border-color: #ff1493 !important;
				color: #ffffff !important;
				transform: translateY(-2px) !important;
				outline: none !important;
			}

			.stc-footer-share-row svg {
				display: block !important;
				width: 16px !important;
				height: 16px !important;
				min-width: 16px !important;
				min-height: 16px !important;
				max-width: 16px !important;
				max-height: 16px !important;
				fill: currentColor !important;
				stroke: none !important;
				margin: 0 !important;
				padding: 0 !important;
			}

			@media (max-width: 600px) {
				.stc-footer-share-row {
					gap: 10px !important;
					margin-top: 14px !important;
				}

				.stc-footer-share-row a.stc-footer-share-link {
					width: 30px !important;
					height: 30px !important;
					min-width: 30px !important;
					min-height: 30px !important;
					max-width: 30px !important;
					max-height: 30px !important;
				}

				.stc-footer-share-row svg {
					width: 15px !important;
					height: 15px !important;
					min-width: 15px !important;
					min-height: 15px !important;
					max-width: 15px !important;
					max-height: 15px !important;
				}
			}
		</style>

		<script id="stc-fixed-footer-social-share-row-js">
			document.addEventListener('DOMContentLoaded', function () {
				if (document.body.classList.contains('home') || document.querySelector('.stc-footer-share-row')) {
					return;
				}

				var encodedUrl = encodeURIComponent(window.location.href);
				var encodedTitle = encodeURIComponent(document.title || 'StoryTime And Confessions');

				var row = document.createElement('div');
				row.className = 'stc-footer-share-row';
				row.setAttribute('aria-label', 'Share this page on social media');
				row.innerHTML = '' +
					'<a class="stc-footer-share-link" href="https://www.facebook.com/sharer/sharer.php?u=' + encodedUrl + '" target="_blank" rel="noopener noreferrer" aria-label="Share on Facebook" title="Share on Facebook">' +
						'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M22 12.06C22 6.48 17.52 2 11.94 2S2 6.48 2 12.06c0 5.02 3.66 9.18 8.44 9.94v-7.03H7.9v-2.91h2.54V9.84c0-2.5 1.49-3.89 3.77-3.89 1.09 0 2.23.2 2.23.2v2.45h-1.26c-1.24 0-1.63.77-1.63 1.56v1.9h2.78l-.44 2.91h-2.34V22C18.34 21.24 22 17.08 22 12.06z"></path></svg>' +
					'</a>' +
					'<a class="stc-footer-share-link" href="https://twitter.com/intent/tweet?url=' + encodedUrl + '&text=' + encodedTitle + '" target="_blank" rel="noopener noreferrer" aria-label="Share on X" title="Share on X">' +
						'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M18.9 2.5h3.3l-7.2 8.2 8.5 11.3h-6.7l-5.2-6.8-6 6.8H2.3l7.7-8.8L1.8 2.5h6.8l4.7 6.2 5.6-6.2zm-1.2 17.5h1.8L7.6 4.4H5.7L17.7 20z"></path></svg>' +
					'</a>' +
					'<a class="stc-footer-share-link" href="https://pinterest.com/pin/create/button/?url=' + encodedUrl + '&description=' + encodedTitle + '" target="_blank" rel="noopener noreferrer" aria-label="Share on Pinterest" title="Share on Pinterest">' +
						'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12.04 2C6.56 2 3 5.94 3 10.23c0 2.05 1.13 4.61 2.94 5.42.27.12.42.07.48-.19.05-.2.29-1.17.4-1.62.03-.14.02-.27-.1-.42-.6-.73-.98-1.74-.98-2.8 0-3.08 2.33-6.05 6.3-6.05 3.43 0 5.83 2.34 5.83 5.69 0 3.79-1.91 6.42-4.4 6.42-1.37 0-2.39-1.13-2.06-2.52.39-1.66 1.15-3.45 1.15-4.65 0-1.07-.58-1.97-1.77-1.97-1.4 0-2.53 1.45-2.53 3.4 0 1.24.42 2.08.42 2.08s-1.39 5.87-1.64 6.96c-.28 1.19-.17 2.85-.05 3.94.09.03.18.06.28.08.67-.92 1.54-2.25 1.9-3.43.19-.64.99-3.85.99-3.85.52.99 2.03 1.82 3.64 1.82 4.79 0 8.25-4.4 8.25-9.86C22 5.43 18.29 2 12.04 2z"></path></svg>' +
					'</a>' +
					'<a class="stc-footer-share-link" href="https://www.linkedin.com/shareArticle?mini=true&url=' + encodedUrl + '&title=' + encodedTitle + '" target="_blank" rel="noopener noreferrer" aria-label="Share on LinkedIn" title="Share on LinkedIn">' +
						'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4.98 3.5C4.98 4.88 3.86 6 2.5 6S0 4.88 0 3.5 1.12 1 2.5 1s2.48 1.12 2.48 2.5zM.35 8h4.3v14h-4.3V8zM8.1 8h4.12v1.91h.06c.57-1.08 1.98-2.22 4.07-2.22 4.35 0 5.15 2.86 5.15 6.58V22h-4.3v-6.84c0-1.63-.03-3.72-2.27-3.72-2.27 0-2.62 1.77-2.62 3.6V22H8.1V8z"></path></svg>' +
					'</a>';

				var footer = document.querySelector('footer, .site-footer, #footer, .footer-area, .footer-wrapper');
				if (footer) {
					footer.appendChild(row);
				} else {
					document.body.appendChild(row);
				}
			});
		</script>
		<?php
	}
}
add_action( 'wp_footer', 'stc_fixed_footer_social_share_row', 9999 );

/* Nebula Ocean production enhancements */
require_once get_template_directory() . '/inc/nebula-ocean/enhancements.php';
