HEX
Server: LiteSpeed
System: Linux spg20.cloudpowerdns.com 5.14.0-611.35.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 25 03:46:09 EST 2026 x86_64
User: carrerup (3153)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: /home/carrerup/.trash/techland/inc/template-functions.php
<?php
/**
 * Functions which enhance the theme by hooking into WordPress
*/


/*************************************************
## ADMIN NOTICES
*************************************************/


add_action('admin_notices', 'techland_theme_activation_notice');
function techland_theme_activation_notice() {
    if (get_user_meta(get_current_user_id(), 'techland-ignore-notice', true) == 'yes') {
        return;
    }
    $url = add_query_arg( 'techland-ignore-notice', 'techland_dismiss_admin_notices' );
    ?>
    <div class="updated notice notice-info is-dismissible techland-admin-notice">
        <p><?php echo esc_html__( 'If you need help about demodata installation, please read docs and ', 'techland' ); ?>
            <a target="_blank" href="<?php echo esc_url( 'https://techland.com/contact/' ); ?>"><?php echo esc_html__( 'Open a ticket', 'techland' ); ?></a>
            <?php echo esc_html__('or', 'techland'); ?>
            <a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html__( 'Dismiss this notice', 'techland' ); ?></a>
            <button type="button" class="notice-dismiss hide-admin-notice"><span class="screen-reader-text"></span></button>
        </p>
    </div>
    <?php
}


add_action('admin_init', 'techland_theme_activation_notice_ignore');
function techland_theme_activation_notice_ignore() {
    if (isset($_GET['techland-ignore-notice'])) {
        update_user_meta(get_current_user_id(), 'techland-ignore-notice', 'yes');
    }
}


/*************************************************
## MENU ADD FIRST AND LAST CLASSES
*************************************************/


add_filter( 'wp_nav_menu_objects', 'techland_first_last_class_to_top_level_menu' );

function techland_first_last_class_to_top_level_menu( $objects ) {
    // add 'first' class to first element of menu items array
    if ( empty( $objects ) ){
        return;
    }

    $objects[1]->classes[] = 'nt-first-menu-item';
    // find array index of the last element of top level menu
    foreach($objects as $i=>$item) if($item->menu_item_parent==0) $last_top_level_menu_index = $i;
    // add 'last' class to the last element of top level menu
    $objects[$last_top_level_menu_index]->classes[] = 'nt-last-menu-item';
    return $objects;
}


/*************************************************
## DATA CONTROL FROM THEME-OPTIONS PANEL
*************************************************/


function techland_settings($opt_id, $def_value='')
{
    global $techland;

    $defval = '' != $def_value ? $def_value : false;
    $opt_id = trim($opt_id);
    $opt = isset($techland[$opt_id]) ? $techland[$opt_id] : $defval;

    if ( class_exists('Redux')) {
        return $opt;
    } else {
        return $defval;
    }
}

/*************************************************
## DATA CONTROL FROM PAGE METABOXES
*************************************************/

function techland_mbsettings($opt_id, $def_value='')
{

    $defval = '' != $def_value ? $def_value : '0';
    $opt_id = trim($opt_id);
    $opt = (class_exists('RWMB_Loader')) && isset( $opt_id ) ? rwmb_meta($opt_id) : $defval;

    return $opt;
}


/*************************************************
## SIDEBAR CONTROL
*************************************************/


function techland_sidebar_control($layout='', $default='', $sidebar='')
{
    global $techland;

    $layout = trim($layout);

    $sidebar = $sidebar != '' ? is_active_sidebar($sidebar) : is_active_sidebar('sidebar-1');

    $default = $default ? $default : 'right-sidebar';

    $layout = isset($techland[$layout]) ? $techland[$layout] : $default;

    $layout = $sidebar && $layout != 'full-width' ? 'col-12 col-lg-8 col-xl-9 pl-lg-10 pr-lg-10 nt-has-sidebar' : 'col-12 col-lg-8 nt-no-sidebar';

    return $layout;
}


/*************************************************
## SANITIZE MODIFIED VC-ELEMENTS OUTPUT
*************************************************/


if (!function_exists('techland_vc_sanitize_data')) {
    function techland_vc_sanitize_data($html_data)
    {
        return $html_data;
    }
}

/*************************************************
## VC COMPOSER PAGE CSS
*************************************************/
/*
*	get vc composer custom css from by page id
*	and add css to head by wp_head hook
*/
if( ! function_exists('techland_vc_inject_shortcode_css') )  {
    function techland_vc_inject_shortcode_css( $id ){
        $shortcodes_custom_css = get_post_meta( $id, '_wpb_shortcodes_custom_css', true );
        if ( ! empty( $shortcodes_custom_css ) ) {
            $shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
            echo '<style type="text/css" data-type="nt-shortcodes-custom-css-page-'.$id.'">';
            echo esc_attr( $shortcodes_custom_css );
            echo '</style>';
        }
    }
    add_action('wp_head', 'techland_vc_inject_shortcode_css');
}



/*************************************************
## VC COMPOSER SAVED TEMPLATE LIST
*************************************************/
if( ! function_exists('techland_vc_saved_template_list') )  {
    function techland_vc_saved_template_list()
    {

        $options = array();
        $saved_templates = get_option( 'wpb_js_templates' );
        if ( !empty($saved_templates) ) {
            foreach ( $saved_templates as $template => $key ) {
                $options[$template] = $key['name'];
            }
        }
        return $options;
    }
}


/*************************************************
## VC COMPOSER SAVED TEMPLATE CONTENT
*************************************************/
if( ! function_exists( 'techland_vc_print_saved_template' ) ) {

    function techland_vc_print_saved_template( $template_id = '')
    {
        $content  = '';
        if ( $template_id ) {
            $saved_templates = get_option( 'wpb_js_templates' );
            $content = trim( $saved_templates[ $template_id ][ 'template' ] );
            $content = str_replace( '\"', '"', $content );
            $pattern = get_shortcode_regex();
            $content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_shortcode', $content );
        }
        return do_shortcode( $content );
    }
}


/*************************************************
## PARSE VC COMPOSER SAVED TEMPLATE CONTENT CSS
*************************************************/
if( ! function_exists( 'techland_parse_shortcodes_template_css' ) ) {

    function techland_parse_shortcodes_template_css( $content )
    {

        $css = '';
        if ( ! preg_match( '/\s*(\.[^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $content ) ) {
            return $css;
        }

        preg_match_all( '/' . get_shortcode_regex() . '/', $content, $shortcodes );
        foreach ( $shortcodes[2] as $index => $tag ) {
            $shortcode = class_exists( 'WPBMap' ) ? WPBMap::getShortCode( $tag ) : '';
            $attr_array = shortcode_parse_atts( trim( $shortcodes[3][ $index ] ) );
            if ( isset( $shortcode['params'] ) && ! empty( $shortcode['params'] ) ) {
                foreach ( $shortcode['params'] as $param ) {
                    if ( isset( $param['type'] ) && 'css_editor' === $param['type'] && isset( $attr_array[ $param['param_name'] ] ) ) {
                        $css .= $attr_array[ $param['param_name'] ];
                    }
                }
            }
        }

        foreach ( $shortcodes[5] as $shortcode_content ) {
            $css .= techland_parse_shortcodes_template_css( $shortcode_content );
        }

        return $css;
    }
}


/*************************************************
## ADD HEAD VC COMPOSER SAVED TEMPLATE CONTENT CSS
*************************************************/
if( ! function_exists( 'techland_add_template_css_to_head' ) ) {
    function techland_add_template_css_to_head()
    {
        $template = array(
            techland_settings( 'vc_footer_templates' ),
            techland_settings( 'vc_header_templates' ),
            techland_settings( 'vc_before_header_templates' ),
            techland_settings( 'vc_after_header_templates' ),
            techland_settings( 'vc_before_index_templates' ),
            techland_settings( 'vc_after_index_templates' ),
            techland_settings( 'vc_before_single_templates' ),
            techland_settings( 'vc_after_single_templates' ),
            techland_settings( 'vc_before_archive_templates' ),
            techland_settings( 'vc_after_archive_templates' ),
            techland_settings( 'vc_before_search_templates' ),
            techland_settings( 'vc_after_search_templates' ),
            techland_settings( 'vc_before_shop_templates' ),
            techland_settings( 'vc_after_shop_templates' ),
            techland_settings( 'vc_before_singleshop_templates' ),
            techland_settings( 'vc_after_singleshop_templates' )
        );

        $saved_templates = get_option( 'wpb_js_templates' );
        $theCSS = '';

        if ( !empty( $template ) ) {
            foreach ( $template as $template_id ) {
                if ( $template_id ) {
                    $content = trim( $saved_templates[ $template_id ][ 'template' ] );
                    $content = str_replace( '\"', '"', $content );
                    $pattern = get_shortcode_regex();
                    $content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_shortcode', $content );
                    $theCSS .= techland_parse_shortcodes_template_css( $content );
                }
            }
            if ( !empty( $theCSS ) ) {
                wp_register_style( 'techland-vc-template-custom', false );
                wp_enqueue_style( 'techland-vc-template-custom' );
                wp_add_inline_style( 'techland-vc-template-custom', $theCSS );
            }
        }
    }
    add_action( 'wp_enqueue_scripts', 'techland_add_template_css_to_head' );
}




function techland_body_theme_classes($classes)
{
    $theme_name =  wp_get_theme();
    $theme_version =  'nt-version-' . wp_get_theme()->get('Version');
    $theme_page =  (! is_page_template('custom-page.php')) ? 'nt-body' : '';

    if (is_page()) {

        // page color styles
        $techland_page_clr = techland_mbsettings('techland_page_color_style', '1');
        if ($techland_page_clr != 'default' && $techland_page_clr != false ) {

            $classes[] = 'color-style-' .$techland_page_clr;
        }

    } else {

        $techland_clr = techland_settings( 'theme_color', '1' );
        if ($techland_clr != 'custom' || $techland_clr != 'default') {

            $classes[] = 'color-style-' .$techland_clr;
        }
    }

    $classes[] =  $theme_name;
    $classes[] =  $theme_version;
    $classes[] =  $theme_page;

    return $classes;

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


/*************************************************
## CUSTOM POST CLASS
*************************************************/

function techland_post_theme_class($classes)
{
    if ( ! is_single() AND ! is_page() ) {

        $masonry = ( 'masonry' == techland_settings( 'index_type', 'default' ) ) ? ' masonry-item ' : '';
        $format_box_type = techland_settings( 'format_box_type', '' );

        if ( 'masonry' == techland_settings( 'index_type', 'default' ) ) {
            $column = techland_settings( 'index_type_column', 'col-lg-6' );
        }

        $is_links = ( wp_link_pages('echo=0') ) ? ' nt-is-wp-link-pages ' : '';

        if ( 'masonry' == techland_settings( 'index_type', 'default' ) ) {
            $classes[] =  $column;
        }

        $classes[] =  $masonry;
        $classes[] =  $format_box_type;
        $classes[] =  $is_links;

    }

    $class = ' nt-post-class ';

    $classes[] =  $class;

    return $classes;

}
add_filter('post_class', 'techland_post_theme_class');


/*************************************************
## HEADER SEARCH FORM
*************************************************/

function techland_header_search_form()
{
    $form = '<form
    role="search"
    method="get"
    id="header-searchform"
    class="searchform"
    action="'.esc_url(home_url('/')).'">

		<input
        type="text"
        value="' . get_search_query() . '"
        name="s" id="hs"
        class="nt-header-form-search-field"
        placeholder="'.esc_attr__('Start Typing &amp; Press Enter ...', 'techland').'">

		<button type="button" class="nt-header-form-search-close"><span class="ion-ios-close-empty"></span></button>

	</form>';

    return $form;

}
add_filter('get_search_form', 'techland_header_search_form');


/*************************************************
## THEME SEARCH FORM
*************************************************/

function techland_content_custom_search_form()
{
    $form = '<div class="nt-sidebar-inner-search">
        <form class="nt-sidebar-inner-search-form searchform form--horizontal" role="search" method="get" id="widget-searchform"  action="' . esc_url(home_url('/')) . '" >
            <div class="row no-gutters">
                <div class="col-12 col-sm">
                    <div class="input-wrp">
                        <input class="nt-sidebar-inner-search-field textfield textfield--grey" type="text" value="' . get_search_query() . '" placeholder="'. esc_attr__('Search for...', 'techland') .'" name="s" id="ws" >
                    </div>
                </div>
                <div class="col-12 col-sm-auto">
                    <button class="nt-sidebar-inner-search-button custom-btn custom-btn--medium custom-btn--style-1" id="searchsubmit" type="submit">Search</button>
                </div>
            </div>
        </form>
    </div>';

    return $form;
}
add_filter('get_search_form', 'techland_content_custom_search_form');

/*************************************************
## THEME WOOCOMMERCE SEARCH FORM
*************************************************/

function techland_woo_content_custom_search_form()
{
    $form = '<div class="nt-sidebar-inner-search">
        <form class="nt-sidebar-inner-search-form searchform form--horizontal" role="search" method="get" id="widget-searchform"  action="' . esc_url(home_url('/')) . '" >
            <div class="row no-gutters">
                <div class="col-12 col-sm">
                    <div class="input-wrp">
                        <input class="nt-sidebar-inner-search-field textfield textfield--grey" type="text" value="' . get_search_query() . '" placeholder="'. esc_attr__('Search for...', 'techland') .'" name="s" id="ws" >
                        <input type="hidden" name="post_type" value="product" />
                    </div>
                </div>
                <div class="col-12 col-sm-auto">
                    <button class="nt-sidebar-inner-search-button custom-btn custom-btn--medium custom-btn--style-1" id="searchsubmit" type="submit">
                    <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                </div>
            </div>
        </form>
    </div>';

    return $form;
}
add_filter('get_product_search_form', 'techland_woo_content_custom_search_form');


/*************************************************
## THEME SEARCH FORM
*************************************************/

function techland_custom_search_form($form)
{
    $form = '<div class="nt-sidebar-inner-search">
        <form class="nt-sidebar-inner-search-form searchform form--horizontal" role="search" method="get" id="widget-searchform"  action="' . esc_url(home_url('/')) . '" >
            <div class="row no-gutters">
                <div class="col-12 col-sm">
                    <div class="input-wrp">
                        <input class="nt-sidebar-inner-search-field textfield textfield--grey" type="text" value="' . get_search_query() . '" placeholder="'. esc_attr__('Search for...', 'techland') .'" name="s" id="ws">
                    </div>
                </div>
                <div class="col-12 col-sm-auto">
                    <button class="nt-sidebar-inner-search-button custom-btn custom-btn--medium custom-btn--style-1" id="searchsubmit" type="submit" ><i class="fa fa-search" aria-hidden="true"></i></button>

                </div>
            </div>
        </form>
    </div>';

    return $form;
}
add_filter('get_search_form', 'techland_custom_search_form');




/*************************************************
## EXCERPT FILTER
*************************************************/

function techland_custom_excerpt_more($more)
{
    return '...';
}
add_filter('excerpt_more', 'techland_custom_excerpt_more');


/*************************************************
## EXCERPT LIMIT
*************************************************/

function techland_excerpt_limit($limit)
{

    $excerpt = explode(' ', get_the_excerpt(), $limit);

    if (count($excerpt) >= $limit) {
        array_pop($excerpt);
        $excerpt = implode(" ", $excerpt) . '...';
    } else {
        $excerpt = implode(" ", $excerpt);
    }

    $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);

    return $excerpt;

}

/*************************************************
## DEFAULT CATEGORIES WIDGET
*************************************************/

function techland_add_span_cat_count($links)
{

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

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

    return $links;

}
add_filter('wp_list_categories', 'techland_add_span_cat_count');


/*************************************************
## DEFAULT ARCHIVES WIDGET
*************************************************/

function techland_add_span_arc_count($links)
{

    $links = str_replace('</a>&nbsp;(', '</a> <span class="widget-list-span">', $links);
    $links = str_replace(')', '</span>', $links);

    // dropdown selectbox
    $links = str_replace('&nbsp;(', ' - ', $links);


    return $links;

}
add_filter('get_archives_link', 'techland_add_span_arc_count');


/*************************************************
## PAGINATION CUSTOMIZATION
*************************************************/

function techland_sanitize_pagination($content)
{

    // remove role attribute
    $content = str_replace('role="navigation"', '', $content);

    // remove h2 tag
    $content = preg_replace('#<h2.*?>(.*?)<\/h2>#si', '', $content);

    return $content;

}
add_action('navigation_markup_template', 'techland_sanitize_pagination');


/*************************************************
## CUSTOM ARCHIVE TITLES
*************************************************/

function techland_archive_title()
{

    $title = '';
    if (is_category()) {
        $title = single_cat_title('', false);
    } elseif (is_tag()) {
        $title = single_tag_title('', false);
    } elseif (is_author()) {
        $title = get_the_author();
    } elseif (is_year()) {
        $title = get_the_date(_x('Y', 'yearly archives date format', 'techland'));
    } elseif (is_month()) {
        $title = get_the_date(_x('F Y', 'monthly archives date format', 'techland'));
    } elseif (is_day()) {
        $title = get_the_date(_x('F j, Y', 'daily archives date format', 'techland'));
    } elseif (is_post_type_archive()) {
        $title = post_type_archive_title('', false);
    } elseif (is_tax()) {
        $title = single_term_title('', false);
    } else {
        $title = get_the_archive_title();
    }

    return $title;

}
add_filter('get_the_archive_title', 'techland_archive_title');



/*************************************************
## CHECKS TO SEE IF CPT EXISTS.
*************************************************/
/*
* By setting '_builtin' to false,
* we exclude the WordPress built-in public post types
* (post, page, attachment, revision, and nav_menu_item)
* and retrieve only registered custom public post types.
* return boolean
*/
function techland_cpt_exists()
{

    $args = array(
       'public'   => true,
       '_builtin' => false
    );

    $output = 'names'; // 'names' or 'objects' (default: 'names')
    $operator = 'and'; // 'and' or 'or' (default: 'and')

    $post_types = get_post_types( $args, $output, $operator ); // get simple cpt if exists
    $classes = get_body_class();
    $cpt_exsits = array();

    if ( $post_types ) {
        foreach ($post_types as $cpt ) {
            if ( is_single() ) {
                array_push($cpt_exsits, 'single-'.$cpt);
            }
            if ( is_archive() ) {
                array_push($cpt_exsits, 'post-type-archive-'.$cpt);
            }
        }
    }

    $sameclass = array_intersect( $cpt_exsits, $classes );

    if ( $sameclass ) {

        return true;

    }

    return false;
}

/*************************************************
## PARALLAX BG .
*************************************************/
/**
 * attributes
 * @var $parallax
 * @var $img
 * @var $type
 * @var $speed
 * @var $bgpos
 * @var $bgsize
 * @var $bgrepeat
 * @var $localvideo
 * @var $localtype
 * @var $localurl
 * @var $video
*/
function techland_parallax($parallax='',$img='',$type='',$speed='',$bgpos='',$bgsize='',$bgrepeat='',$localvideo='',$localtype='',$localurl='',$video='')
{

    if ($parallax == true || $parallax == '1') {
        wp_enqueue_script('jarallax');

        $attr[] = 'data-img-src="'.esc_attr($img).'"';
        $attr[] = 'data-type="'.esc_attr($type).'"';
        $attr[] = 'data-speed="'.esc_attr($speed).'"';
        $attr[] = 'data-img-position="'.esc_attr($bgpos).'"';
        $attr[] = 'data-img-size="'.esc_attr($bgsize).'"';
        $attr[] = 'data-img-repeat="'.esc_attr($bgrepeat).'"';

        if ($localvideo == true || $localvideo == '1') {
            if ($localtype == 'mp4') {
                $attr[] = $localurl ? 'data-jarallax-video="mp4:'.esc_url($localurl).'"' : '';
            }
            if ($localtype == 'webm') {
                $attr[] = $localurl ? 'data-jarallax-video="webm:'.esc_url($localurl).'"' : '';
            }
            if ($localtype == 'ogv') {
                $attr[] = $localurl ? 'data-jarallax-video="ogv:'.esc_url($localurl).'"' : '';
            }
        } else {
            $attr[] = $video ? 'data-jarallax-video="'.esc_url($video).'"' : '';
        }

        return implode(' ', $attr);
    }

    return false;
}


/*************************************************
## ROW SVG DIVIDER .
*************************************************/
/**
 * attributes
 * @var $dstyle svg element
 * @var $dwidth svg width properties
 * @var $dheight svg height properties
 * @var $dcolor svg color properties
 * @return $html
*/
if ( ! function_exists('techland_vc_row_divider') ) {

    function techland_vc_row_divider($atts=array(),$dstyle = '', $dheight = '', $dcolor = '', $dextra = false)
    {
        extract($atts);
		$html = '';
        $d_height = $dheight ? $dheight : '450';
        $d_color = $dcolor ? $dcolor : '#fff';

        if ($dstyle == 'type-1') {

            $html = '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="'.esc_attr($d_height).'" viewBox="0 0 1680 '.esc_attr($d_height).'" preserveAspectRatio="none" style="min-height: 180px"><path d="M0 3s561.937 57 842 55c286 0 484-18 839-58v'.esc_attr($d_height).'H-2z" style="mix-blend-mode:screen" fill="'.esc_attr($d_color).'" fill-rule="evenodd"></path></svg>';

        } elseif ($dstyle == 'type-2') {
            $html = '<svg width="100%" height="300px" viewBox="0 0 1280 '.esc_attr($d_height).'" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg" fill="'.esc_attr($d_color).'"><g><path d="M0 0l64.8 30.95 91.2-2.54 95.46 27.87 120.04.2L443 83.15l90.09-3.12L640 110.12l102.39-29.73 85.55 8.51 88.11-5.75L992 52.22l73.21 4.26L1132 38.79l77-.33L1280 0v'.esc_attr($d_height).'H0V0z" fill-opacity=".5"/><path d="M0 0l64.8 38.69 91.2-3.18 95.46 34.84 120.04.24 71.5 33.35 90.09-3.91L640 137.65l102.39-37.17 85.55 10.65 88.11-7.19L992 65.28l73.21 5.31 66.79-22.1 77-.41L1280 0v'.esc_attr($d_height).'H0V0z"/></g></svg>';
        } elseif ($dstyle == 'type-3') {

        }

        return '<div class="shape">'.$html.'</div>';

    }

}

/*************************************************
## POST THUMBNAIL CONTROL
*************************************************/

function techland_can_show_post_thumbnail()
{
    return apply_filters('techland_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail());
}


/*************************************************
## CHECKS TO SEE IF WE'RE ON THE HOMEPAGE OR NOT.
*************************************************/

function techland_is_frontpage()
{
    return ( is_front_page() && ! is_home() );
}


/*************************************************
## CONVERT HEX TO RGB
*************************************************/

 if (! function_exists('techland_hex2rgb')) {
     function techland_hex2rgb($hex)
     {
         $hex = str_replace("#", "", $hex);

         if (strlen($hex) == 3) {
             $r = hexdec(substr($hex, 0, 1).substr($hex, 0, 1));
             $g = hexdec(substr($hex, 1, 1).substr($hex, 1, 1));
             $b = hexdec(substr($hex, 2, 1).substr($hex, 2, 1));
         } else {
             $r = hexdec(substr($hex, 0, 2));
             $g = hexdec(substr($hex, 2, 2));
             $b = hexdec(substr($hex, 4, 2));
         }
         $rgb = array($r, $g, $b);

         return $rgb; // returns an array with the rgb values
     }
 }


/**********************************
## THEME ALLOWED HTML TAG
/**********************************/

if (! function_exists('techland_allowed_html')) {
    function techland_allowed_html()
    {
        $allowed_tags = array(
            'a' => array(
                'class' => array(),
                'href'  => array(),
                'rel'   => array(),
                'title' => array(),
                'target' => array(),
            ),
            'abbr' => array(
                'title' => array(),
            ),
            'iframe' => array(
                'src' => array(),
            ),
            'b' => array(),
            'br' => array(),
            'blockquote' => array(
                'cite'  => array(),
            ),
            'cite' => array(
                'title' => array(),
            ),
            'code' => array(),
            'del' => array(
                'datetime' => array(),
                'title' => array(),
            ),
            'dd' => array(),
            'div' => array(
                'class' => array(),
                'title' => array(),
                'style' => array(),
            ),
            'dl' => array(),
            'dt' => array(),
            'em' => array(),
            'h1' => array(),
            'h2' => array(),
            'h3' => array(),
            'h4' => array(),
            'h5' => array(),
            'h6' => array(),
            'i' => array(
                'class'  => array(),
            ),
            'img' => array(
                'alt'    => array(),
                'class'  => array(),
                'height' => array(),
                'src'    => array(),
                'width'  => array(),
            ),
            'li' => array(
                'class' => array(),
            ),
            'ol' => array(
                'class' => array(),
            ),
            'p' => array(
                'class' => array(),
            ),
            'q' => array(
                'cite' => array(),
                'title' => array(),
            ),
            'span' => array(
                'class' => array(),
                'title' => array(),
                'style' => array(),
            ),
            'strike' => array(),
            'strong' => array(),
            'ul' => array(
                'class' => array(),
            ),
        );
        return $allowed_tags;
    }
}


/*****************************************
## ADD COLORPICKER FOR ADD NEW CATGEGORY
/*****************************************/

/**
* Add new colorpicker field to "Add new Category" screen
* - https://developer.wordpress.org/reference/hooks/taxonomy_add_form_fields/
*/

function techland_colorpicker_field_add_new_category( $taxonomy ) {
    ?>
    <div class="form-field term-colorpicker-wrap">
        <label for="term-colorpicker"><?php echo esc_html_e('Category Color','techland'); ?></label>
        <input name="_category_color" value="#ffffff" class="colorpicker" id="term-colorpicker" />
        <p><?php echo esc_html_e('This is the field description where you can tell the user how the color is used in the theme.','techland'); ?></p>
    </div>
    <?php
}
add_action( 'category_add_form_fields', 'techland_colorpicker_field_add_new_category' );  // Variable Hook Name

/**
 * Add new colopicker field to "Edit Category" screen
 * - https://developer.wordpress.org/reference/hooks/taxonomy_add_form_fields/
 */

function techland_colorpicker_field_edit_category( $term ) {

  $color = get_term_meta( $term->term_id, '_category_color', true );
  $color = ( ! empty( $color ) ) ? "#{$color}" : '#ffffff';

?>

  <tr class="form-field term-colorpicker-wrap">
      <th scope="row"><label for="term-colorpicker"><?php echo esc_html_e('Category Color','techland'); ?></label></th>
      <td>
          <input name="_category_color" value="<?php echo esc_attr($color); ?>" class="colorpicker" id="term-colorpicker" />
          <p class="description"><?php echo esc_html_e('This is the field description where you can tell the user how the color is used in the theme.','techland'); ?></p>
      </td>
  </tr>

<?php
}
add_action( 'category_edit_form_fields', 'techland_colorpicker_field_edit_category' );   // Variable Hook Name


/**
 * Term Metadata - Save Created and Edited Term Metadata
 * - https://developer.wordpress.org/reference/hooks/created_taxonomy/
 * - https://developer.wordpress.org/reference/hooks/edited_taxonomy/
 */

function techland_save_termmeta( $term_id ) {

    // Save term color if possible
    if ( isset( $_POST['_category_color'] ) && ! empty( $_POST['_category_color'] ) ) {
        update_term_meta( $term_id, '_category_color', sanitize_hex_color_no_hash( $_POST['_category_color'] ) );
    } else {
        delete_term_meta( $term_id, '_category_color' );
    }
}
add_action( 'created_category', 'techland_save_termmeta' );  // Variable Hook Name
add_action( 'edited_category',  'techland_save_termmeta' );  // Variable Hook Name


/**
 * Enqueue colorpicker styles and scripts.
 * - https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/
 */

function techland_category_colorpicker_enqueue( $taxonomy ) {

    if ( null !== ( $screen = get_current_screen() ) && 'edit-category' !== $screen->id ) {
        return;
    }
    // Colorpicker Scripts
    wp_enqueue_script( 'wp-color-picker' );
    // Colorpicker Styles
    wp_enqueue_style( 'wp-color-picker' );

}
add_action( 'admin_enqueue_scripts', 'techland_category_colorpicker_enqueue' );

/**
* Print javascript to initialize the colorpicker
* - https://developer.wordpress.org/reference/hooks/admin_print_scripts/
*/
function techland_colorpicker_init_inline() {

    if( null !== ( $screen = get_current_screen() ) && 'edit-category' !== $screen->id ) {
        return;
    }
    ?>
    <script>
    jQuery( document ).ready( function( $ ) {
        $( '.colorpicker' ).wpColorPicker();
    } ); // End Document Ready JQuery
</script>
<?php
}
add_action( 'admin_print_scripts', 'techland_colorpicker_init_inline', 20 );


add_action('admin_notices', 'techland_notice_for_activation');
if (!function_exists('techland_notice_for_activation')) {
    function techland_notice_for_activation() {
        global $pagenow;

        if ( !get_option('envato_purchase_code_23965663') ) {

            echo '<div class="notice notice-warning">
                <p>' . sprintf(
                esc_html__( 'Enter your Envato Purchase Code to receive Theme and plugin updates %s', 'techland' ),
                '<a href="' . admin_url('admin.php?page=merlin&step=license') . '">' . esc_html__( 'Enter Purchase Code', 'techland' ) . '</a>') . '</p>
            </div>';
        }
    }
}

if ( !get_option('envato_purchase_code_23965663') ) {
    add_filter('auto_update_theme', '__return_false');
}

add_action('upgrader_process_complete', 'techland_upgrade_function', 10, 2);
if ( !function_exists('techland_upgrade_function') ) {
    function techland_upgrade_function($upgrader_object, $options) {
        $purchase_code = get_option('envato_purchase_code_23965663');

        if (($options['action'] == 'update' && $options['type'] == 'theme') && !$purchase_code) {
            wp_redirect(admin_url('admin.php?page=merlin&step=license'));
        }
    }
}

if ( !function_exists( 'techland_is_theme_registered') ) {
    function techland_is_theme_registered() {
        $purchase_code = get_option('envato_purchase_code_23965663');
        $registered_by_purchase_code = !empty($purchase_code);

        // Purchase code entered correctly.
        if ($registered_by_purchase_code) {
            return true;
        }
    }
}

function techland_deactivate_envato_plugin() {
    if (  function_exists( 'envato_market' ) && !get_option('envato_purchase_code_23965663') ) {
        deactivate_plugins('envato-market/envato-market.php');
    }
}
add_action( 'admin_init', 'techland_deactivate_envato_plugin' );