<?php
/**
 * Child theme functions
 *
 * When using a child theme (see http://codex.wordpress.org/Theme_Development
 * and http://codex.wordpress.org/Child_Themes), you can override certain
 * functions (those wrapped in a function_exists() call) by defining them first
 * in your child theme's functions.php file. The child theme's functions.php
 * file is included before the parent theme's file, so the child theme
 * functions would be used.
 *
 * Text Domain: wpex
 * @link http://codex.wordpress.org/Plugin_API
 *
 */

//define('THEMEVERSION', '1.0');
define('THEMEVERSION', time());
define('THEMEPATH', get_stylesheet_directory());
define('THEMEURL', get_stylesheet_directory_uri());

$files = [
    '/config/acf.php',
//    '/config/cf7.php',
    '/config/templates.php',
    '/config/gutenberg.php',
    '/config/scripts.php',
    '/config/sidebar.php',
    '/includes/theme_functions.php',
    '/includes/body.php',
    '/includes/archive.php',
    '/includes/footer.php',
    '/includes/header.php',
    '/includes/shortcodes.php',
    '/includes/cpt.php',
    '/customizer/topbar.php',
//    '/customizer/footer.php',
];

foreach ($files as $file) {
    if(!$filepath = THEMEPATH.$file) {
        trigger_error( sprintf( __('Error locating %s for inclusion'), $file ), E_USER_ERROR );
    }

    require_once($filepath);
    unset($file, $filepath);
}

remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );

add_filter( 'wpex_metaboxes', '__return_false' );
add_filter( 'wpex_gallery_metabox_post_types', '__return_false' );


//Gravity Form - avoid jump between form when using multiple forms on single page
add_filter( 'gform_tabindex_5', '__return_false' );

add_action('wp_head', function(){
	echo "
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-K3HZLN5');</script>
<!-- End Google Tag Manager -->
";
});
add_action('wp_body_open', function(){
	echo '
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-K3HZLN5"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
';
});