????

Your IP : 18.119.110.76


Current Path : /home2/morganrand/backup.morganrand.com/wp-content/themes/wanderfuls/
Upload File :
Current File : /home2/morganrand/backup.morganrand.com/wp-content/themes/wanderfuls/functions.php

<?php

/**

 * This is where the magic happens.

 *

 * IMPORTANT: DO NOT EVER EDIT THIS FILE !!!!

 * IMPORTANT: DO NOT EVER COPY AND PASTE ANYTHING FROM HERE TO YOUR CHILD THEME !!!

 *

 * Wanderfuls is a very powerful theme and virtually anything can be customized

 * via a child theme. If you need any help altering a function, just let us know!

 * Customizations aren't included for free but if it's a simple task I'll be sure to help :)

 *

 * Theme Docs: http://tbplorer-themes.com/total/docs/

 *

 * @package Wanderfuls WordPress Theme

 * @subpackage Templates

 */
class TB_Theme_Setup {

    private $template_dir;

    /**

     * Main Theme Class Constructor

     *

     * Loads all necessary classes, functions, hooks, configuration files and actions for the theme.

     * Everything starts here.

     *

     * @since 1.6.0

     *

     */
    public function __construct() {



        $this->template_dir = get_template_directory();



        // Define globals

        global $tb_theme, $tb_theme_mods, $tb_admin_help_tabs;



        // Load global object file first so it can be used anywhere needed - this is important
        // because when inserting VC modules we must re-run the class object at times

        require_once( $this->template_dir . '/framework/classes/global-object.php' );



        // Add admin help tabs?

        $tb_admin_help_tabs = apply_filters('tb_admin_help_tabs', true);



        // Gets all theme mods and stores them in an easily accessable var

        $tb_theme_mods = get_theme_mods();



        // Functions used to retrieve theme mods - must be loaded early so it can be used on all hooks.

        require_once( $this->template_dir . '/framework/get_mods.php' );



        // Populate the global object
        // Must be done after all core functions are registered and after the WP object is set up so ID exists
        // Priority of 20 is important so we can use filters at default priority via other classes

        add_action('template_redirect', array($this, 'global_object'), 20);



        // Defines hooks and runs actions

        add_action('init', array($this, 'actions'), 0);



        // Define constants

        add_action('after_setup_theme', array($this, 'constants'), 1);



        // Load all the theme addons - must run on this hook!

        add_action('after_setup_theme', array($this, 'addons'), 2);



        // Load configuration classes (post types & 3rd party plugins)
        // Must load first so it can use hooks defined in the classes

        add_action('after_setup_theme', array($this, 'configs'), 3);



        // Load all core theme function files

        add_action('after_setup_theme', array($this, 'include_functions'), 4);



        // Load framework classes

        add_action('after_setup_theme', array($this, 'classes'), 5);



        // Load custom widgets

        add_action('after_setup_theme', array($this, 'custom_widgets'), 5);



        // Actions & filters

        add_action('after_setup_theme', array($this, 'add_theme_support'));



        // Run after switch theme

        add_action('after_switch_theme', array($this, 'after_switch_theme'));



        // Load scripts in the WP admin

        add_action('admin_enqueue_scripts', array($this, 'admin_scripts'));



        // Load theme CSS

        add_action('wp_enqueue_scripts', array($this, 'theme_css'));



        // Load responsive CSS - must be added last

        add_action('wp_enqueue_scripts', array($this, 'responsive_css'), 99);



        // Load theme js

        add_action('wp_enqueue_scripts', array($this, 'theme_js'));



        // Add meta viewport tag to header

        add_action('wp_head', array($this, 'meta_viewport'), 1);



        // Add an X-UA-Compatible header

        add_filter('wp_headers', array($this, 'x_ua_compatible_headers'));



        // Browser dependent CSS

        add_action('wp_head', array($this, 'browser_dependent_css'));



        // Loads html5 shiv script

        add_action('wp_head', array($this, 'html5_shiv'));



        // Outputs custom CSS to the head

        add_action('wp_head', array($this, 'custom_css'), 9999);



        // Outputs custom CSS for the admin

        add_action('admin_head', array($this, 'admin_inline_css'));



        // register sidebar widget areas

        add_action('widgets_init', array($this, 'register_sidebars'));



        // Add gallery metabox to portfolio

        add_filter('tb_gallery_metabox_post_types', array($this, 'add_gallery_metabox'), 10);



        // Define the directory URI for the gallery metabox calss

        add_filter('tb_gallery_metabox_dir_uri', array($this, 'gallery_metabox_dir_uri'));



        // Alter tagcloud widget to display all tags with 1em font size

        add_filter('widget_tag_cloud_args', array($this, 'widget_tag_cloud_args'));



        // Alter WP categories widget to display count inside a span

        add_filter('wp_list_categories', array($this, 'wp_list_categories_args'));



        // Exclude categories from the blog page

        add_filter('pre_get_posts', array($this, 'pre_get_posts'));



        // Add new social profile fields to the user dashboard

        add_filter('user_contactmethods', array($this, 'add_user_social_fields'));



        // Add a responsive wrapper to the WordPress oembed output

        add_filter('embed_oembed_html', array($this, 'add_responsive_wrap_to_oembeds'), 99, 4);



        // Allow for the use of shortcodes in the WordPress excerpt

        add_filter('the_excerpt', 'shortcode_unautop');

        add_filter('the_excerpt', 'do_shortcode');



        // Make sure the wp_get_attachment_url() function returns correct page request (HTTP or HTTPS)

        add_filter('wp_get_attachment_url', array($this, 'honor_ssl_for_attachments'));



        // Tweak the default password protection output form

        add_filter('the_password_form', array($this, 'custom_password_protected_form'));



        // Exclude posts with custom links from the next and previous post links

        add_filter('get_previous_post_join', array($this, 'prev_next_join'));

        add_filter('get_next_post_join', array($this, 'prev_next_join'));

        add_filter('get_previous_post_where', array($this, 'prev_next_where'));

        add_filter('get_next_post_where', array($this, 'prev_next_where'));



        // Redirect posts with custom links

        add_filter('template_redirect', array($this, 'redirect_custom_links'));



        // Remove tb_term_data when a term is removed

        add_action('delete_term', array($this, 'delete_term'), 5);



        // Remove emoji scripts

        if (tb_get_mod('remove_emoji_scripts_enable', true)) {

            remove_action('wp_head', 'print_emoji_detection_script', 7);

            remove_action('admin_print_scripts', 'print_emoji_detection_script');

            remove_action('wp_print_styles', 'print_emoji_styles');

            remove_action('admin_print_styles', 'print_emoji_styles');
        }



        // Adds classes the post class

        add_filter('post_class', array($this, 'post_class'));



        // Add schema markup to the authors post link

        add_filter('the_author_posts_link', array($this, 'the_author_posts_link'));
    }

// End constructor

    /**

     * Defines the constants for use within the theme.

     *

     * @since 2.0.0

     */
    public function constants() {



        // Theme version

        define('TB_THEME_VERSION', '1.0.5');



        // Visual Composer supported version

        define('TB_VC_SUPPORTED_VERSION', '4.11.2');



        // Define branding constant based on theme options

        define('TB_THEME_BRANDING', tb_get_mod('theme_branding', 'Wanderfuls'));



        // Theme Panel slug

        define('TB_THEME_PANEL_SLUG', 'tb-panel');

        define('TB_ADMIN_PANEL_HOOK_PREFIX', 'theme-panel_page_' . TB_THEME_PANEL_SLUG);



        // Paths to the parent theme directory

        define('TB_THEME_DIR', $this->template_dir);

        define('TB_THEME_URI', get_template_directory_uri());



        // Javascript and CSS Paths

        define('TB_JS_DIR_URI', TB_THEME_URI . '/js/');

        define('TB_CSS_DIR_URI', TB_THEME_URI . '/css/');



        // Framework Paths

        define('TB_FRAMEWORK_DIR', TB_THEME_DIR . '/framework/');

        define('TB_FRAMEWORK_DIR_URI', TB_THEME_URI . '/framework/');

        define('TB_ClASSES', TB_FRAMEWORK_DIR . '/classes/');



        // Classes directory

        define('TB_ClASSES_DIR', TB_FRAMEWORK_DIR . '/classes/');



        // Check if plugins are active

        define('TB_VC_ACTIVE', class_exists('Vc_Manager'));

        define('TB_BBPRESS_ACTIVE', class_exists('bbPress'));

        define('TB_WOOCOMMERCE_ACTIVE', class_exists('WooCommerce'));

        define('TB_REV_SLIDER_ACTIVE', class_exists('RevSlider'));

        define('TB_LAYERSLIDER_ACTIVE', function_exists('lsSliders'));

        define('TB_WPML_ACTIVE', class_exists('SitePress'));

        define('TB_TRIBE_EVENTS_CALENDAR_ACTIVE', class_exists('Tribe__Events__Main'));



        // Active post types

        define('TB_PORTFOLIO_IS_ACTIVE', tb_get_mod('portfolio_enable', true));

        define('TB_STAFF_IS_ACTIVE', tb_get_mod('staff_enable', true));

        define('TB_TESTIMONIALS_IS_ACTIVE', tb_get_mod('testimonials_enable', true));



        // Visual Composer

        define('TB_VCEX_DIR', TB_FRAMEWORK_DIR . 'visual-composer/');

        define('TB_VCEX_DIR_URI', TB_FRAMEWORK_DIR_URI . 'visual-composer/');
    }

    /**

     * Defines all theme hooks and runs all needed actions for theme hooks.

     *

     * @since 2.0.0

     */
    public static function actions() {



        $dir = TB_FRAMEWORK_DIR;



        // Perform actions after updating

        require_once( $dir . 'updates/after-update.php' );



        // Register hooks (needed in admin for Custom Actions panel)

        require_once( $dir . 'hooks/hooks.php' );



        // Front-end stuff

        if (!is_admin()) {

            require_once( $dir . 'hooks/actions.php' );

            require_once( $dir . 'hooks/partials.php' );
        }
    }

    /**

     * Theme addons

     *

     * @since 2.0.0

     */
    public static function addons() {

        require_once( TB_FRAMEWORK_DIR . 'addons/theme-panel.php' );
    }

    /**

     * Configs for post types and 3rd party plugins.

     *

     * @since 2.0.0

     */
    public function configs() {



        $dir = TB_FRAMEWORK_DIR;



        // Portfolio

        if (TB_PORTFOLIO_IS_ACTIVE) {

            require_once( $dir . 'portfolio/portfolio-config.php' );
        }



        // Staff

        if (TB_STAFF_IS_ACTIVE) {

            require_once( $dir . 'staff/staff-config.php' );
        }



        // Testimonias

        if (TB_TESTIMONIALS_IS_ACTIVE) {

            require_once( $dir . 'testimonials/testimonials-config.php' );
        }



        // WooCommerce

        if (TB_WOOCOMMERCE_ACTIVE) {

            require_once( $dir . 'woocommerce/woocommerce-config.php' );
        }



        // Visual Composer

        if (TB_VC_ACTIVE) {

            require_once( $dir . 'visual-composer/vc-config.php' );
        }



        // The Events Calendar

        if (TB_TRIBE_EVENTS_CALENDAR_ACTIVE) {

            require_once( $dir . 'config/tribe-events.php' );
        }



        // Revolution slider

        if (TB_REV_SLIDER_ACTIVE) {

            require_once( $dir . 'config/revslider.php' );
        }



        // WPML

        if (TB_WPML_ACTIVE) {

            require_once( $dir . 'config/wpml.php' );
        }



        // Polylang

        if (class_exists('Polylang')) {

            require_once( $dir . 'config/polylang.php' );
        }



        // bbPress

        if (TB_BBPRESS_ACTIVE) {

            require_once( $dir . 'config/bbpress.php' );
        }



        // Sensei

        if (function_exists('Sensei')) {

            require_once( $dir . 'config/sensei.php' );
        }
    }

    /**

     * Framework functions

     *

     * @since 2.0.0

     */
    public function include_functions() {

        $dir = TB_FRAMEWORK_DIR;

        require_once( $dir . 'deprecated.php' );

        require_once( $dir . 'core.php' );

        require_once( $dir . 'conditionals.php' );

        require_once( $dir . 'body-classes.php' );

        require_once( $dir . 'arrays.php' );

        require_once( $dir . 'fonts.php' );

        require_once( $dir . 'shortcodes/shortcodes.php' );

        require_once( $dir . 'overlays.php' );

        require_once( $dir . 'togglebar.php' );

        require_once( $dir . 'topbar.php' );

        require_once( $dir . 'header-functions.php' );

        require_once( $dir . 'search-functions.php' );

        require_once( $dir . 'title.php' );

        require_once( $dir . 'page-header.php' );

        require_once( $dir . 'menu-functions.php' );

        require_once( $dir . 'excerpts.php' );

        require_once( $dir . 'comments-callback.php' );

        require_once( $dir . 'social-share.php' );

        require_once( $dir . 'blog-functions.php' );

        require_once( $dir . 'pagination.php' );

        require_once( $dir . 'tinymce.php' );

        if (tb_get_mod('blog_dash_thumbs', true)) {

            require_once( $dir . 'thumbnails/dashboard-thumbnails.php' );
        }
    }

    /**

     * Framework Classes

     *

     * @since 2.0.0

     */
    public function classes() {



        // Classes Dir

        $dir = TB_ClASSES_DIR;



        // Sanitize input

        require_once( $dir . 'sanitize-data.php' );



        // iLightbox

        require_once( $dir . 'ilightbox.php' );



        // Image Resize

        require_once( $dir . 'image-resize.php' );



        // Gallery metabox

        require_once( $dir . 'gallery-metabox/gallery-metabox.php' );



        // Term colors - coming soon!
        //require_once( $dir .'term-colors.php' );
        // Post Series

        if (tb_get_mod('post_series_enable', true)) {

            require_once( $dir . 'post-series.php' );
        }



        // Custom WP header

        if (tb_get_mod('header_image_enable')) {

            require_once( $dir . 'custom-header.php' );
        }



        // Auto updates

        require_once( $dir . 'wp-updates-theme.php' );



        // Recommend plugins

        if (tb_get_mod('recommend_plugins_enable', true)) {

            require_once( $dir . 'class-tgm-plugin-activation.php' );

            require_once( TB_FRAMEWORK_DIR . 'config/tgm-plugin-activation.php' );
        }



        // Term thumbnails

        if (tb_get_mod('term_thumbnails_enable', true)) {

            require_once( $dir . 'tax-thumbnails.php' );
        }



        // Remove post type slugs

        if (tb_get_mod('remove_posttype_slugs')) {

            require_once( $dir . 'remove-post-type-slugs.php' );
        }



        // Image sizes panel

        if (tb_get_mod('image_sizes_enable', true)) {

            require_once( $dir . 'image-sizes.php' );
        }



        // Admin only classes

        if (is_admin()) {



            // Category meta

            require_once( $dir . 'category-meta.php' );



            // Metabox - custom fields

            require_once( $dir . 'metabox.php' );



            // Custom attachment fields

            require_once( $dir . 'attachment-fields.php' );
        }



        // Front-end classes
        else {



            // Accent color

            require_once( $dir . 'accent-color.php' );



            // Site layouts

            require_once( $dir . 'site-layouts.php' );



            // Site backgrounds

            require_once( $dir . 'site-backgrounds.php' );



            // Advanced styling

            require_once( $dir . 'advanced-styling.php' );



            // Breadcrumbs class

            require_once( $dir . 'breadcrumbs.php' );
        }



        // Customizer must load last to take advantage of all functions before it

        require_once( TB_FRAMEWORK_DIR . 'customizer/customizer.php' );
    }

    /**

     * Include all custom widget classes

     *

     * @since 2.0.0

     */
    public static function custom_widgets() {



        // Define array of custom widgets for the theme

        $widgets = apply_filters('tb_custom_widgets', array(
            'social-fontawesome',
            'social',
            'simple-menu',
            'modern-menu',
            'flickr',
            'video',
            'posts-thumbnails',
            'posts-grid',
            'posts-icons',
            'comments-avatar',
        ));



        // Loop through widgets and load their files

        $dir = TB_ClASSES_DIR;

        foreach ($widgets as $widget) {

            require_once( $dir . 'widgets/' . $widget . '.php' );
        }
    }

    /**

     * Populate the $tb_theme global object.

     *

     * This helps speed things up by calling core functions only once and saving them in memory.

     *

     * @since 2.0.0

     */
    public static function global_object() {



        // Get global object

        global $tb_theme;



        // Run global object class and update global var

        $tb_theme = new TB_Global_Theme_Object();



        // Apply filters to object var for advanced tweaking

        $tb_theme = apply_filters('tb_global_theme_object', $tb_theme);
    }

    /**

     * Adds basic theme support functions and registers the nav menus

     *

     * @since 1.6.0

     */
    public static function add_theme_support() {



        // Get globals

        global $content_width;



        // Set content width based on theme's default design

        if (!isset($content_width)) {

            $content_width = 980;
        }



        // Menus

        $menus = array(
            'topbar_menu' => __('Top Bar', 'tb'),
            'main_menu' => __('Main', 'tb'),
            'mobile_menu_alt' => __('Mobile Menu Alternative', 'tb'),
            'footer_menu' => __('Footer', 'tb'),
        );



        // Add mobile icons menu nav

        if (in_array(tb_get_mod('mobile_menu_toggle_style', 'icon_buttons'), array('icon_buttons', 'icon_buttons_under_logo'))) {

            $menus['mobile_menu'] = __('Mobile Icons', 'tb');
        }



        // Register navigation menus

        register_nav_menus($menus);

        function print_filters_for($hook = '') {
            global $wp_filter;
            if (empty($hook) || !isset($wp_filter[$hook]))
                return;

            print '<pre>';
            print_r($wp_filter[$hook]);
            print '</pre>';
        }

        function footer_function_list_fn($atts) {
            ob_start();

            print_filters_for('wp_footer');

            return ob_get_clean();
        }

        add_shortcode('footer_function_list', 'footer_function_list_fn');

        function desktop_testimonial_function($atts) {

            ob_start();

            $test_query = new WP_Query(array(
                'post_type' => 'reviews',
                'posts_per_page' => 3,
            ));
            ?>

            <?php if ($test_query->have_posts()) : ?>

                <div class="row">

                    <?php while ($test_query->have_posts()) : $test_query->the_post(); ?>

                        <div class="col-md-4">

                            <div style="position: relative;padding-bottom: 70px;margin-left: -10px;margin-right: -10px;" class="des-testimonial-item">

                                <h1 style="text-align: center">"<?php the_title(); ?>"</h1>

                                <hr>

                                <?php the_content(); ?>



                                <div style="position: absolute;right:15px;bottom:30px;" class="reviewer-details">

                                    <p style="text-align: right;font-size:18px"><strong>– <?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_name', true)); ?></strong><br><?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_city', true)); ?></p>			

                                </div>

                            </div>

                        </div>

                    <?php endwhile; ?>

                </div>

            <?php endif; ?>

            <?php
            return ob_get_clean();
        }

        add_shortcode('des_testimonial', 'desktop_testimonial_function');

        function lucy_orange_scripts() {
            ?>

            <script type='text/javascript'>

                window.__lo_site_id = 61520;



                (function () {

                    var wa = document.createElement('script');
                    wa.type = 'text/javascript';
                    wa.async = true;

                    wa.src = 'https://d10lpsik1i8c69.cloudfront.net/w.js';

                    var s = document.getElementsByTagName('script')[0];
                    s.parentNode.insertBefore(wa, s);

                })();

            </script>



            <?php
        }

        add_action('wp_head', 'lucy_orange_scripts');

        function facebook_scripts() {
            ?>

            <script>
                window.fbAsyncInit = function () {
                    FB.init({
                        appId: '104046656996943',
                        cookie: true,
                        xfbml: true,
                        version: 'v2.8'
                    });
                    FB.AppEvents.logPageView();
                };

                (function (d, s, id) {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (d.getElementById(id)) {
                        return;
                    }
                    js = d.createElement(s);
                    js.id = id;
                    js.src = "//connect.facebook.net/en_US/sdk.js";
                    fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));
            </script>



            <?php
        }

        add_action('wp_head', 'facebook_scripts');

        function color_mobile_menu_style() {
            ?>

            <style>
                .prodcuts_menu_1{
                    display: <?php echo is_wfm_products_1() == 1 ? 'block' : 'none'; ?>;
                }

                .prodcuts_menu_2{
                    display: <?php echo is_wfm_products_2() == 1 ? 'block' : 'none'; ?>;
                }

                .prodcuts_menu_3{
                    display: <?php echo is_wfm_products_3() == 1 ? 'block' : 'none'; ?>;
                }

                .discounts_menu_1{
                    display: <?php echo is_wfm_discounts_1() == 1 ? 'block' : 'none'; ?>;
                }

                .discounts_menu_2{
                    display: <?php echo is_wfm_discounts_2() == 1 ? 'block' : 'none'; ?>;
                }
            </style>

            <?php
        }

        add_action('wp_head', 'color_mobile_menu_style');

        function favor_big_animation_function($atts) {
            ob_start();
            ?>
            <div id="favorbig" class="fbig">
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer15.png"/>      
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer02.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer03.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer04.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer05.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer06.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer07.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer08.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer09.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer10.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer12.png"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fbig/small_10_pink_pompoms_dissolveLayer13.png"/>    
            </div>
            <?php
            return ob_get_clean();
        }

        add_shortcode('favor_big_animation', 'favor_big_animation_function');

        function favor6_animation_function($atts) {
            ob_start();
            ?>
            <!-- Favor 6 -->  
            <div id="favor6" class="fv6">
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer7.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer1.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer2.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer3.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer4.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer5.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv6/small_06_pink_pompoms_dissolvelayer6.jpg"/> 
            </div>
            <?php
            return ob_get_clean();
        }

        add_shortcode('favor6_animation', 'favor6_animation_function');

        function facebook_shortcode_fn($atts) {
            ob_start();

            echo get_scp_widget();

            return ob_get_clean();
        }

        add_shortcode('facebook_c_shortcode', 'facebook_shortcode_fn');

        function favor8_animation_function($atts) {
            ob_start();
            ?>
            <!-- Favor 8 --> 
            <div id="favor8" class="fv8">
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer9.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer1.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer2.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer3.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer4.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer5.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer6.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer7.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv8/small_08_pink_pompoms_dissolvelayer8.jpg"/>            
            </div>	
            <?php
            return ob_get_clean();
        }

        add_shortcode('favor8_animation', 'favor8_animation_function');

        function favor9_animation_function($atts) {
            ob_start();
            ?>
            <!-- Favor 9 --> 
            <div id="favor9" class="fv9">
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer10.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer1.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer2.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer3.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer4.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer5.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer6.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer7.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer8.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv9/small_09_pink_pompoms_dissolvelayer9.jpg"/> 
            </div>	
            <?php
            return ob_get_clean();
        }

        add_shortcode('favor9_animation', 'favor9_animation_function');

        function favor10_animation_function($atts) {
            ob_start();
            ?>
            <!-- Favor 10 --> 
            <div id="favor10" class="fv10">
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer12.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer03.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer05.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer06.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer07.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer08.jpg"/> 
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer09.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer10.jpg"/>
                <img src="<?php echo get_template_directory_uri(); ?>/images/fv10/small_10_pink_pompoms_dissolvelayer11.jpg"/> 
            </div>
            <?php
            return ob_get_clean();
        }

        add_shortcode('favor10_animation', 'favor10_animation_function');

        function faq_item_function_shortcode($atts) {
            ob_start();
            ?>

            <div class="vc_row wpb_row vc_inner vc_row-fluid vc_custom_1499668453659">
                <div class="wpb_column vc_column_container vc_col-sm-4 vc_custom_1499688435760"  style="margin-bottom: -30px !important;">
                    <div class="wpb_wrapper tb-vc-column-wrapper tb-clr">
                        <?php
                        $first_col_query = new WP_Query(array(
                            'post_type' => 'faqs',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                array(
                                    'key' => 'wf_faq_coloumn',
                                    'value' => '1st_coloumn'
                                ),
                            ),
                        ));
                        ?>

                        <?php while ($first_col_query->have_posts()) : $first_col_query->the_post(); ?>
                            <div class="vc_toggle vc_toggle_default vc_toggle_color_default  vc_toggle_size_md   faq-item">
                                <div class="vc_toggle_title"><h4><?php the_title(); ?></h4><i class="vc_toggle_icon"></i></div>
                                <div class="vc_toggle_content" style="overflow: hidden; display: none;"><?php the_content(); ?></div>
                            </div>
                        <?php endwhile; ?>
                    </div>
                </div>
                <div class="wpb_column vc_column_container vc_col-sm-4 vc_custom_1499688463598" style="margin-bottom: -30px !important;">
                    <div class="wpb_wrapper tb-vc-column-wrapper tb-clr">

                        <?php
                        $second_coloumn_query = new WP_Query(array(
                            'post_type' => 'faqs',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                array(
                                    'key' => 'wf_faq_coloumn',
                                    'value' => '2nd_coloumn'
                                ),
                            ),
                        ));
                        ?>
                        <?php while ($second_coloumn_query->have_posts()) : $second_coloumn_query->the_post(); ?>
                            <div class="vc_toggle vc_toggle_default vc_toggle_color_default  vc_toggle_size_md   faq-item">
                                <div class="vc_toggle_title"><h4><?php the_title(); ?></h4><i class="vc_toggle_icon"></i></div>
                                <div class="vc_toggle_content" style="overflow: hidden; display: none;"><?php the_content(); ?></div>
                            </div>
                        <?php endwhile; ?>

                    </div>
                </div>	

                <div class="wpb_column vc_column_container vc_col-sm-4 vc_custom_1499688456830"  style="margin-bottom: -30px !important;">
                    <div class="wpb_wrapper tb-vc-column-wrapper tb-clr">

                        <?php
                        $third_coloumn_query = new WP_Query(array(
                            'post_type' => 'faqs',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                array(
                                    'key' => 'wf_faq_coloumn',
                                    'value' => '3rd_coloumn'
                                ),
                            ),
                        ));
                        ?>
                        <?php while ($third_coloumn_query->have_posts()) : $third_coloumn_query->the_post(); ?>
                            <div class="vc_toggle vc_toggle_default vc_toggle_color_default  vc_toggle_size_md   faq-item">
                                <div class="vc_toggle_title"><h4><?php the_title(); ?></h4><i class="vc_toggle_icon"></i></div>
                                <div class="vc_toggle_content" style="overflow: hidden; display: none;"><?php the_content(); ?></div>
                            </div>
                        <?php endwhile; ?>

                    </div>
                </div>	


            </div>

            <?php
            return ob_get_clean();
        }

        add_shortcode('faqs_item', 'faq_item_function_shortcode');

        function desktop_testimonial_function2($atts) {

            ob_start();

            $test_query = new WP_Query(array(
                'post_type' => 'reviews',
                'posts_per_page' => 9,
            ));
            ?>

            <?php if ($test_query->have_posts()) : ?>

                <div class="row">

                    <?php while ($test_query->have_posts()) : $test_query->the_post(); ?>

                        <div class="col-md-4">

                            <div style="position: relative;padding-bottom: 70px;margin-left: -10px;margin-right: -10px;" class="des-testimonial-item">

                                <h1 style="text-align: center">"<?php the_title(); ?>"</h1>

                                <hr>

                                <?php the_content(); ?>



                                <div style="position: absolute;right:15px;bottom:30px;" class="reviewer-details">

                                    <p style="text-align: right;font-size:18px"><strong>– <?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_name', true)); ?></strong><br><?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_city', true)); ?></p>			

                                </div>

                            </div>

                        </div>

                    <?php endwhile; ?>

                </div>

            <?php endif; ?>

            <?php
            return ob_get_clean();
        }

        add_shortcode('des_testimonial2', 'desktop_testimonial_function2');

        function mobile_testimonial_function($atts) {

            ob_start();

            $test_query = new WP_Query(array(
                'post_type' => 'reviews',
                'posts_per_page' => 9,
            ));
            ?>

            <?php if ($test_query->have_posts()) : ?>

                <div class="row">

                    <div class="col-md-12">

                        <div  class="owl-carousel default testimonial-slider">

                            <?php while ($test_query->have_posts()) : $test_query->the_post(); ?>



                                <div class="mob-testimonial-item">

                                    <h1 style="text-align: center">"<?php the_title(); ?>"</h1>

                                    <hr>

                                    <?php the_content(); ?>



                                    <div class="reviewer-details">

                                        <p style="text-align: right;font-size:18px"><strong>– <?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_name', true)); ?></strong><br><?php echo esc_attr(get_post_meta(get_the_ID(), 'rv_city', true)); ?></p>			

                                    </div>

                                </div>



                            <?php endwhile; ?>

                        </div>

                    </div>

                </div>

            <?php endif; ?>

            <?php
            return ob_get_clean();
        }

        add_shortcode('mob_testimonial', 'mobile_testimonial_function');




        add_action('init', 'post_reviews_init');

        function my_password_form() {
            global $post;
            $label = 'pwbox-' . ( empty($post->ID) ? rand() : $post->ID );

            ob_start();
            ?>

            <div class="password-protection-box clr">
                <form action="<?php echo esc_url(site_url('wp-login.php?action=postpass', 'login_post')); ?>" method="post">
                    <h2>Password Protected</h2>
                    <p>This content is password protected. To view it please enter your password below:</p>
                    <p>		<input name="post_password" id="<?php echo $label; ?>" size="20" maxlength="20" placeholder="Password" type="password"><input name="Submit" value="Enter" type="submit"><a class="color-page-link" href="/colors.html">Go to COLORS</a><br>
                    </p></form>
            </div>

            <?php
            return ob_get_clean();
        }

        add_filter('the_password_form', 'my_password_form');



        /* Page switcher */


        add_action('admin_menu', 'wf_add_admin_menu');
        add_action('admin_init', 'wf_settings_init');

        function wf_add_admin_menu() {

            add_menu_page('Wonderfuls Page Switch', 'Wonderfuls Page Switch', 'manage_options', 'wonderfuls_page_switch', 'wf_options_page');
        }

        function wf_settings_init() {

            register_setting('pluginPage', 'wf_settings');

            add_settings_section(
                    'wf_pluginPage_section', __('', 'wonderfuls'), 'wf_settings_section_callback', 'pluginPage'
            );

            add_settings_field(
                    'wf_select_field_0', __('Products or Discounts Page', 'wonderfuls'), 'wf_select_field_0_render', 'pluginPage', 'wf_pluginPage_section'
            );

            add_settings_field(
                    'wf_select_field_1', __('Choose Products Version', 'wonderfuls'), 'wf_select_field_1_render', 'pluginPage', 'wf_pluginPage_section'
            );

            add_settings_field(
                    'wf_select_field_2', __('Choose Discounts Version', 'wonderfuls'), 'wf_select_field_2_render', 'pluginPage', 'wf_pluginPage_section'
            );
        }

        function wf_select_field_0_render() {

            $options = get_option('wf_settings');
            ?>
            <select id="select_1" name='wf_settings[wf_select_field_0]'>
                <option value='products' <?php selected($options['wf_select_field_0'], 'products'); ?>>Products</option>
                <option value='discounts' <?php selected($options['wf_select_field_0'], 'discounts'); ?>>Discounts</option>
            </select>

            <?php
        }

        function wf_select_field_1_render() {

            $options = get_option('wf_settings');
            ?>
            <select  id="select_2"  name='wf_settings[wf_select_field_1]'>
                <option value='products1' <?php selected($options['wf_select_field_1'], 'products1'); ?>>Products A</option>
                <option value='products2' <?php selected($options['wf_select_field_1'], 'products2'); ?>>Products B</option>
                <option value='products3' <?php selected($options['wf_select_field_1'], 'products3'); ?>>Products C</option>
            </select>

            <?php
        }

        function wf_select_field_2_render() {

            $options = get_option('wf_settings');
            ?>
            <select id="select_3" name='wf_settings[wf_select_field_2]'>
                <option value='discounts1' <?php selected($options['wf_select_field_2'], 'discounts1'); ?>>Discounts A</option>
                <option value='discounts2' <?php selected($options['wf_select_field_2'], 'discounts2'); ?>>Discounts B</option>
            </select>

            <?php
        }

        function wf_settings_section_callback() {

            echo __('', 'wonderfuls');
        }

        function wf_options_page() {
            ?>
            <form class="page_switch" action='options.php' method='post'>

                <h2>Wonderfuls Page Switcher</h2>

                <?php
                settings_fields('pluginPage');
                do_settings_sections('pluginPage');
                ?>
                <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"  />
                <button type="reset" id="reset" class="button">Reset</button>

            </form>
            <?php
        }

        add_action('admin_footer', 'page_switch_enqueue');

        function page_switch_enqueue() {
            ?>
            <script>





                jQuery(document).ready(function ($) {



                    $('#reset').click(function () {

                        $('#select_1 option').attr('selected', false);
                        $('#select_2 option').attr('selected', false);
                        $('#select_3 option').attr('selected', false);
                        $('#select_4 option').attr('selected', false);
                    });


                });

            </script>

            <?php
        }

        function is_wfm_products_1() {
            $options = get_option('wf_settings');

            $val = $options['wf_select_field_0'];
            $val_sub = $options['wf_select_field_1'];

            if ($val == 'products' && $val_sub == 'products1') {
                return true;
            } else {
                return false;
            }
        }

        function is_wfm_products_2() {
            $options = get_option('wf_settings');

            $val = $options['wf_select_field_0'];
            $val_sub = $options['wf_select_field_1'];

            if ($val == 'products' && $val_sub == 'products2') {
                return true;
            } else {
                return false;
            }
        }

        function is_wfm_products_3() {
            $options = get_option('wf_settings');

            $val = $options['wf_select_field_0'];
            $val_sub = $options['wf_select_field_1'];

            if ($val == 'products' && $val_sub == 'products3') {
                return true;
            } else {
                return false;
            }
        }

        function is_wfm_discounts_1() {
            $options = get_option('wf_settings');

            $val = $options['wf_select_field_0'];
            $val_sub = $options['wf_select_field_2'];

            if ($val == 'discounts' && $val_sub == 'discounts1') {
                return true;
            } else {
                return false;
            }
        }

        function is_wfm_discounts_2() {
            $options = get_option('wf_settings');

            $val = $options['wf_select_field_0'];
            $val_sub = $options['wf_select_field_2'];

            if ($val == 'discounts' && $val_sub == 'discounts2') {
                return true;
            } else {
                return false;
            }
        }

        /**

         * Register a book post type.

         *

         * @link http://codex.wordpress.org/Function_Reference/register_post_type

         */
        function post_reviews_init() {

            $labels = array(
                'name' => _x('Reviews', 'post type general name', 'your-plugin-textdomain'),
                'singular_name' => _x('Review', 'post type singular name', 'your-plugin-textdomain'),
                'menu_name' => _x('Reviews', 'admin menu', 'your-plugin-textdomain'),
                'name_admin_bar' => _x('Review', 'add new on admin bar', 'your-plugin-textdomain'),
                'add_new' => _x('Add New', 'Review', 'your-plugin-textdomain'),
                'add_new_item' => __('Add New Review', 'your-plugin-textdomain'),
                'new_item' => __('New Review', 'your-plugin-textdomain'),
                'edit_item' => __('Edit Review', 'your-plugin-textdomain'),
                'view_item' => __('View Review', 'your-plugin-textdomain'),
                'all_items' => __('All Reviews', 'your-plugin-textdomain'),
                'search_items' => __('Search Reviews', 'your-plugin-textdomain'),
                'parent_item_colon' => __('Parent Reviews:', 'your-plugin-textdomain'),
                'not_found' => __('No Reviews found.', 'your-plugin-textdomain'),
                'not_found_in_trash' => __('No Reviews found in Trash.', 'your-plugin-textdomain')
            );



            $args = array(
                'labels' => $labels,
                'description' => __('Description.', 'your-plugin-textdomain'),
                'public' => true,
                'publicly_queryable' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'query_var' => true,
                'rewrite' => array('slug' => 'review'),
                'capability_type' => 'post',
                'has_archive' => true,
                'hierarchical' => false,
                'menu_position' => null,
                'supports' => array('title', 'editor')
            );



            register_post_type('reviews', $args);
        }

        function post_faqs_init() {

            $labels = array(
                'name' => _x('Faqs', 'post type general name', 'your-plugin-textdomain'),
                'singular_name' => _x('Faq', 'post type singular name', 'your-plugin-textdomain'),
                'menu_name' => _x('Faqs', 'admin menu', 'your-plugin-textdomain'),
                'name_admin_bar' => _x('Faq', 'add new on admin bar', 'your-plugin-textdomain'),
                'add_new' => _x('Add New', 'Faq', 'your-plugin-textdomain'),
                'add_new_item' => __('Add New Faq', 'your-plugin-textdomain'),
                'new_item' => __('New Faq', 'your-plugin-textdomain'),
                'edit_item' => __('Edit Faq', 'your-plugin-textdomain'),
                'view_item' => __('View Faq', 'your-plugin-textdomain'),
                'all_items' => __('All Faqs', 'your-plugin-textdomain'),
                'search_items' => __('Search Faqs', 'your-plugin-textdomain'),
                'parent_item_colon' => __('Parent Faqs:', 'your-plugin-textdomain'),
                'not_found' => __('No Faqs found.', 'your-plugin-textdomain'),
                'not_found_in_trash' => __('No Faqs found in Trash.', 'your-plugin-textdomain')
            );



            $args = array(
                'labels' => $labels,
                'description' => __('Description.', 'your-plugin-textdomain'),
                'public' => true,
                'publicly_queryable' => true,
                'show_ui' => true,
                'show_in_menu' => true,
                'query_var' => true,
                'rewrite' => array('slug' => 'faqs'),
                'capability_type' => 'post',
                'has_archive' => true,
                'hierarchical' => false,
                'menu_icon' => 'dashicons-format-chat',
                'menu_position' => null,
                'supports' => array('title', 'editor')
            );



            register_post_type('faqs', $args);
        }

        add_action('init', 'post_faqs_init');

        /*         * * faqs metabox *** */

        function faqs_metabox() {

            add_meta_box(
                    'Faqs Coloumn', __('Faqs', 'nuliterature'), 'faqs_callback_function', 'faqs', 'upper_2', 'high'
            );
        }

        add_action('add_meta_boxes', 'faqs_metabox');

        function faqs_callback_function($post) {



            wp_nonce_field('faqs_metabox_action', 'faqs_metabox_nonce_name');
            ?>

            <div class="inside">
                <?php $wf_faq_coloumn = esc_attr(get_post_meta($post->ID, 'wf_faq_coloumn', true)); ?>

                <p><label for="wf_faq_coloumn">Select Coloumn</label></p>

                <p> <select name="wf_faq_coloumn" id="wf_faq_coloumn" class="widefat">
                        <option <?php echo $wf_faq_coloumn == '1st_coloumn' ? 'selected' : ''; ?> value="1st_coloumn">1st Coloumn</option>
                        <option <?php echo $wf_faq_coloumn == '2nd_coloumn' ? 'selected' : ''; ?> value="2nd_coloumn">2nd Coloumn</option>
                        <option <?php echo $wf_faq_coloumn == '3rd_coloumn' ? 'selected' : ''; ?> value="3rd_coloumn">3rd Coloumn</option>
                    </select>
            </div>



            <?php
        }

        function save_faqs_metabox_data($post_id) {



            if (if_user_can_save_faqs_data($post_id, 'faqs_metabox_nonce_name')) {





                if (isset($_POST['wf_faq_coloumn'])) {

                    $meta_value = stripslashes(strip_tags($_POST['wf_faq_coloumn']));

                    update_post_meta($post_id, 'wf_faq_coloumn', $meta_value);
                }
            }
        }

        add_action('save_post', 'save_faqs_metabox_data');

        function if_user_can_save_faqs_data($post_id, $nonce) {



            // this is not an autosave

            $r_autosave = wp_is_post_autosave($post_id);



            // this is not an Revison

            $r_revision = wp_is_post_revision($post_id);



            //check if the nonce is valid

            $r_is_valid_nonce = isset($_POST[$nonce]) && wp_verify_nonce($_POST[$nonce], 'faqs_metabox_action');



            // return true if the user is able to save data

            return !($r_autosave || $r_revision ) && $r_is_valid_nonce;
        }

        function faq_move_deck() {

            # Get the globals:

            global $post, $wp_meta_boxes;



            # Output the "advanced" meta boxes:

            do_meta_boxes(get_current_screen(), 'upper_2', $post);



            # Remove the initial "advanced" meta boxes:

            unset($wp_meta_boxes['post']['faqs']);
        }

        add_action('edit_form_after_title', 'faq_move_deck');


        /*

         *

         * Meta boxes

         *

         *

         */

        function foo_move_deck() {

            # Get the globals:

            global $post, $wp_meta_boxes;



            # Output the "advanced" meta boxes:

            do_meta_boxes(get_current_screen(), 'upper', $post);



            # Remove the initial "advanced" meta boxes:

            unset($wp_meta_boxes['post']['reviews']);
        }

        add_action('edit_form_after_title', 'foo_move_deck');

        function reviews_metabox() {

            add_meta_box(
                    'Reviews Details', __('Reviews', 'nuliterature'), 'reviews_callback_function', 'reviews', 'upper', 'high'
            );
        }

        add_action('add_meta_boxes', 'reviews_metabox');



        /* === First Year Result Metabox === */

        function reviews_callback_function($post) {



            wp_nonce_field('reviews_metabox_action', 'reviews_metabox_nonce_name');
            ?>

            <div class="inside">

                <p><label for="1st_regno">Reviewer Name</label></p>

                <p><input type="text" name="rv_name" value="<?php echo esc_attr(get_post_meta($post->ID, 'rv_name', true)); ?>" id="rv_name" class="widefat" /></p>



                <p><label for="1st_regno">Reviewer City</label></p>

                <p><input type="text" name="rv_city" value="<?php echo esc_attr(get_post_meta($post->ID, 'rv_city', true)); ?>" id="rv_city" class="widefat" /></p>



            </div>



            <?php
        }

        function save_metabox_data($post_id) {



            if (if_user_can_save_data($post_id, 'reviews_metabox_nonce_name')) {





                if (isset($_POST['rv_name'])) {

                    $meta_value = stripslashes(strip_tags($_POST['rv_name']));

                    update_post_meta($post_id, 'rv_name', $meta_value);
                }



                if (isset($_POST['rv_city'])) {

                    $meta_value = stripslashes(strip_tags($_POST['rv_city']));

                    update_post_meta($post_id, 'rv_city', $meta_value);
                }
            }
        }

        add_action('save_post', 'save_metabox_data');

        function if_user_can_save_data($post_id, $nonce) {



            // this is not an autosave

            $r_autosave = wp_is_post_autosave($post_id);



            // this is not an Revison

            $r_revision = wp_is_post_revision($post_id);



            //check if the nonce is valid

            $r_is_valid_nonce = isset($_POST[$nonce]) && wp_verify_nonce($_POST[$nonce], 'reviews_metabox_action');



            // return true if the user is able to save data

            return !($r_autosave || $r_revision ) && $r_is_valid_nonce;
        }

        // Apply filters for easier editing

        $menus = apply_filters('tb_nav_menus', $menus);





        register_nav_menus(array(
            'sticky_menu' => 'Sticky Menu'
        ));





        // Load text domain

        load_theme_textdomain('tb', TB_THEME_DIR . '/languages');



        // Declare theme support

        add_theme_support('post-formats', array('video', 'gallery', 'audio', 'quote', 'link'));

        add_theme_support('automatic-feed-links');

        add_theme_support('post-thumbnails');

        add_theme_support('html5');

        add_theme_support('woocommerce');

        add_theme_support('title-tag');

        add_theme_support('yoast-seo-breadcrumbs');



        // Enable excerpts for pages.

        add_post_type_support('page', 'excerpt');



        // Add styles to the WP editor

        add_editor_style('css/editor-style.css?ver=5.4');
    }

    /**

     * Functions called after theme switch

     *

     * @since 1.6.0

     */
    public static function after_switch_theme() {

        flush_rewrite_rules();

        delete_metadata('user', null, 'tgmpa_dismissed_notice_tb_theme', null, true);
    }

    /**

     * Adds the meta tag to the site header

     *

     * @since 1.6.0

     */
    public function meta_viewport() {



        // Responsive viewport viewport

        if (tb_global_obj('responsive')) {

            $viewport = '<meta name="viewport" content="width=device-width, initial-scale=1">';
        }



        // Non responsive meta viewport
        else {

            $width = intval(tb_get_mod('main_container_width', '980'));

            $width = $width ? $width : '980';

            $viewport = '<meta name="viewport" content="width=' . $width . '" />';
        }



        // Apply filters to the meta viewport for child theme tweaking

        echo apply_filters('tb_meta_viewport', $viewport);
    }

    /**

     * Load scripts in the WP admin

     *

     * @since 1.6.0

     */
    public function admin_scripts() {

        wp_enqueue_style('tb-font-awesome', TB_CSS_DIR_URI . 'font-awesome.min.css');
    }

    /**

     * Returns all CSS needed for the front-end

     *

     * @since 1.6.0

     */
    public static function theme_css() {



        // Front end only

        if (is_admin()) {

            return;
        }



        // Define dir

        $dir = TB_CSS_DIR_URI;

        $theme_version = TB_THEME_VERSION;



        // Remove other font awesome scripts

        wp_deregister_style('font-awesome');

        wp_deregister_style('fontawesome');



        // Load font awesome script everywhere except the front-end composer because the js_composer already adds it

        wp_enqueue_style('tb-font-awesome', $dir . 'font-awesome.min.css', false, '4.3.0');



        // Register hover-css

        wp_register_style('tb-hover-animations', $dir . 'hover-css.min.css', false, '2.0.1');



        // LayerSlider

        if (TB_LAYERSLIDER_ACTIVE) {

            wp_enqueue_style('tb-layerslider', $dir . 'tb-layerslider.css', false, $theme_version);
        }



        // Main Style.css File

        wp_enqueue_style('tb-style', get_stylesheet_uri(), false, $theme_version);



        // Load RTL.css if enabled

        if (is_RTL()) {

            wp_enqueue_style('tb-rtl', $dir . 'rtl.css', array('tb-style'), false);
        }
    }

    /**

     * Loads responsive css very last after all styles.

     *

     * @since 1.6.0

     */
    public static function responsive_css() {

        if (tb_global_obj('responsive')) {

            wp_enqueue_style('tb-responsive', TB_CSS_DIR_URI . 'tb-responsive.css', false, TB_THEME_VERSION);
        }
    }

    /**

     * Returns all js needed for the front-end

     *

     * @since 1.6.0

     */
    public function theme_js() {



        // Front end only

        if (is_admin()) {

            return;
        }



        // Get js directory uri

        $dir = TB_JS_DIR_URI;



        // Get current theme version

        $theme_version = TB_THEME_VERSION;



        // Get localized array

        $localize_array = $this->localize_array();



        // Make sure the core jQuery script is loaded

        // wp_enqueue_script('jquery');
        wp_deregister_script('jquery');
        wp_register_script( 'jquery', 'https://code.jquery.com/jquery-1.9.1.js');
        wp_enqueue_script('jquery');


        // Retina.js

        if (tb_global_obj('retina')) {

            wp_enqueue_script('retina', $dir . 'retina.js', array('jquery'), '0.0.2', true);
        }



        // Comment reply

        if (is_singular() && comments_open() && get_option('thread_comments')) {

            wp_enqueue_script('comment-reply');
        }



        // Load minified js

        if (tb_get_mod('minify_js_enable', true)) {

            wp_enqueue_script('wanderfuls-min', $dir . 'wanderfuls-min.js', array('jquery'), $theme_version, true);

            wp_localize_script('wanderfuls-min', 'tbLocalize', $localize_array);
        }



        // Load all non-minified js
        else {



            // Superfish used for menu dropdowns

            wp_enqueue_script('tb-superfish', $dir . 'lib/superfish.js', array('jquery'), $theme_version, true);

            wp_enqueue_script('tb-supersubs', $dir . 'lib/supersubs.js', array('jquery'), $theme_version, true);

            wp_enqueue_script('tb-hoverintent', $dir . 'lib/hoverintent.js', array('jquery'), $theme_version, true);



            // Sticky header

            wp_enqueue_script('tb-sticky', $dir . 'lib/sticky.js', array('jquery'), $theme_version, true);



            // Page animations

            wp_enqueue_script('tb-animsition', $dir . 'lib/animsition.js', array('jquery'), $theme_version, true);



            // Tooltips

            wp_enqueue_script('tb-tipsy', $dir . 'lib/tipsy.js', array('jquery'), $theme_version, true);



            // Checks if images are loaded within an element

            wp_enqueue_script('tb-images-loaded', $dir . 'lib/images-loaded.js', array('jquery'), $theme_version, true);



            // Main masonry script

            wp_enqueue_script('tb-isotope', $dir . 'lib/isotope.js', array('jquery'), $theme_version, true);



            // Leaner modal used for search/woo modals: @todo: Replace with CSS+light js

            wp_enqueue_script('tb-leanner-modal', $dir . 'lib/leanner-modal.js', array('jquery'), $theme_version, true);



            // Slider Pro

            wp_enqueue_script('tb-sliderpro', $dir . 'lib/jquery.sliderPro.js', array('jquery'), $theme_version, true);

            wp_enqueue_script('tb-sliderpro-customthumbnails', $dir . 'lib/jquery.sliderProCustomThumbnails.js', array('jquery'), false, true);



            // Touch Swipe - do we need it?

            wp_enqueue_script('tb-touch-swipe', $dir . 'lib/touch-swipe.js', array('jquery'), $theme_version, true);



            // Carousels

            wp_enqueue_script('tb-owl-carousel', $dir . 'lib/owl.carousel.js', array('jquery'), $theme_version, true);



            // Used for milestones

            wp_enqueue_script('tb-count-to', $dir . 'lib/count-to.js', array('jquery'), $theme_version, true);

            wp_enqueue_script('tb-appear', $dir . 'lib/appear.js', array('jquery'), $theme_version, true);



            // Mobile menu

            wp_enqueue_script('tb-sidr', $dir . 'lib/sidr.js', array('jquery'), $theme_version, true);



            // Custom Selects

            wp_enqueue_script('tb-custom-select', $dir . 'lib/jquery.customSelect.js', array('jquery'), $theme_version, true);



            // Equal Heights

            wp_enqueue_script('tb-match-height', $dir . 'lib/jquery.matchHeight.js', array('jquery'), $theme_version, true);



            // Mousewheel

            /* wp_enqueue_script( 'tb-mousewheel', $dir .'lib/jquery.mousewheel.js', array( 'jquery' ), $theme_version, true ); */



            // Parallax bgs

            wp_enqueue_script('tb-scrolly', $dir . 'lib/scrolly.js', array('jquery'), $theme_version, true);



            // iLightbox

            wp_enqueue_script('tb-ilightbox', $dir . 'lib/ilightbox.js', array('jquery'), $theme_version, true);



            // Cycle2

            wp_enqueue_script('tb-cycle2', $dir . 'lib/jquery.cycle2.js', array('jquery'), $theme_version, true);



            // WooCommerce quanity buttons

            if (TB_WOOCOMMERCE_ACTIVE) {

                wp_enqueue_script('wc-quantity-increment', $dir . 'lib/wc-quantity-increment.js', array('jquery'), $theme_version, true);
            }



            // Core global functions

            wp_enqueue_script('tb-functions', $dir . 'functions.js', array('jquery'), $theme_version, true);



            // Core global functions




            wp_enqueue_script('tb-customjs', $dir . 'custom.js', array('jquery'), $theme_version, true);

            // Localize script

            wp_localize_script('tb-functions', 'tbLocalize', $localize_array);
        }
    }

    /**

     * Functions.js localize array

     * IMPORTANT: Must be static so we can get array in VC inline_js class

     *

     * @since 3.0.0

     */
    public static function localize_array() {



        // Get theme options

        $header_style = tb_global_obj('header_style');

        $sticky_header = tb_global_obj('has_fixed_header');

        $sticky_header = tb_global_obj('has_fixed_header');

        $mobile_menu_style = tb_global_obj('mobile_menu_style');



        // Create array

        $array = array(
            'isRTL' => is_rtl(),
            'mainLayout' => tb_global_obj('main_layout'),
            'mobileMenuStyle' => tb_global_obj('mobile_menu_style'),
            'menuSearchStyle' => tb_global_obj('menu_search_style'),
            'hasStickyHeader' => $sticky_header,
            'siteHeaderStyle' => $header_style,
            'superfishDelay' => 600,
            'superfishSpeed' => 'fast',
            'superfishSpeedOut' => 'fast',
            'localScrollUpdateHash' => false,
            'localScrollSpeed' => 800,
            'windowScrollTopSpeed' => 800,
            'carouselSpeed' => 150,
            'customSelects' => '.woocommerce-ordering .orderby, #dropdown_product_cat, .widget_categories select, .widget_archive select, #bbp_stick_topic_select, #bbp_topic_status_select, #bbp_destination_topic, .single-product .variations_form .variations select',
        );



        // WooCart

        if (TB_WOOCOMMERCE_ACTIVE) {

            $array['wooCartStyle'] = tb_global_obj('menu_cart_style');
        }



        // Sidr settings

        if ('sidr' == $mobile_menu_style) {

            $array['sidrSource'] = tb_global_obj('sidr_menu_source');

            $array['sidrDisplace'] = tb_get_mod('mobile_menu_sidr_displace', true) ? true : false;

            $array['sidrSide'] = tb_get_mod('mobile_menu_sidr_direction', 'left');

            $array['sidrSpeed'] = 300;
        }



        // Toggle mobile menu

        if ('toggle' == $mobile_menu_style) {

            $array['animateMobileToggle'] = true;
        }



        // Sticky Header

        if ($sticky_header) {

            $array['stickyShrinkOffset'] = 0;

            if (tb_global_obj('fixed_header_logo')) {

                $array['stickyheaderCustomLogo'] = tb_global_obj('fixed_header_logo');
            }

            $array['hasStickyMobileHeader'] = tb_get_mod('fixed_header_mobile');

            $array['overlayHeaderStickyTop'] = 0;

            $array['stickyHeaderBreakPoint'] = 960;

            $array['shrinkHeaderLogoHeight'] = tb_get_mod('fixed_header_shrink_logo_height', 50);
        }



        // Sticky topBar

        if (tb_get_mod('top_bar_sticky')) {

            $array['stickyTopBarBreakPoint'] = 960;

            $array['hasStickyTopBarMobile'] = true;
        }



        // Header five

        if ('five' == $header_style) {

            $array['headerFiveSplitOffset'] = 1;
        }



        // Full screen mobile menu style

        if ('full_screen' == $mobile_menu_style) {

            $array['fullScreenMobileMenuStyle'] = tb_get_mod('full_screen_mobile_menu_style', 'white');
        }



        // Apply filters and return array

        return apply_filters('tb_localize_array', $array);
    }

    /**

     * Add headers for IE to override IE's Compatibility View Settings

     *

     * @since 2.1.0

     */
    public static function x_ua_compatible_headers($headers) {

        $headers['X-UA-Compatible'] = 'IE=edge';

        return $headers;
    }

    /**

     * Adds CSS for ie8

     * Applies the tb_ie_8_url filter so you can alter your IE8 stylesheet URL

     *

     * @since 1.6.0

     */
    public static function browser_dependent_css() {

        $ie_8 = apply_filters('tb_ie8_stylesheet', TB_CSS_DIR_URI . 'ie8.css');

        echo '<!--[if IE 8]><link rel="stylesheet" type="text/css" href="' . $ie_8 . '" media="screen"><![endif]-->';

        $ie_9 = apply_filters('tb_ie9_stylesheet', TB_CSS_DIR_URI . 'ie9.css');

        echo '<!--[if IE 9]><link rel="stylesheet" type="text/css" href="' . $ie_9 . '" media="screen"><![endif]-->';
    }

    /**

     * Load HTML5 dependencies for IE8

     *

     * @since 1.6.0

     */
    public static function html5_shiv() {

        echo '<!--[if lt IE 9]><script src="' . TB_JS_DIR_URI . 'html5.js"></script><![endif]-->';
    }

    /**

     * Registers the theme sidebars (widget areas)

     *

     * @since 1.6.0

     */
    public function register_sidebars() {



        // Heading element type

        $sidebar_headings = tb_get_mod('sidebar_headings', 'div');

        $sidebar_headings = $sidebar_headings ? $sidebar_headings : 'div';

        $footer_headings = tb_get_mod('footer_headings', 'div');

        $footer_headings = $footer_headings ? $footer_headings : 'div';



        // Main Sidebar

        register_sidebar(array(
            'name' => __('Main Sidebar', 'tb'),
            'id' => 'sidebar',
            'description' => __('Widgets in this area are used in the default sidebar. This sidebar will be used for your standard blog posts.', 'tb'),
            'before_widget' => '<div class="sidebar-box %2$s clr">',
            'after_widget' => '</div>',
            'before_title' => '<' . $sidebar_headings . ' class="widget-title">',
            'after_title' => '</' . $sidebar_headings . '>',
        ));



        // Pages Sidebar

        if (tb_get_mod('pages_custom_sidebar', true)) {

            register_sidebar(array(
                'name' => __('Pages Sidebar', 'tb'),
                'id' => 'pages_sidebar',
                'before_widget' => '<div class="sidebar-box %2$s clr">',
                'after_widget' => '</div>',
                'before_title' => '<' . $sidebar_headings . ' class="widget-title">',
                'after_title' => '</' . $sidebar_headings . '>',
            ));
        }



        // Search Results Sidebar

        if (tb_get_mod('search_custom_sidebar', true)) {

            register_sidebar(array(
                'name' => __('Search Results Sidebar', 'tb'),
                'id' => 'search_sidebar',
                'before_widget' => '<div class="sidebar-box %2$s clr">',
                'after_widget' => '</div>',
                'before_title' => '<' . $sidebar_headings . ' class="widget-title">',
                'after_title' => '</' . $sidebar_headings . '>',
            ));
        }



        // Testimonials Sidebar

        if (post_type_exists('testimonials') && tb_get_mod('testimonials_custom_sidebar', true)) {

            $obj = get_post_type_object('testimonials');

            $post_type_name = $obj->labels->name;

            register_sidebar(array(
                'name' => $post_type_name . ' ' . __('Sidebar', 'tb'),
                'id' => 'testimonials_sidebar',
                'before_widget' => '<div class="sidebar-box %2$s clr">',
                'after_widget' => '</div>',
                'before_title' => '<' . $sidebar_headings . ' class="widget-title">',
                'after_title' => '</' . $sidebar_headings . '>',
            ));
        }

// Side Menu Widgit

        register_sidebar(array(
            'name' => __('Side Menu Widgit Area', 'tb'),
            'id' => 'side_menu',
            'before_widget' => '<div class="side_menu %2$s clr">',
            'after_widget' => '</div>',
            'before_title' => '<' . $sidebar_headings . ' class="widget-title">',
            'after_title' => '</' . $sidebar_headings . '>',
        ));





        register_sidebar(array(
            'name' => __('Custom Footer Coloumn 1', ''),
            'id' => 'cs-footer-1',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Footer Coloumn 2', ''),
            'id' => 'cs-footer-2',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Footer Coloumn 3', ''),
            'id' => 'cs-footer-3',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Footer Coloumn 4', ''),
            'id' => 'cs-footer-4',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Footer Coloumn 5', ''),
            'id' => 'cs-footer-5',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Mobile Coloumn left', ''),
            'id' => 'cs-m-footer-1',
            'description' => __('Add footer coloumn', ''),
            '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' => __('Custom Mobile Coloumn Right', ''),
            'id' => 'cs-m-footer-2',
            'description' => __('Add footer coloumn', ''),
            'before_widget' => '<div id="%1$s" class="widget %2$s">',
            'after_widget' => '</div>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));





        // Footer Sidebars

        if (tb_get_mod('footer_widgets', true)) {



            // Footer widget columns

            $footer_columns = tb_get_mod('footer_widgets_columns', '4');



            // Footer 1

            register_sidebar(array(
                'name' => __('Footer Column 1', 'tb'),
                'id' => 'footer_one',
                'before_widget' => '<div class="footer-widget %2$s clr">',
                'after_widget' => '</div>',
                'before_title' => '<' . $footer_headings . ' class="widget-title">',
                'after_title' => '</' . $footer_headings . '>',
            ));



            // Footer 2

            if ($footer_columns > '1') {

                register_sidebar(array(
                    'name' => __('Footer Column 2', 'tb'),
                    'id' => 'footer_two',
                    'before_widget' => '<div class="footer-widget %2$s clr">',
                    'after_widget' => '</div>',
                    'before_title' => '<' . $footer_headings . ' class="widget-title">',
                    'after_title' => '</' . $footer_headings . '>'
                ));
            }



            // Footer 3

            if ($footer_columns > '2') {

                register_sidebar(array(
                    'name' => __('Footer Column 3', 'tb'),
                    'id' => 'footer_three',
                    'before_widget' => '<div class="footer-widget %2$s clr">',
                    'after_widget' => '</div>',
                    'before_title' => '<' . $footer_headings . ' class="widget-title">',
                    'after_title' => '</' . $footer_headings . '>',
                ));
            }



            // Footer 4

            if ($footer_columns > '3') {

                register_sidebar(array(
                    'name' => __('Footer Column 4', 'tb'),
                    'id' => 'footer_four',
                    'before_widget' => '<div class="footer-widget %2$s clr">',
                    'after_widget' => '</div>',
                    'before_title' => '<' . $footer_headings . ' class="widget-title">',
                    'after_title' => '</' . $footer_headings . '>',
                ));
            }



            // Footer 5

            if ($footer_columns > '4') {

                register_sidebar(array(
                    'name' => __('Footer Column 5', 'tb'),
                    'id' => 'footer_five',
                    'before_widget' => '<div class="footer-widget %2$s clr">',
                    'after_widget' => '</div>',
                    'before_title' => '<' . $footer_headings . ' class="widget-title">',
                    'after_title' => '</' . $footer_headings . '>',
                ));
            }
        }
    }

    /**

     * Add the gallery metabox to more post types

     *

     * @since 2.0.0

     */
    public static function add_gallery_metabox($types) {

        $types[] = 'page';

        return $types;
    }

    /**

     * Defines the directory URI for the gallery metabox class.

     *

     * @since 1.6.3

     */
    public static function gallery_metabox_dir_uri() {

        return TB_FRAMEWORK_DIR_URI . 'classes/gallery-metabox/';
    }

    /**

     * All theme functions hook into the tb_head_css filter for this function.

     * This way all dynamic CSS is minified and outputted in one location in the site header.

     *

     * @since 1.6.0

     */
    public static function custom_css($output = NULL) {



        // Add filter for adding custom css via other functions

        $output = apply_filters('tb_head_css', $output);



        // Minify and output CSS in the wp_head

        if (!empty($output)) {

            $output = tb_minify_css($output);

            $output = "<!-- TOTAL CSS -->\n<style type=\"text/css\">\n" . $output . "\n</style>";

            echo $output;
        }
    }

    /**

     * Adds inline CSS for the admin

     *

     * @since 1.6.0

     */
    public static function admin_inline_css() {

        echo '<style>div#setting-error-tgmpa{display:block;}</style>';
    }

    /**

     * Alters the default WordPress tag cloud widget arguments.

     * Makes sure all font sizes for the cloud widget are set to 1em.

     *

     * @since 1.6.0 

     */
    public static function widget_tag_cloud_args($args) {

        $args['largest'] = '0.923em';

        $args['smallest'] = '0.923em';

        $args['unit'] = 'em';

        return $args;
    }

    /**

     * Alter wp list categories arguments.

     * Adds a span around the counter for easier styling.

     *

     * @since 1.6.0

     */
    public static function wp_list_categories_args($links) {

        $links = str_replace('</a> (', '</a> <span class="cat-count-span">(', $links);

        $links = str_replace(' )', ' )</span>', $links);

        return $links;
    }

    /**

     * This function runs before the main query.

     *

     * @since 1.6.0

     */
    public function pre_get_posts($query) {



        // Lets not break stuff

        if (is_admin() || !$query->is_main_query()) {

            return;
        }



        // Search pagination

        if (is_search()) {

            $query->set('posts_per_page', tb_get_mod('search_posts_per_page', '10'));

            return;
        }



        // Exclude categories from the main blog

        if (( is_home() || is_page_template('templates/blog.php') ) && $cats = tb_blog_exclude_categories()) {

            set_query_var('category__not_in', $cats);

            return;
        }



        // Category pagination

        $terms = get_terms('category');

        if (!empty($terms)) {

            foreach ($terms as $term) {

                if (is_category($term->slug)) {

                    $term_id = $term->term_id;

                    $term_data = get_option("category_$term_id");

                    if ($term_data) {

                        if (!empty($term_data['tb_term_posts_per_page'])) {

                            $query->set('posts_per_page', $term_data['tb_term_posts_per_page']);

                            return;
                        }
                    }
                }
            }
        }
    }

    /**

     * Add new user fields / user meta

     *

     * @since 1.6.0

     */
    public static function add_user_social_fields($contactmethods) {



        $branding = TB_THEME_BRANDING;



        if (!isset($contactmethods['tb_twitter'])) {

            $contactmethods['tb_twitter'] = $branding . ' - Twitter';
        }



        if (!isset($contactmethods['tb_facebook'])) {

            $contactmethods['tb_facebook'] = $branding . ' - Facebook';
        }



        if (!isset($contactmethods['tb_googleplus'])) {

            $contactmethods['tb_googleplus'] = $branding . ' - Google+';
        }



        if (!isset($contactmethods['tb_linkedin'])) {

            $contactmethods['tb_linkedin'] = $branding . ' - LinkedIn';
        }



        if (!isset($contactmethods['tb_pinterest'])) {

            $contactmethods['tb_pinterest'] = $branding . ' - Pinterest';
        }



        if (!isset($contactmethods['tb_instagram'])) {

            $contactmethods['tb_instagram'] = $branding . ' - Instagram';
        }



        return $contactmethods;
    }

    /**

     * Alters the default oembed output.

     * Adds special classes for responsive oembeds via CSS.

     *

     * @since 1.6.0

     */
    public static function add_responsive_wrap_to_oembeds($html, $url, $attr, $post_id) {

        $html = '<div class="responsive-video-wrap entry-video">' . $html . '</div>';

        return $html;
    }

    /**

     * The wp_get_attachment_url() function doesn't distinguish whether a page request arrives via HTTP or HTTPS.

     * Using wp_get_attachment_url filter, we can fix this to avoid the dreaded mixed content browser warning

     *

     * @since 1.6.0

     */
    public static function honor_ssl_for_attachments($url) {

        $http = site_url(FALSE, 'http');

        $https = site_url(FALSE, 'https');

        $isSecure = false;

        if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {

            $isSecure = true;
        }

        if ($isSecure) {

            return str_replace($http, $https, $url);
        } else {

            return $url;
        }
    }

    /**

     * Alters the default WordPress password protected form so it's easier to style

     *

     * @since 2.0.0

     */
    public static function custom_password_protected_form() {

        ob_start();

        include( locate_template('partials/password-protection-form.php') );

        return ob_get_clean();
    }

    /**

     * Modify JOIN in the next/prev function

     *

     * @since 2.0.0

     */
    public static function prev_next_join($join) {

        global $wpdb;

        $join .= " LEFT JOIN $wpdb->postmeta AS m ON ( p.ID = m.post_id AND m.meta_key = 'tb_post_link' )";

        return $join;
    }

    /**

     * Modify WHERE in the next/prev function

     *

     * @since 2.0.0

     */
    public static function prev_next_where($where) {

        global $wpdb;

        $where .= " AND ( (m.meta_key = 'tb_post_link' AND CAST(m.meta_value AS CHAR) = '' ) OR m.meta_id IS NULL ) ";

        return $where;
    }

    /**

     * Redirect posts using custom links

     *

     * @since 2.0.0

     */
    public static function redirect_custom_links() {

        if (is_singular() && $custom_link = tb_get_custom_permalink()) {

            wp_redirect($custom_link, 301);
        }
    }

    /**

     * When a term is deleted, delete its data.

     *

     * @since 2.1.0

     */
    public static function delete_term($term_id) {



        // If term id is defined

        if ($term_id = absint($term_id)) {



            // Get terms data

            $term_data = get_option('tb_term_data');



            // Remove key with term data

            if ($term_data && isset($term_data[$term_id])) {

                unset($term_data[$term_id]);

                update_option('tb_term_data', $term_data);
            }
        }
    }

    /**

     * Adds extra classes to the post_class() output

     *

     * @since 3.0.0

     */
    public static function post_class($classes) {



        // Get post

        global $post;



        // Add entry class

        $classes[] = 'entry';



        // Add has media class

        if (has_post_thumbnail() || get_post_meta($post->ID, 'tb_post_oembed', true) || get_post_meta($post->ID, 'tb_post_self_hosted_media', true) || get_post_meta($post->ID, 'tb_post_video_embed', true) || get_post_meta($post->ID, 'tb_post_oembed', true)
        ) {

            $classes[] = 'format-video';

            $classes[] = 'has-media';
        }



        // Return classes

        return $classes;
    }

    /**

     * Add schema markup to the authors post link

     *

     * @since 3.0.0

     */
    public static function the_author_posts_link($link) {



        // Add schema markup

        $schema = tb_get_schema_markup('author_link');

        if ($schema) {

            $link = str_replace('rel="author"', 'rel="author"' . $schema, $link);
        }



        // Return link

        return $link;
    }

}

$tb_theme_setup = new TB_Theme_Setup;

function theme_name_scripts() {

    wp_enqueue_style('bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css');

    wp_enqueue_style('style', get_template_directory_uri() . '/bootstrap/style.css');

    wp_enqueue_script('bootstrap', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js');

    wp_enqueue_script('flash', get_template_directory_uri() . '/js/flash_detect_min.js');

    wp_enqueue_script('dt', get_template_directory_uri() . '/js/dt50.js');

    wp_enqueue_style('custom', get_template_directory_uri() . '/css/custom.css');

    wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');
}

add_action('wp_enqueue_scripts', 'theme_name_scripts');




include('optionpage/admin_menu.php');

add_action('woocommerce_product_thumbnails', 'display_product_video', 1);

function display_product_video() {
    echo '<span class="selected_candy"></span>';
    echo '<div class="video-on-fullwidth">';
    the_field('video');
    echo '</div>';
}

add_action('woocommerce_single_product_summary', 'woocommerce_template_top_category_desc', 31);

function woocommerce_template_top_category_desc() {
    echo '<div class="video-on-mobile">';
    the_field('video');
    echo '</div>';
}

/*
 * Call On Phone Customization 
 */

/*
 * Add Custom Fields to Product
 */

function action_woocommerce_before_add_to_cart_button() {

    if (is_user_logged_in()) {
        $user_meta = get_field('call_on_phone_executive', 'user_' . get_current_user_id());
        if ((!empty($user_meta)) && ($user_meta == 'Yes')) {
            ?>
            <div style="margin-bottom: 25px;">
                <label>Color of Pom Poms</label>
                <input name="color_of_pompoms" maxlength="50" class="input-text text" type="text" />
            </div>
            <div style="margin-bottom: 25px;">
                <label>Color of Tassels</label>
                <input name="color_of_tassel" maxlength="50" class="input-text text" type="text" />
            </div>
            <div style="margin-bottom: 25px;">
                <label>Color of Ribbons(around candy tube)</label>
                <input name="color_of_ribbons" class="input-text text" type="text" />
            </div>
            <div style="margin-bottom: 25px;">
                <label>Color of Bases</label>
                <input name="color_of_bases" class="input-text text" type="text" />
            </div>
            <?php
        }
    }
    ?>

    <?php
}

add_action('woocommerce_before_add_to_cart_button', 'action_woocommerce_before_add_to_cart_button', 10, 0);

/*
 * Add to Cart Meta fields
 */

function iconic_add_engraving_text_to_cart_item($cart_item_data, $product_id, $variation_id) {
    $color_of_bases = filter_input(INPUT_POST, 'color_of_bases');
    if (!empty($color_of_bases)) {
        $cart_item_data['color_of_bases'] = $color_of_bases;
    }
    $color_of_tassel = filter_input(INPUT_POST, 'color_of_tassel');
    if (!empty($color_of_tassel)) {
        $cart_item_data['color_of_tassel'] = $color_of_tassel;
    }
    $color_of_ribbons = filter_input(INPUT_POST, 'color_of_ribbons');
    if (!empty($color_of_ribbons)) {
        $cart_item_data['color_of_ribbons'] = $color_of_ribbons;
    }
    $color_of_pompoms = filter_input(INPUT_POST, 'color_of_pompoms');
    if (!empty($color_of_bases)) {
        $cart_item_data['color_of_pompoms'] = $color_of_pompoms;
    }
    return $cart_item_data;
}

add_filter('woocommerce_add_cart_item_data', 'iconic_add_engraving_text_to_cart_item', 10, 3);

function iconic_display_engraving_text_cart($item_data, $cart_item) {
    if (!empty($cart_item['color_of_bases'])) {
        $item_data[] = array(
            'key' => __('Color Of Bases', 'iconic'),
            'value' => wc_clean($cart_item['color_of_bases']),
            'display' => '',
        );
    }
    if (!empty($cart_item['color_of_tassel'])) {
        $item_data[] = array(
            'key' => __('Color Of Tassels', 'iconic'),
            'value' => wc_clean($cart_item['color_of_tassel']),
            'display' => '',
        );
    }
    if (!empty($cart_item['color_of_ribbons'])) {
        $item_data[] = array(
            'key' => __('Color Of Ribbons', 'iconic'),
            'value' => wc_clean($cart_item['color_of_ribbons']),
            'display' => '',
        );
    }
    if (!empty($cart_item['color_of_pompoms'])) {
        $item_data[] = array(
            'key' => __('Color Of Pompoms', 'iconic'),
            'value' => wc_clean($cart_item['color_of_pompoms']),
            'display' => '',
        );
    }



    return $item_data;
}

add_filter('woocommerce_get_item_data', 'iconic_display_engraving_text_cart', 10, 2);

add_action('woocommerce_add_order_item_meta', 'add_product_custom_field_to_order_item_meta', 9, 3);

function add_product_custom_field_to_order_item_meta($item_id, $item_values, $item_key) {
    if (!empty($item_values['color_of_bases'])) {
        wc_update_order_item_meta($item_id, 'Color of Bases', sanitize_text_field($item_values['color_of_bases']));
    }
    if (!empty($item_values['color_of_tassel'])) {
        wc_update_order_item_meta($item_id, 'Color of Tassel', sanitize_text_field($item_values['color_of_tassel']));
    }
    if (!empty($item_values['color_of_ribbons'])) {
        wc_update_order_item_meta($item_id, 'Color of Ribbons', sanitize_text_field($item_values['color_of_ribbons']));
    }
    if (!empty($item_values['color_of_pompoms'])) {
        wc_update_order_item_meta($item_id, 'Color of Pompoms', sanitize_text_field($item_values['color_of_pompoms']));
    }
}

/*
 * Add Cart Subtotal Fields
 */
add_action('woocommerce_after_checkout_billing_form', 'add_box_option_to_checkout');

function add_box_option_to_checkout($checkout) {
    if (is_user_logged_in()) {
        $user_meta = get_field('call_on_phone_executive', 'user_' . get_current_user_id());
        if ((!empty($user_meta)) && ($user_meta == 'Yes')) {
            echo '<div id="message_fields">';
            woocommerce_form_field('add_surcharge', array(
                'type' => 'text',
                'class' => array('add_surcharge_box form-row-wide'),
                'label' => __('Surcharge'),
                'placeholder' => __(''),
                    ), $checkout->get_value('add_surcharge'));
            woocommerce_form_field('add_surcharge_title', array(
                'type' => 'text',
                'class' => array('add_surcharge_box form-row-wide'),
                'label' => __('Surcharge Title'),
                'placeholder' => __(''),
                    ), $checkout->get_value('add_surcharge_title'));
            woocommerce_form_field('add_discount', array(
                'type' => 'text',
                'class' => array('add_discount_box form-row-wide'),
                'label' => __('Discount'),
                'placeholder' => __(''),
                    ), $checkout->get_value('add_discount'));
            woocommerce_form_field('add_discount_title', array(
                'type' => 'text',
                'class' => array('add_discount_box form-row-wide'),
                'label' => __('Discount Title'),
                'placeholder' => __(''),
                    ), $checkout->get_value('add_discount_title'));
            echo '<a class="button alt update_surcharge" href="#">Update Total</a>';
            echo '</div>';
        }
    }
}

add_action('wp_footer', 'woocommerce_add_gift_box');

function woocommerce_add_gift_box() {
    if (is_checkout()) {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('.update_surcharge').click(function () {
                    jQuery('body').trigger('update_checkout');
                    return false;
                });
            });
        </script>
        <?php
    }
}

add_action('woocommerce_cart_calculate_fees', 'woo_add_cart_fee');

function woo_add_cart_fee($cart) {
    if (is_user_logged_in()) {
        $user_meta = get_field('call_on_phone_executive', 'user_' . get_current_user_id());
        if ((!empty($user_meta)) && ($user_meta == 'Yes')) {
            if (!$_POST || ( is_admin() && !is_ajax() )) {
                return;
            }

            if (isset($_POST['post_data'])) {
                parse_str($_POST['post_data'], $post_data);
            } else {
                $post_data = $_POST; // fallback for final checkout (non-ajax)
            }

            if (isset($post_data['add_surcharge_title'])) {
                if (isset($post_data['add_surcharge'])) {
                    WC()->cart->add_fee($post_data['add_surcharge_title'], $post_data['add_surcharge']);
                } else {
                    WC()->cart->add_fee($post_data['add_surcharge_title'], 0);
                }
            }
            if (isset($post_data['add_discount_title'])) {
                if (isset($post_data['add_discount'])) {
                    WC()->cart->add_fee($post_data['add_discount_title'], -1 * $post_data['add_discount']);
                } else {
                    WC()->cart->add_fee($post_data['add_discount_title'], 0);
                }
            }
        }
    }
}

/*
 * Add Custom checkout fields 
 */

add_action('woocommerce_after_order_notes', 'customise_checkout_field');

function customise_checkout_field($checkout) {
    if (is_user_logged_in()) {
        $user_meta = get_field('call_on_phone_executive', 'user_' . get_current_user_id());
        if ((!empty($user_meta)) && ($user_meta == 'Yes')) {
            echo '<div id="customise_checkout_field"><h2>' . __('Party Details') . '</h2>';
            wp_enqueue_script('jquery-ui-datepicker');
            echo '
    <script>
        jQuery(function($){
            $("#datepicker").datepicker();
        });
    </script>';
            woocommerce_form_field('party_type', array(
                'type' => 'text',
                'class' => array(
                    'party_type form-row-wide'
                ),
                'label' => __('Party Type'),
                'placeholder' => __('Party Type'),
                'required' => true,
                    ), $checkout->get_value('party_type'));
            woocommerce_form_field('party_date', array(
                'type' => 'text',
                'class' => array(
                    'party_date form-row-wide'
                ),
                'id' => 'datepicker',
                'label' => __('Party Date'),
                'placeholder' => __('Party Date'),
                'required' => true,
                    ), $checkout->get_value('party_date'));
            echo '</div>';
        }
    }
}

add_action('woocommerce_checkout_update_order_meta', 'customise_checkout_field_update_order_meta');

function customise_checkout_field_update_order_meta($order_id) {
    $billing_email = get_post_meta($order_id, '_billing_email', TRUE);

    /* Search User By Email */
    if (!empty($billing_email)) {
        if (email_exists($billing_email)) {
            $user = get_user_by('email', $billing_email);
            update_post_meta($order_id, '_customer_user', $user->ID);
            $quoter = get_field('quoter', 'user_' . $user->ID);
            if (!empty($quoter)) {
                update_post_meta($order_id, 'quoter', $quoter);
            }
        }
    }

    if (!empty($_POST['party_type'])) {
        update_post_meta($order_id, 'Party Type', sanitize_text_field($_POST['party_type']));
    }
    if (!empty($_POST['party_date'])) {
        update_post_meta($order_id, 'Party Date', sanitize_text_field($_POST['party_date']));
    }
}