<?php
/**
 * Probit functions and definitions
 *
 * Sets up the theme and provides some helper functions, which are used
 * in the theme as custom template tags. Others are attached to action and
 * filter hooks in WordPress to change core functionality.
 *
 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached
 * to a filter or action hook.
 *
 * For more information on hooks, actions, and filters, @link http://codex.wordpress.org/Plugin_API
 *
 * @package WordPress
 * @subpackage Probit
 * @since Probit 1.0
 *
 */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}

// Set up the content width value based on the theme's design and stylesheet.
if (!isset($content_width))
    $content_width = 625;

/**
 * Probit setup.
 *
 * Sets up theme defaults and registers the various WordPress features that
 * Probit supports.
 *
 * @uses load_theme_textdomain() For translation/localization support.
 * @uses add_editor_style() To add a Visual Editor stylesheet.
 * @uses add_theme_support() To add support for post thumbnails, automatic feed links,
 * 	custom background, and post formats.
 * @uses register_nav_menu() To add support for navigation menus.
 * @uses set_post_thumbnail_size() To set a custom post thumbnail size.
 *
 *
 */
if (!function_exists('probit_setup')) {

    function probit_setup() {
        /*
         * Makes Probit available for translation.
         *
         * Translations can be added to the /languages/ directory.
         * If you're building a theme based on Probit, use a find and replace
         * to change 'probit' to the name of your theme in all the template files.
         */
        load_theme_textdomain('probit', get_template_directory() . '/languages');

        // This theme styles the visual editor with editor-style.css to match the theme style.
        add_editor_style();

        // Adds RSS feed links to <head> for posts and comments.
        add_theme_support('automatic-feed-links');

        add_theme_support('title-tag');

        /*
         * Enable support for custom logo.
         *
         *  @since 1.1.7
         */
        add_theme_support('custom-logo', array(
            'height' => 52,
            'width' => 172,
            'flex-height' => true,
            'flex-width' => true,
        ));

        // This theme uses wp_nav_menu() in one location.
        register_nav_menu('primary', __('Primary Menu', 'probit'));

        /*
         * This theme supports custom background color and image,
         * and here we also set up the default background color.
         */
        add_theme_support('custom-background', array(
            'default-color' => 'e6e6e6',
        ));


        // This theme uses a custom image size for featured images, displayed on "standard" posts.
        add_theme_support('post-thumbnails');
        set_post_thumbnail_size(624, 9999); // Unlimited height, soft crop

        /*
         * Add custom image sizes.
         */
        add_image_size('probit-portfolio-slider-img', 370, 370, true);
        add_image_size('probit-testimonial-slider-img', 150, 150, true);
        add_image_size('probit-blog-img', 270, 270, true);
        add_image_size('probit-blogpage-img', 600, 600, true);
        add_image_size('probit-client-logo', 200, 130, true);

        // Add theme support for selective refresh for widgets.
        add_theme_support('customize-selective-refresh-widgets');

        add_theme_support('custom-header', apply_filters('probit_custom_header_args', array(
            'default-text-color' => '000000',
            'width' => 1200,
            'height' => 280,
            'flex-height' => true,
            'wp-head-callback' => 'probit_header_style',
        )));
    }

}
add_action('after_setup_theme', 'probit_setup');

if (!function_exists('probit_scripts_styles')) {

    /**
     * Enqueue scripts and styles for front-end.
     */
    function probit_scripts_styles() {
        /*
         * Adds JavaScript to pages with the comment form to support
         * sites with threaded comments (when in use).
         */
        if (is_singular() && comments_open() && get_option('thread_comments'))
            wp_enqueue_script('comment-reply');

        //script
        wp_enqueue_script('bootstrap', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', array('jquery'));
        wp_enqueue_script('superfish', get_template_directory_uri() . '/js/superfish.js');
        wp_enqueue_script('jquery.meanmenu', get_template_directory_uri() . '/js/jquery.meanmenu.js');
        wp_enqueue_script('carouFredSel', get_template_directory_uri() . '/js/jquery.carouFredSel-6.2.1.js');
        wp_enqueue_script('slick', get_template_directory_uri() . '/js/slick.js');
        wp_enqueue_script('isotope', get_template_directory_uri() . '/js/isotope.pkgd.js');
        wp_enqueue_script('probit-script', get_template_directory_uri() . '/js/probit-script.js');

        // Adds JavaScript for handling the navigation menu hide-and-show behavior.
        wp_enqueue_script('probit-navigation', get_template_directory_uri() . '/js/probit-navigation.js', array('jquery'), '20140711', true);

        //style
        wp_enqueue_style('bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css');
        wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.css');
        wp_enqueue_style('meanmenu', get_template_directory_uri() . '/css/meanmenu.css');
        wp_enqueue_style('slick', get_template_directory_uri() . '/css/slick.css');

        // Loads our main stylesheet.
        wp_enqueue_style('probit-style', get_stylesheet_uri());

        $link_color = esc_attr(get_theme_mod('theme_color'));
        $header_textcolor = esc_attr(get_theme_mod('header_textcolor'));
        $background_color = esc_attr(get_theme_mod('background_color'));
        $content_color = esc_attr(get_theme_mod('content_color'));
        $custom_css = "";

        if ($header_textcolor != '') :
            $custom_css .= "
                .main-navigation li a {
                        color: {$header_textcolor};
                }
                .site-title a {
                    color: {$header_textcolor} !important;
                }";
        endif;

        if ($link_color != '#1E73BE') :
            $custom_css = "
                .top-header,
                .single_block a:hover,
                .filter_ourteam ul li a.category_menu_selected,
                .filter_ourteam ul li a:hover,
                .effect_portfolio,
                .read_more:hover,
                .widget-area .widget-title,
                .overlay,
                .pagination span.current,
                .blog-wrap .date_wrapper .date,
                .post-icon,
                .Recent_posts ul li .desc .ico i,
                .pricing_table_single.heighlight_price .title,
                .button_div a:hover,
                .faq-list .question_heading,
                .mean-container .mean-bar,
                .our-team-designation a,
                .mean-container .mean-bar,
                #category_menu_ul .category_menu_selected,
                #primary .filter_portfolio a:hover,
                #primary .filter_portfolio a:active,
                #primary .filter_portfolio a:focus,
                #primary .pagination a:hover,
                #primary div[role='tabpanel'] .tabstyle2.nav-tabs > li.active > a,
                #primary div[role='tabpanel'] .tabstyle2.nav-tabs > li.active > a:hover,
                #primary div[role='tabpanel'] .tabstyle2.nav-tabs > li.active > a:focus,
                #primary div[role='tabpanel'] .tabstyle2.nav-tabs > li > a:focus,
                #primary div[role='tabpanel'] .tabstyle2.nav-tabs > li > a:hover,
                button:hover,
                footer[role='contentinfo'] a.arrow-up,
                input[type='submit']:hover,
                input[type='button']:hover,
                input[type='reset']:hover,
                article.post-password-required input[type='submit']:hover {
                    background-color: {$link_color};
                }
                .mean-container .meanmenu-reveal, 
                .mean-container .mean-nav,
                .progress_inner {
                    background-color: {$link_color} !important;
                }
                .title_heading span,
                .filter_ourteam ul li a.category_menu_selected,
                .filter_ourteam ul li a:hover,
                #category_menu_ul .category_menu_selected,
                #primary .filter_portfolio a:hover,
                #primary .filter_portfolio a:active,
                #primary .filter_portfolio a:focus {
                    border-color: {$link_color};
                } 
                #masthead.is-sticky {
                    box-shadow: 0 0 15px 0 {$link_color};
                } 
                .site-header h1 a:hover,
                .site-header h2 a:hover,
                a:focus,
                a .leave-reply,
                .main-navigation .menu-item.sfHover > a,
                .portfolio_item:hover .portfoliolink,
                .blog_title h3 a,
                .probit-two-blog a,
                .testimonial_slider_div .caroufredsel_wrapper a,
                .widget-area .widget ul li a,
                .probit-tags a,
                .blog_div .blog_footer span a,
                .postmeta_div span a,
                .comment .comment-meta a,
                .nav-single span a,
                .comment-form p a,
                .footer_area .widget ul li a:hover,
                .footer_area .widget a:hover,
                .footer-bottom .site-info a:hover,
                .widget span a:hover,
                .portflio_slider_div:hover .next_carousel,
                .portflio_slider_div:hover .prev_carousel,
                .portfolio_icon i:hover,
                .main-navigation a:hover,
                .main-navigation a:focus,
                .main-navigation .menu-item.sfHover > a,
                .information a:hover,
                .filter_portfolio a, .filter_ourteam ul li a,
                .entry-content p a,
                .site-info a,
                .footer_area a,
                .tagcloud a,
                .post-edit-link,
                #cancel-comment-reply-link,
                .nav-previous a,
                .footer_area .widget .widget-title,
                .reply-title,
                .comments-title {
                    color: {$link_color} !important;
                } 
                #primary div[role='tabpanel'] .nav-tabs > li.active > a,
                #primary div[role='tabpanel'] .nav-tabs > li.active > a:hover,
                #primary div[role='tabpanel'] .nav-tabs > li.active > a:focus,
                #primary div[role='tabpanel'] .nav-tabs > li > a:focus,
                #primary div[role='tabpanel'] .nav-tabs > li > a:hover,
                .widget_nav_menu .current-menu-item > a,
                .widget_nav_menu .current-menu-ancestor > a,
                .widget_nav_menu .current_page_item > a,
                .widget_nav_menu .current_page_ancestor > a,
                .single_top_bar h1,
                .blog_div h2 a,
                .widget .widget-title ul li a,
                .widget_rss ul li a.rsswidget,
                .entry-content a,
                .entry-content a b,
                .entry-content b a,
                .breadcrumbs .breadcrumbs_inner a,
                .main-navigation li.current-menu-item a,
                .main-navigation li.current-menu-ancestor a,
                .main-navigation li.current_page_item a,
                .main-navigation li.current_page_ancestor a
                footer.footer_area[role='contentinfo'] a,
                footer[role='contentinfo'] a.mailtolink,
                a.mailtolink {
                    color: {$link_color};
                } 
                blockquote {
                    border-color: {$link_color} !important;
                } 
                #masthead.is-sticky,
                .main-navigation li ul {
                    background:#{$background_color} !important;
                } 
                body,
                .single_block a *,
                .title_heading h2,
                .entry-content h1, .comment-content h1,
                .entry-content h2, .comment-content h2, .mu_register h2,
                .entry-content h3, .comment-content h3, .timeline h3,
                .entry-content h4, .comment-content h4,
                .entry-content h5, .comment-content h5,
                .entry-content h6, .comment-content h6,
                .page .entry-content p,
                .entry-summary p,
                .comment-content p,
                .mu_register p,
                .timeline_bg p,
                .main-navigation li a,
                .entry-content a:hover,
                .entry-content a:hover b,
                .entry-content b a:hover,
                .breadcrumbs .breadcrumbs_inner a:hover,
                .breadcrumbs .breadcrumbs_inner span,
                .entry-content table, .comment-content table {
                    color: {$content_color} !important;
                }";
        endif;

        wp_add_inline_style('probit-style', $custom_css);

        // Load the Internet Explorer specific stylesheet.
        wp_enqueue_style('probit-ie', get_template_directory_uri() . '/css/ie.css', array('probit-style'), '20150825');
        wp_style_add_data('probit-ie', 'conditional', 'lt IE 9');

        // Load the html5 shiv.
        wp_enqueue_script('html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3');
        wp_script_add_data('html5', 'conditional', 'lt IE 9');
    }

}
add_action('wp_enqueue_scripts', 'probit_scripts_styles');

if (!function_exists('probit_page_menu_args')) {

    /**
     * Filter the page menu arguments.
     *
     * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link.
     *
     */
    function probit_page_menu_args($args) {
        if (!isset($args['show_home']))
            $args['show_home'] = true;
        return $args;
    }

}
add_filter('wp_page_menu_args', 'probit_page_menu_args');

if (!function_exists('probit_widgets_init')) {

    /**
     * Register sidebars.
     *
     * Registers our main widget area and the front page widget areas.
     *
     *
     */
    function probit_widgets_init() {
        register_sidebar(array(
            'name' => __('Main Sidebar', 'probit'),
            'id' => 'sidebar-1',
            'description' => __('Appears on posts and pages except the optional Front Page template, which has its own widgets', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));

        register_sidebar(array(
            'name' => __('Footer Column 1', 'probit'),
            'id' => 'footer-sidebar1',
            'description' => __('Appears in footer', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));
        register_sidebar(array(
            'name' => __('Footer Column 2', 'probit'),
            'id' => 'footer-sidebar2',
            'description' => __('Appears in footer', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));
        register_sidebar(array(
            'name' => __('Footer Column 3', 'probit'),
            'id' => 'footer-sidebar3',
            'description' => __('Appears in footer', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));
        register_sidebar(array(
            'name' => __('Footer Column 4', 'probit'),
            'id' => 'footer-sidebar4',
            'description' => __('Appears in footer', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));

        register_sidebar(array(
            'name' => __('Contact Page Widget', 'probit'),
            'id' => 'contact-sidebar',
            'description' => __('Appears in Contact page', 'probit'),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => '</aside>',
            'before_title' => '<h3 class="widget-title">',
            'after_title' => '</h3>',
        ));
    }

}
add_action('widgets_init', 'probit_widgets_init');

if (!function_exists('probit_content_nav')) :
    /*
     * Displays navigation to next/previous pages when applicable.
     */

    function probit_content_nav($html_id) {
        global $wp_query;

        $html_id = esc_attr($html_id);

        if ($wp_query->max_num_pages > 1) :
            ?>
            <nav id="<?php echo $html_id; ?>" class="navigation" role="navigation">
                <h3 class="assistive-text"><?php _e('Post navigation', 'probit'); ?></h3>
                <div class="nav-previous"><?php next_posts_link('<span class="meta-nav">&larr;</span> ' . __('Older posts', 'probit')); ?></div>
                <div class="nav-next"><?php previous_posts_link(__('Newer posts', 'probit') . ' <span class="meta-nav">&rarr;</span>'); ?></div>
            </nav><!-- #<?php echo $html_id; ?> .navigation -->
            <?php
        endif;
    }

endif;

if (!function_exists('probit_comment')) :

    /**
     * Template for comments and pingbacks.
     *
     * To override this walker in a child theme without modifying the comments template
     * simply create your own probit_comment(), and that function will be used instead.
     *
     * Used as a callback by wp_list_comments() for displaying the comments.
     *
     *
     */
    function probit_comment($comment, $args, $depth) {
        switch ($comment->comment_type) :
            case 'pingback' :
            case 'trackback' :
                // Display trackbacks differently than normal comments.
                ?>
                <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
                    <p><?php _e('Pingback:', 'probit'); ?> <?php comment_author_link(); ?> <?php edit_comment_link(__('(Edit)', 'probit'), '<span class="edit-link">', '</span>'); ?></p>
                </li>
                <?php
                break;
            default :
                // Proceed with normal comments.
                global $post;
                ?>
                <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
                    <article id="comment-<?php comment_ID(); ?>" class="comment">
                        <header class="comment-meta comment-author vcard">
                            <?php
                            echo get_avatar($comment, 64, $default = '', $alt = get_comment_author());
                            printf('<cite><b class="fn">%1$s</b> %2$s</cite>', get_comment_author_link(),
                                    // If current post author is also comment author, make it known visually.
                                    edit_comment_link(__('Edit', 'probit'), ' <span class="edit-link"> <i class="fa fa-pencil-square-o"></i> ', '</span>')
                            );
                            printf('<a href="%1$s"><time datetime="%2$s">%3$s</time> </a>', esc_url(get_comment_link($comment->comment_ID)), get_comment_time('c'),
                                    /* translators: 1: date, 2: time */ get_comment_date() . ' ' . __('at', 'probit') . ' ' . get_comment_time()
                            );
                            ?>
                            <?php if ('0' == $comment->comment_approved) : ?>
                                <p class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.', 'probit'); ?></p>
                            <?php endif; ?>

                            <section class="comment-content comment">
                                <?php comment_text(); ?>
                            </section><!-- .comment-content -->
                            <div class="reply">
                                <?php comment_reply_link(array_merge($args, array('reply_text' => __('Reply', 'probit'), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
                            </div><!-- .reply -->
                        </header><!-- .comment-meta -->

                    </article><!-- #comment-## -->
                </li>
                <?php
                break;
        endswitch; // end comment_type check
    }

endif;

if (!function_exists('probit_entry_meta')) :

    /**
     * Set up post entry meta.
     *
     * Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
     *
     * Create your own probit_entry_meta() to override in a child theme.
     *
     *
     */
    function probit_entry_meta() {
        // Translators: used between list items, there is a space after the comma.
        $categories_list = get_the_category_list(', ');

        // Translators: used between list items, there is a space after the comma.
        $tag_list = get_the_tag_list('', ', ');

        $date = sprintf('<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', esc_url(get_permalink()), esc_attr(get_the_time()), esc_html(get_the_date('c')), esc_html(get_the_date())
        );

        $author = sprintf('<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by', 'probit') . ' ' . get_the_author())), get_the_author()
        );

        // Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
        if ($tag_list) {
            $utility_text = __('This entry was posted in', 'probit') . ' %1$s ' . __('and tagged', 'probit') . ' %2$s ' . __('on', 'probit') . ' %3$s<span class="by-author"> ' . __('by', 'probit') . ' %4$s</span>.';
        } elseif ($categories_list) {
            $utility_text = __('This entry was posted in', 'probit') . ' %1$s ' . __('on', 'probit') . ' %3$s<span class="by-author"> ' . __('by', 'probit') . ' %4$s</span>.';
        } else {
            $utility_text = __('This entry was posted on', 'probit') . ' %3$s <span class="by-author"> ' . __('by', 'probit') . ' %4$s</span>.';
        }

        printf(
                $utility_text, $categories_list, $tag_list, $date, $author
        );
    }

endif;

if (!function_exists('probit_body_class')) {

    /**
     * Extend the default WordPress body classes.
     *
     * Extends the default WordPress body class to denote:
     * 1. Using a full-width layout, when no active widgets in the sidebar
     *    or full-width template.
     * 2. Front Page template: thumbnail in use and number of sidebars for
     *    widget areas.
     * 3. White or empty background color to change the layout and spacing.
     * 4. Custom fonts enabled.
     * 5. Single or multiple authors.
     *
     *
     *
     * @param array $classes Existing class values.
     * @return array Filtered class values.
     */
    function probit_body_class($classes) {
        $background_color = get_background_color();
        $background_image = get_background_image();

        if (!is_active_sidebar('sidebar-1') || is_page_template('page-templates/full-width.php'))
            $classes[] = 'full-width';

        if (is_page_template('page-templates/front-page.php')) {
            $classes[] = 'template-front-page';
            if (has_post_thumbnail())
                $classes[] = 'has-post-thumbnail';
            if (is_active_sidebar('sidebar-2') && is_active_sidebar('sidebar-3'))
                $classes[] = 'two-sidebars';
        }

        if (empty($background_image)) {
            if (empty($background_color))
                $classes[] = 'custom-background-empty';
            elseif (in_array($background_color, array('fff', 'ffffff')))
                $classes[] = 'custom-background-white';
        }

        // Enable custom font class only if the font CSS is queued to load.
        if (wp_style_is('probit-fonts', 'queue'))
            $classes[] = 'custom-font-enabled';

        if (!is_multi_author())
            $classes[] = 'single-author';

        return $classes;
    }

}
add_filter('body_class', 'probit_body_class');

if (!function_exists('probit_content_width')) {

    /**
     * Adjust content width in certain contexts.
     *
     * Adjusts content_width value for full-width and single image attachment
     * templates, and when there are no active widgets in the sidebar.
     *
     *
     */
    function probit_content_width() {
        if (is_page_template('page-templates/full-width.php') || is_attachment() || !is_active_sidebar('sidebar-1')) {
            global $content_width;
            $content_width = 960;
        }
    }

}
add_action('template_redirect', 'probit_content_width');

if (!function_exists('probit_customize_register')) {

    /**
     * Register postMessage support.
     *
     * Add postMessage support for site title and description for the Customizer.
     *
     * @param WP_Customize_Manager $wp_customize Customizer object.
     */
    function probit_customize_register($wp_customize) {
        $wp_customize->get_setting('blogname')->transport = 'postMessage';
        $wp_customize->get_setting('blogdescription')->transport = 'postMessage';
        $wp_customize->get_setting('header_textcolor')->transport = 'postMessage';
        $wp_customize->get_setting('header_textcolor')->default = '#444444';
    }

}
add_action('customize_register', 'probit_customize_register');

if (!function_exists('probit_customize_preview_js')) {

    /**
     * Enqueue Javascript postMessage handlers for the Customizer.
     *
     * Binds JS handlers to make the Customizer preview reload changes asynchronously.
     *
     *
     */
    function probit_customize_preview_js() {
        wp_enqueue_script('probit-customizer', get_template_directory_uri() . '/js/probit-theme-customizer.js', array('customize-preview'), '20130301', true);
    }

}
add_action('customize_preview_init', 'probit_customize_preview_js');

if (!function_exists('probit_add_body_class')) {
    /*
     * Use filter to Add "sticky-header" class to body for sticky menu.
     */

    function probit_add_body_class($classes) {
        $classes[] = 'sticky-header';
        return $classes;
    }

}
add_filter('body_class', 'probit_add_body_class');

/*
 * Add function "probit_paging_nav" to create probit theme pagination
 *
 * @uses probit_paging_nav() To get the Google Font stylesheet URL.
 *
 * @since Probit 1.0
 *
 * @param integer $mid_size.
 * @return string pagination with HTML.
 */
if (!function_exists('probit_paging_nav')) :

    function probit_paging_nav($mid_size = 1) {
        // Don't print empty markup if there's only one page.
        if ($GLOBALS['wp_query']->max_num_pages < 2) {
            return;
        }

        $paged = get_query_var('paged') ? intval(get_query_var('paged')) : 1;
        $pagenum_link = html_entity_decode(get_pagenum_link());
        $query_args = array();
        $url_parts = explode('?', $pagenum_link);

        if (isset($url_parts[1])) {
            wp_parse_str($url_parts[1], $query_args);
        }

        $pagenum_link = remove_query_arg(array_keys($query_args), $pagenum_link);
        $pagenum_link = trailingslashit($pagenum_link) . '%_%';

        $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && !strpos($pagenum_link, 'index.php') ? 'index.php/' : '';
        $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit('page/%#%', 'paged') : '?paged=%#%';

        // Set up paginated links.
        $links = paginate_links(array(
            'base' => $pagenum_link,
            'format' => $format,
            'total' => $GLOBALS['wp_query']->max_num_pages,
            'current' => $paged,
            'mid_size' => $mid_size,
            'add_args' => array_map('urlencode', $query_args),
            'prev_text' => '&laquo;',
            'next_text' => '&raquo;',
        ));
        if ($links) :
            ?>
            <nav class="navigation paging-navigation" role="navigation">
                <h1 class="screen-reader-text"><?php _e('Posts navigation', 'probit'); ?></h1>
                <div class="pagination loop-pagination">
                    <?php echo $links; ?>
                </div><!-- .pagination -->
            </nav><!-- .navigation -->
            <?php
        endif;
    }

endif;

/*
 * Print HTML with meta information for the current post-date/time and author.
 */
if (!function_exists('probit_posted_on')) :

    function probit_posted_on() {
        if (is_sticky() && is_home() && !is_paged()) {
            echo '<span class="featured-post">' . __('Sticky', 'probit') . '</span>';
        }
        $archive_year = get_the_time('Y');
        $archive_month = get_the_time('m');
        $archive_day = get_the_time('d');
        // Set up and print post meta information.
        printf('<span class="entry-date"><i class="fa fa-calendar"></i><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s">%3$s</time></a></span> <span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="%4$s" rel="author">%5$s</a></span></span>', esc_url(get_day_link($archive_year, $archive_month, $archive_day)), esc_html(get_the_date('c')), esc_html(get_the_date()), esc_url(get_author_posts_url(get_the_author_meta('ID'))), get_the_author()
        );
    }

endif;

/*
 * fuction to display team
 * @return string $data to display our team posts data.
 */
if (!function_exists('probit_ourTeamShortcodeFunction')) {

    function probit_ourTeamShortcodeFunction() {
        ob_start();
        global $wp_query, $post;
        $post_id_page = $post->ID;
        $port_cat = esc_attr(get_theme_mod('team_cat'));
        if ($port_cat != 0) {
            $cat_display_array = probit_get_subcat_ids($port_cat);
            $categories = get_categories(array('child_of' => $port_cat));
            $args = array('order_by' => 'date', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
            $loop = new WP_Query($args);
            if ($loop->have_posts()) {
                ?>
                <div class="slide team-back">
                    <div class="container">
                        <div class="row">
                            <div class="title_heading">
                                <h2 class="text-center"><?php _e('Our Team', 'probit'); ?></h2>
                                <span></span>
                            </div>
                            <div class="col-xs-12">
                                <div class="filter_ourteam">
                                    <ul class="list-inline" id="ourteam_category_menu_ul">
                                        <li id="ourteam_category_menu_Showall" class="show_all text-capitalize">
                                            <a class="category_menu_selected" href="#show_all"><?php _e('Show All', 'probit'); ?></a>
                                        </li>
                                        <?php
                                        if (is_array($categories) && !empty($categories)) {
                                            foreach ($categories as $category) {
                                                ?>
                                                <li data-filter=".<?php echo $category->slug; ?>" class="<?php echo $category->slug; ?> text-capitalize">
                                                    <a href="#<?php echo $category->slug; ?>"><?php echo $category->name; ?></a>
                                                </li>
                                                <?php
                                            }
                                        }
                                        ?>
                                    </ul>
                                </div>
                            </div>
                            <div class="isotope1 our-team col-md-12 col-xs-12 col-sm-12 padding_0">
                                <?php
                                while ($loop->have_posts()) : $loop->the_post();
                                    $terms = wp_get_post_terms(get_the_ID(), 'category');
                                    $termslug = '';
                                    foreach ($terms as $term) {
                                        $termslug .= $term->slug . ' ';
                                    }
                                    ?>
                                    <div class="col-md-4 col-sm-4 col-xs-6 <?php echo $termslug; ?> team_single">
                                        <div class="portfolio_content">
                                            <?php
                                            if (has_post_thumbnail())
                                                the_post_thumbnail('probit-portfolio-slider-img');
                                            else
                                                echo '<img alt="' . esc_attr(get_the_title()) . '" src="' . esc_url(get_template_directory_uri() . '/images/no_image_370.png') . '" />';
                                            ?>
                                            <div class="effect_portfolio"></div>
                                            <div class="port_content team-content">
                                                <h3><a href='<?php the_permalink(); ?>' class="text-capitalize"><?php the_title(); ?></a></h3>
                                                <div class="portfolio-tag text-capitalize">
                                                    <?php
                                                    $separtor = ' ';
                                                    // get lists of term associated in the current post type
                                                    $terms = get_the_terms(get_the_ID(), 'category');
                                                    if ($terms) {
                                                        foreach ($terms as $term) {
                                                            // get term link, the function name explain it
                                                            $term_link = get_term_link($term, 'category');

                                                            // the function explain its purpose
                                                            if (is_wp_error($term_link))
                                                                continue;

                                                            // display term name with link
                                                            echo $separtor . '<span>' . $term->name . '</span>';
                                                            $separtor = '<span>, </span>';
                                                        }
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <?php
                                endwhile;
                                wp_reset_postdata();
                                ?>
                            </div>
                        </div><!-- .row -->
                    </div>
                </div>
                <?php
            }
        }
        $data = ob_get_clean();
        return $data;
    }

}

/*
 * function to display our client data
 *
 * @return string $data to display our team posts data.
 */
if (!function_exists('probit_ourClientDisplayfunction')) {

    function probit_ourClientDisplayfunction() {
        ob_start();
        global $wpdb, $wp_query;
        $port_cat = esc_attr(get_theme_mod('client_cat'));
        if ($port_cat != 0) {
            $cat_display_array = probit_get_subcat_ids($port_cat);
            $args = array('order_by' => 'date', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
            $loop = new WP_Query($args);
            if ($loop->have_posts()) {
                ?>
                <div class="col-xs-12 ourclient_wrapper">
                    <div class='row'>
                        <div class="title_heading">
                            <h2 class="text-center"><?php _e('Our Clients', 'probit'); ?></h2>
                            <span></span>
                        </div>
                        <div class="ourclient_slider col-xs-12 padding_0">
                            <div class="our_client_div">
                                <?php
                                while ($loop->have_posts()) : $loop->the_post();
                                    ?>
                                    <div class="col-md-2">
                                        <?php the_post_thumbnail('probit-client-logo'); ?>
                                    </div>
                                    <?php
                                endwhile;
                                wp_reset_postdata();
                                ?>
                            </div>
                        </div>
                    </div>
                </div>
                <?php
            }
            $clientData = ob_get_clean();
            return $clientData;
        }
    }

}

/*
 * function to display testimonials data.
 * @return string $data to display testimonials posts data.
 */
if (!function_exists('probit_testimonialDisplayfunction')) {

    function probit_testimonialDisplayfunction() {
        ob_start();
        global $wpdb, $wp_query;
        $port_cat = esc_attr(get_theme_mod('testimonial_cat'));
        if ($port_cat != 0) {
            $cat_display_array = probit_get_subcat_ids($port_cat);
            $categories = get_categories(array('child_of' => $port_cat));
            $args = array('order_by' => 'date', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
            $loop = new WP_Query($args);
            if ($loop->have_posts()) {
                ?>
                <div class="test_div_bg">
                    <div class="colo-bg">
                        <div class="title_heading">
                            <h2 class="text-center"><?php _e('Testimonials', 'probit'); ?></h2>
                            <span></span>
                        </div>
                        <div class="testimonial_slider_div">
                            <div id='testimonial_slider'>
                                <?php
                                while ($loop->have_posts()) : $loop->the_post();
                                    ?>
                                    <div class="col-xs-12 col-sm-12 col-md-12 padding_0">
                                        <div class="col-xs-12 col-sm-3 col-md-2 testimonial_img">
                                            <a href="<?php echo esc_url(home_url() . '/testimonial'); ?>">
                                                <?php
                                                if (has_post_thumbnail())
                                                    the_post_thumbnail('probit-testimonial-slider-img');
                                                else
                                                    echo '<img alt="' . esc_attr(get_the_title()) . '" src="' . esc_url(get_template_directory_uri() . '/images/no_image_150.png') . '" />';
                                                ?>
                                            </a>
                                        </div>
                                        <div class="col-sm-9 col-xs-12 col-md-10 test_content_div">
                                            <?php the_excerpt(); ?>
                                        </div>
                                        <a class="text-right testimonial_title" href="<?php echo esc_url(home_url() . '/testimonial'); ?>">
                                            <?php the_title(); ?>
                                        </a>
                                    </div>
                                    <?php
                                endwhile;
                                ?>
                            </div>
                            <div class="clearfix"></div>
                            <div id="paginatecircle" class="paginatecircle" data-moveby="1"></div>
                        </div><!-- .color-bg -->
                    </div>
                </div>
                <?php
            }
            wp_reset_postdata();
            $clientData = ob_get_clean();
            return $clientData;
        }
    }

}

/**
 * Register theme supported plugins
 */
get_template_part('inc/register', 'plugins');

/*
 * Add action "customize_register" to add theme color option at admin side.
 */
if (!function_exists('probit_add_theme_color_option')) {

    function probit_add_theme_color_option($wp_customize) {

        // add color picker setting
        $wp_customize->add_setting('theme_color', array(
            'default' => '#1E73BE',
            'sanitize_callback' => 'sanitize_hex_color'
        ));
        $wp_customize->add_setting('content_color', array(
            'default' => '#333333',
            'sanitize_callback' => 'sanitize_hex_color'
        ));
        // add color picker control to colors setting
        $wp_customize->add_control(
                new WP_Customize_Color_Control(
                $wp_customize, 'theme_color', array(
            'label' => __('Theme Color', 'probit'),
            'section' => 'colors',
            'settings' => 'theme_color')
        ));

        $wp_customize->add_control(
                new WP_Customize_Color_Control(
                $wp_customize, 'content_color', array(
            'label' => __('Content Color', 'probit'),
            'section' => 'colors',
            'settings' => 'content_color')
        ));

        /* Theme Option Panel */
        $wp_customize->add_panel('probit_panel_id', array(
            'priority' => 10,
            'capability' => 'edit_theme_options',
            'theme_supports' => '',
            'title' => __('Theme Options', 'probit'),
            'description' => __('Use the options below to customize your theme!', 'probit'),
        ));


        /* General Settings */
        $wp_customize->add_section('general_setting_section', array(
            'priority' => 10,
            'capability' => 'edit_theme_options',
            'theme_supports' => '',
            'title' => __('General Settings', 'probit'),
            'description' => 'Manage your website\'s Breadcrumbs and social media links.',
            'panel' => 'probit_panel_id',
        ));

        $wp_customize->add_setting('enable_breadcrumbs', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'probit_sanitize_checkbox'
        ));

        $wp_customize->add_control('enable_breadcrumbs', array(
            'settings' => 'enable_breadcrumbs',
            'label' => __("Enable Breadcrumbs ?", "probit"),
            'section' => 'general_setting_section',
            'type' => 'checkbox',
            'priority' => 2
        ));

        $social_sites = probit_get_social_media_array();
        $priority = 10;
        $email_note = $socialNewName = $socialDescName = "";
        foreach ($social_sites as $social_site) {
            $esc_url_raw = 'esc_url_raw';
            if ($social_site['iconname'] == 'email') {
                $esc_url_raw = 'sanitize_email';
            }
            $socialName = $social_site['iconname'];
            if ($socialName == "facebook") {
                $socialNewName = __("Facebook URL", 'probit');
            } else if ($socialName == "twitter") {
                $socialNewName = __("Twitter URL", 'probit');
            } else if ($socialName == "email") {
                $socialNewName = __("Email Address", 'probit');
            } else if ($socialName == "pinterest") {
                $socialNewName = __("Pinterest URL", 'probit');
            } else if ($socialName == "googleplus") {
                $socialNewName = __("Google+ URL", 'probit');
            } else if ($socialName == "rssfeed") {
                $socialNewName = __("RSS Feed URL", 'probit');
            } else if ($socialName == "instagram") {
                $socialNewName = __("Instagram URL", 'probit');
            } else if ($socialName == "linkedin") {
                $socialNewName = __("LinkedIn URL", 'probit');
            } else if ($socialName == "youtube") {
                $socialNewName = __("Youtube URL", 'probit');
            } else if ($socialName == "flicker") {
                $socialNewName = __("Flickr URL", 'probit');
            }

            if ($socialName == "email") {
                $email_note = '<b>' . __('Note', 'probit') . '</b> : ' . __('Use mail to function in email address', 'probit');
            } else {
                $email_note = '';
            }

            $wp_customize->add_setting("$socialName", array(
                'type' => 'theme_mod',
                'transport' => 'postMessage',
                'capability' => 'edit_theme_options',
                'sanitize_callback' => $esc_url_raw
            ));

            $wp_customize->add_control("$socialName", array(
                'label' => $socialNewName,
                'section' => 'general_setting_section',
                'type' => 'text',
                'priority' => $priority,
                'description' => __('Enter your ', 'probit') . $socialNewName . '.<br/> ' . $email_note
            ));

            $priority = $priority + 5;
        }

        // Icon Shape Select control
        $wp_customize->add_setting('iconshape', array(
            'default' => 'circle',
            'sanitize_callback' => 'esc_attr'
        ));
        $shape = array('circle' => __('Circle', 'probit'), 'square' => __('Square', 'probit'));
        $wp_customize->add_control('shape_setting', array(
            'label' => __('Icon Shape', 'probit'),
            'section' => 'general_setting_section',
            'settings' => 'iconshape',
            'type' => 'select',
            'choices' => $shape,
            'priority' => 60,
            'description' => __('Select icon shape', "probit")
        ));

        /* Header Settings */
        /* Home Settings */
        $wp_customize->add_section('home_setting_section', array(
            'priority' => 14,
            'capability' => 'edit_theme_options',
            'theme_supports' => '',
            'title' => __('Home Page Settings', 'probit'),
            'description' => __('Manage home page settings', 'probit'),
            'panel' => 'probit_panel_id',
        ));

        // Home Page Slider Select control
        // Get all Avartan slider to create option for sliders
        global $wpdb;
        $avartanTable = $wpdb->prefix . 'avartan_sliders';
        if ($wpdb->get_var("SHOW TABLES LIKE '$avartanTable'") == $avartanTable) {
            $avartanSliders = $wpdb->get_results("SELECT * FROM $avartanTable");
            $sliderArray = array();
            $latest_slider_id = 0;
            $sliderArray[0] = __('Select Slider', 'probit');
            // get all slider array to display dropdown option
            foreach ($avartanSliders as $key => $avartanSlider) {
                $sliderArray[$avartanSlider->id] = $avartanSlider->name;
            }
            $sliderArrayCount = sizeof($sliderArray);
            if ($sliderArrayCount > 1) {
                $wp_customize->add_setting('homepage_avartan_slider', array(
                    'default' => $latest_slider_id,
                    'sanitize_callback' => 'esc_attr'
                ));
                $wp_customize->add_control('slider_control_setting', array(
                    'label' => __('Home Page Slider', 'probit'),
                    'section' => 'home_setting_section',
                    'settings' => 'homepage_avartan_slider',
                    'type' => 'select',
                    'choices' => $sliderArray,
                    'priority' => 5,
                    'description' => __('Select Home Page Slider', 'probit')
                ));
            }
        }

        /* box 1 */
        $wp_customize->add_setting('home_below_slider_box1_title', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box1_setting', array(
            'label' => __('Box 1 - Title', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box1_title',
            'type' => 'text',
            'description' => __('Enter title you want to show with image.', "probit") . '<br />' . __('eg: Clean Design', "probit"),
            'priority' => 7
        ));
        $wp_customize->add_setting('block1icon', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box1_icon_setting', array(
            'label' => __('Box 1 - Icon', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'block1icon',
            'type' => 'text',
            'description' => __("Choose ", "probit") . " <a href='" . esc_url('https://fortawesome.github.io/Font-Awesome/icons/') . "' target='_blank'>fontawesome icon</a> " . __(' that you want to show with image.', 'probit') . '<br/> eg: fa fa-pencil',
            'priority' => 9
        ));
        $wp_customize->add_setting('home_below_slider_box1_link', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'esc_url'
        ));
        $wp_customize->add_control('box1_title_setting', array(
            'label' => __('Box 1 - Title URL', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box1_link',
            'type' => 'text',
            'description' => __("Enter the URL of Box 1.", "probit") . '<br/> eg: ' . esc_url('http://www.domain.com/yourpage.'),
            'priority' => 11
        ));
        $wp_customize->add_setting('home_below_slider_box1_link_open', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'probit_sanitize_checkbox'
        ));

        $wp_customize->add_control('box1_open_link', array(
            'settings' => 'home_below_slider_box1_link_open',
            'label' => __("Link Open in New Window (Box 1) ?", "probit"),
            'section' => 'home_setting_section',
            'type' => 'checkbox',
            'priority' => 13
        ));

        /* box 2 */
        $wp_customize->add_setting('home_below_slider_box2_title', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box2_setting', array(
            'label' => __('Box 2 - Title', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box2_title',
            'type' => 'text',
            'description' => __('Enter title you want to show with image.', "probit") . '<br/>' . __('eg: Responsive', "probit"),
            'priority' => 15
        ));
        $wp_customize->add_setting('block2icon', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box2_icon_setting', array(
            'label' => __('Box 2 - Icon', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'block2icon',
            'description' => __("Choose", "probit") . " <a href='" . esc_url('https://fortawesome.github.io/Font-Awesome/icons/') . "' target='_blank'>fontawesome icon</a> " . __('that you want to show with image.', 'probit') . '<br/> eg: fa fa-mobile-phone',
            'priority' => 17
        ));
        $wp_customize->add_setting('home_below_slider_box2_link', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'esc_url'
        ));
        $wp_customize->add_control('box2_title_setting', array(
            'label' => __('Box 2 - Title URL', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box2_link',
            'type' => 'text',
            'description' => __("Enter the URL of Box 2.", "probit") . '<br/> eg: ' . esc_url("http://www.domain.com/yourpage."),
            'priority' => 19
        ));
        $wp_customize->add_setting('home_below_slider_box2_link_open', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'probit_sanitize_checkbox'
        ));

        $wp_customize->add_control('box2_open_link', array(
            'settings' => 'home_below_slider_box2_link_open',
            'label' => __("Link Open in New Window (Box 2) ?", "probit"),
            'section' => 'home_setting_section',
            'type' => 'checkbox',
            'priority' => 21
        ));

        /* box 3 */
        $wp_customize->add_setting('home_below_slider_box3_title', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box3_setting', array(
            'label' => __('Box 3 - Title', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box3_title',
            'type' => 'text',
            'description' => __('Enter title you want to show with image.', "probit") . '<br />' . __('eg: Tons of Options', "probit"),
            'priority' => 23
        ));
        $wp_customize->add_setting('block3icon', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box3_icon_setting', array(
            'label' => __('Box 3 - Icon', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'block3icon',
            'description' => __("Choose", "probit") . " <a href='" . esc_url('https://fortawesome.github.io/Font-Awesome/icons/') . "' target='_blank'>fontawesome icon</a> " . __('that you want to show with image.', 'probit') . '<br/> eg: fa fa-gears',
            'priority' => 25
        ));
        $wp_customize->add_setting('home_below_slider_box3_link', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'esc_url'
        ));
        $wp_customize->add_control('box3_title_setting', array(
            'label' => __('Box 3 - Title URL', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box3_link',
            'type' => 'text',
            'description' => __("Enter the URL of Box 3.", "probit") . '<br/> eg: ' . esc_url('http://www.domain.com/yourpage.'),
            'priority' => 27
        ));
        $wp_customize->add_setting('home_below_slider_box3_link_open', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'probit_sanitize_checkbox'
        ));

        $wp_customize->add_control('box3_open_link', array(
            'settings' => 'home_below_slider_box3_link_open',
            'label' => __("Link Open in New Window (Box 3) ?", "probit"),
            'section' => 'home_setting_section',
            'type' => 'checkbox',
            'priority' => 29
        ));

        /* box 4 */
        $wp_customize->add_setting('home_below_slider_box4_title', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box4_setting', array(
            'label' => __('Box 4 - Title', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box4_title',
            'type' => 'text',
            'description' => __('Enter title you want to show with image.', "probit") . '<br />' . __('eg: Wide Audience', "probit"),
            'priority' => 31
        ));
        $wp_customize->add_setting('block4icon', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'sanitize_text_field'
        ));
        $wp_customize->add_control('box4_icon_setting', array(
            'label' => __('Box 4 - Icon', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'block4icon',
            'description' => __("Choose", "probit") . " <a href='" . esc_url('https://fortawesome.github.io/Font-Awesome/icons/') . "' target='_blank'>fontawesome icon</a> " . __('that you want to show with image. eg: fa fa-bullhorn', 'probit'),
            'priority' => 33
        ));
        $wp_customize->add_setting('home_below_slider_box4_link', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'esc_url'
        ));
        $wp_customize->add_control('box4_title_setting', array(
            'label' => __('Box 4 - Title URL', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'home_below_slider_box4_link',
            'type' => 'text',
            'description' => __("Enter the URL of Box 4.", "probit") . '<br/> eg: ' . esc_url('http://www.domain.com/yourpage.'),
            'priority' => 35
        ));
        $wp_customize->add_setting('home_below_slider_box4_link_open', array(
            'type' => 'theme_mod',
            'capability' => 'edit_theme_options',
            'sanitize_callback' => 'probit_sanitize_checkbox'
        ));

        $wp_customize->add_control('box4_open_link', array(
            'settings' => 'home_below_slider_box4_link_open',
            'label' => __("Link Open in New Window (Box 4) ?", "probit"),
            'section' => 'home_setting_section',
            'type' => 'checkbox',
            'priority' => 37
        ));

        $port_cat_list[0] = __('Select Portfolio Category', "probit");
        $team_cat_list[0] = __('Select Our Team Category', "probit");
        $testimonial_cat_list[0] = __('Select Testimonial Category', "probit");
        $our_client[0] = __('Select Our Client Category', "probit");
        $port_child_cat = get_categories();
        if (is_array($port_child_cat) && !empty($port_child_cat)) {
            foreach ($port_child_cat as $port_child_cat_s) {
                $port_cat_list[$port_child_cat_s->term_id] = $team_cat_list[$port_child_cat_s->term_id] = $testimonial_cat_list[$port_child_cat_s->term_id] = $our_client[$port_child_cat_s->term_id] = $port_child_cat_s->name;
            }
        }

        // Portfolio Select control
        $wp_customize->add_setting('port_cat', array(
            'default' => '0',
            'sanitize_callback' => 'esc_attr'
        ));
        $wp_customize->add_control('portfolio_setting', array(
            'label' => __('Portfolio Category', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'port_cat',
            'type' => 'select',
            'choices' => $port_cat_list,
            'priority' => 40,
            'description' => __('Select category for Portfolio', "probit")
        ));

        // Our Team Select control
        $wp_customize->add_setting('team_cat', array(
            'default' => '0',
            'sanitize_callback' => 'esc_attr'
        ));
        $wp_customize->add_control('ourteam_setting', array(
            'label' => __('Our Team Category', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'team_cat',
            'type' => 'select',
            'choices' => $team_cat_list,
            'priority' => 41,
            'description' => __('Select category for Our Team', "probit")
        ));

        // Our Team Select control
        $wp_customize->add_setting('testimonial_cat', array(
            'default' => '0',
            'sanitize_callback' => 'esc_attr'
        ));
        $wp_customize->add_control('testimonial_setting', array(
            'label' => __('Testimonial Category', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'testimonial_cat',
            'type' => 'select',
            'choices' => $testimonial_cat_list,
            'priority' => 42,
            'description' => __('Select category for Our Testimonial', "probit")
        ));

        // Our Client Select control
        $wp_customize->add_setting('client_cat', array(
            'default' => '0',
            'sanitize_callback' => 'esc_attr'
        ));
        $wp_customize->add_control('ourclient_setting', array(
            'label' => __('Our Client Category', 'probit'),
            'section' => 'home_setting_section',
            'settings' => 'client_cat',
            'type' => 'select',
            'choices' => $our_client,
            'priority' => 43,
            'description' => __('Select category for Our Client', "probit")
        ));
        /* Home Settings */
    }

}
add_action('customize_register', 'probit_add_theme_color_option');

if (!function_exists('probit_sanitize_checkbox')) {

    /**
     * Sanitize a checkbox setting.
     */
    function probit_sanitize_checkbox($value) {
        if ($value == 1) {
            return 1;
        } else {
            return '';
        }
    }

}

if (!function_exists('probit_kses_html')) {

    /**
     * Allow HTML for textarea
     * @param string $value
     * @return string $value
     */
    function probit_kses_html($value) {
        return wp_kses($value, wp_kses_allowed_html('entities'));
    }

}

if (!function_exists('probit_new_excerpt_more')) {

    /* Changes excerpt length */

    function probit_new_excerpt_more($more) {
        if (!is_admin()) {
            $more = ' &hellip;';
        }
        return $more;
    }

}
add_filter('excerpt_more', 'probit_new_excerpt_more');

// wherever you hook into admin screen:
if (!function_exists('probit_theme_option_page')) {

    /**
     * Probit Theme option page
     */
    function probit_theme_option_page() {
        echo '<div id="thinkup-theme-options-moved" style="background: #fff;padding: 20px;margin-top: 20px;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;-ms-box-sizing: border-box;-o-box-sizing: border-box;box-sizing: border-box;border: 1px solid #dadada;max-width: 800px;">';
        echo '<h2 style="margin: 0 0 20px;border-bottom: 1px solid #ddd;padding-bottom: 20px;text-transform: uppercase;font-size: 25px;">' . __('New Theme Options Panel', 'probit') . '</h2>';
        echo '<p style="font-size: 16px;">' . __('We have made a major update to the theme options panel to comply with the new WordPress.org guidelines which state that all theme options must be in the customizer. From October 21st 2015 all new themes and theme updates are required to remove any options panels and instead add all options to the WordPress Customizer.', 'probit') . '</p><h3 style="font-size: 18px;">' . __('Where are the new theme options?', 'probit') . '</h3><p style="font-size: 16px;">' . __('We are glad you asked! All of the work you did using the theme options panel can now be found in the customizer. You can find this in the left-hand side menu under', 'probit') . ' <b>' . __('Appearance', 'probit') . ' &raquo; ' . __('Customize', 'probit') . '</b>.</p>';
        echo '<p style="font-size: 16px;"><img src="' . esc_url(get_template_directory_uri() . '/images/theme_option.png') . '" style="border: 1px solid #ddd;"></p>';
        echo '<h3 style="font-size: 18px;">' . __('Have I lost my previous work?', 'probit') . '</h3>';
        echo '<p style="font-size: 16px;">' . __('Absolutely not. We have taken care of everything for you. All of the work that you did in the theme options panel has now been automatically migrated to the customizer. So you can simply continue from where you left off.', 'probit') . '</p>';
        echo '</div>';
    }

}

if (!function_exists('probit_theme_menu_page')) {

    /**
     * Add Theme option notice page
     */
    function probit_theme_menu_page() {
        add_theme_page(__('Theme Options', 'probit'), __('Theme Options', 'probit'), 'manage_options', 'probit-theme-options', 'probit_theme_option_page');
    }

}
add_action('admin_menu', 'probit_theme_menu_page');

/*
 * Includes Custom php files like custom posts, ourclients, shortcode and icon etc.
 */
get_template_part('inc/custom_post_type');
get_template_part('inc/breadcrumb');

if (!function_exists('probit_get_subcat_ids')) {

    function probit_get_subcat_ids($parent_cat) {
        $cat_display_array = array();
        $cat_display_array[] = $parent_cat;
        $categories = get_categories(array('child_of' => $parent_cat));
        if (is_array($categories) && !empty($categories)) {
            foreach ($categories as $category) {
                $cat_display_array[] = $category->term_id;
            }
        }
        return $cat_display_array;
    }

}

if (!function_exists('probit_get_social_media_array')) {

    /**
     * Get array of social site for icon links
     * @return string
     */
    function probit_get_social_media_array() {

        /* store social site names in array */
        $social_sites = array(
            array('iconname' => 'facebook'),
            array('iconname' => 'twitter'),
            array('iconname' => 'email'),
            array('iconname' => 'pinterest'),
            array('iconname' => 'googleplus'),
            array('iconname' => 'rssfeed'),
            array('iconname' => 'instagram'),
            array('iconname' => 'linkedin'),
            array('iconname' => 'youtube'),
            array('iconname' => 'flicker'),
        );
        return $social_sites;
    }

}

// avoid first time run the updater if user just switching on theme
if (!function_exists('probit_theme_version_update')) {

    function probit_theme_version_update() {
        global $wpdb;
        $table_name = $wpdb->prefix . "posts";
        $data_updated = $wpdb->query("UPDATE $table_name SET post_content = REPLACE(post_content, 'sol_accordian', 'sol_accordion')");
        $probit_current_version = get_option('probit_current_version');
        $theme_data = wp_get_theme();
        $probit_new_version = $theme_data->get('Version');
        if ($probit_current_version == '' || $probit_new_version > $probit_current_version) {
            update_option('probit_current_version', $probit_new_version);
        }
    }

}
add_action('after_switch_theme', 'probit_theme_version_update');

if (!function_exists('probit_header_style')) {

    /**
     * Styles the header image and text displayed on the blog.
     *
     * @see foodfork_custom_header_setup().
     */
    function probit_header_style() {
        // If the header text option is untouched, let's bail.
        if (display_header_text()) {
            return;
        }

        // If the header text has been hidden.
        ?>
        <style type="text/css" id="twentysixteen-header-css">
            .site-branding {
                margin: 0 auto 0 0;
            }

            .site-branding .site-title,
            .site-description {
                clip: rect(1px, 1px, 1px, 1px);
                position: absolute;
            }

        </style>
        <?php
    }

}

if (!function_exists('probit_blog_filter')) {

    function probit_blog_filter() {
        //Make array not in portfolio, team and testimonial
        $not_display_array = array();
        $port_cat = esc_attr(get_theme_mod('port_cat'));
        if ($port_cat != 0) {
            $port_child_cat = get_categories(array('child_of' => $port_cat));
            $not_display_array[] = $port_cat;
            if (is_array($port_child_cat) && !empty($port_child_cat)) {
                foreach ($port_child_cat as $port_child_cat_s) {
                    $not_display_array[] = $port_child_cat_s->term_id;
                }
            }
        }
        $team_cat = esc_attr(get_theme_mod('team_cat'));
        if ($team_cat != 0) {
            $team_child_cat = get_categories(array('child_of' => $team_cat));
            $not_display_array[] = $team_cat;
            if (is_array($team_child_cat) && !empty($team_child_cat)) {
                foreach ($team_child_cat as $team_child_cat_s) {
                    $not_display_array[] = $team_child_cat_s->term_id;
                }
            }
        }
        $testimonial_cat = esc_attr(get_theme_mod('testimonial_cat'));
        if ($testimonial_cat != 0) {
            $testimonial_child_cat = get_categories(array('child_of' => $testimonial_cat));
            $not_display_array[] = $testimonial_cat;
            if (is_array($testimonial_child_cat) && !empty($testimonial_child_cat)) {
                foreach ($testimonial_child_cat as $testimonial_child_cat_s) {
                    $not_display_array[] = $testimonial_child_cat_s->term_id;
                }
            }
        }
        $client_cat = esc_attr(get_theme_mod('client_cat'));
        if ($client_cat != 0) {
            $client_child_cat = get_categories(array('child_of' => $client_cat));
            $not_display_array[] = $client_cat;
            if (is_array($client_child_cat) && !empty($client_child_cat)) {
                foreach ($client_child_cat as $client_child_cat_s) {
                    $not_display_array[] = $client_child_cat_s->term_id;
                }
            }
        }
        return $not_display_array;
    }

}


/*
 * Home page Query filters
 */
if (!function_exists('probit_home_qfilter')) {

    function probit_home_qfilter($query) {
        if ($query->is_home() && $query->is_main_query()) {
            $not_display_array = probit_blog_filter();
            $query->set('category__not_in', $not_display_array);
        }
    }

}
add_action('pre_get_posts', 'probit_home_qfilter', 10);

/*
 * Blog page templates query filter
 */
if (!function_exists('probit_blog_2_qfilter')) {

    function probit_blog_2_qfilter($query) {
        if ($query->is_main_query() && (is_page_template('page-templates/blog_timeline.php') || is_page_template('page-templates/blog_fullwidth_2_column.php'))) {
            $not_display_array = probit_blog_filter();
            $query->set('category__not_in', $not_display_array);
            $query->set('pagename', '');
        }
    }

}
add_action('pre_get_posts', 'probit_blog_2_qfilter', 10);

if(!function_exists('probit_search_form')){
    function probit_search_form( $form ) {
        $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
                    <div>
                        <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label', 'probit' ) . '</label>
                        <input type="text" value="' . get_search_query() . '" name="s" id="s" />
                            <i class="fa fa-search"></i>
                        <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button', 'probit' ) .'" />
                    </div>
                </form>';
        return $form;
    }
    add_filter( 'get_search_form', 'probit_search_form', 99 );
}