File: //home/madepabj/hc-cosmetics.com/wp-content/themes/dbea/functions.php
<?php
define( 'DBEA_THEME_DIR', get_template_directory() );
define( 'DBEA_THEME_URI', get_template_directory_uri() );
require_once( DBEA_THEME_DIR.'/framework/init.php' );
/**
* Initialize Visual Composer in the theme.
**/
add_action( 'vc_before_init', 'dbea_vc_setastheme' );
function dbea_vc_setastheme() {
if ( function_exists('vc_set_as_theme') ) vc_set_as_theme(true);
}
/**
* Width of content, it's max width of content without sidebar.
**/
if ( ! isset( $content_width ) ) { $content_width = 960; }
/**
* Set base function for theme.
**/
if ( ! function_exists( 'dbea_setup' ) ) {
function dbea_setup() {
global $dbea_opt;
// Load default theme textdomain.
load_theme_textdomain( 'dbea' , DBEA_THEME_DIR . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Enable support for Post Thumbnails on posts and pages.
add_theme_support( 'post-thumbnails' );
// Add title-tag, it auto title of head
add_theme_support( 'title-tag' );
// Enable support for Post Formats.
add_theme_support( 'post-formats',
array(
'video', 'quote', 'link', 'gallery'
)
);
// Register images size
add_image_size('dbea_blog_tiny_footer_thumb', 90, 70, true);
add_image_size('dbea_blog_tiny_thumb', 90, 90, true);
add_image_size('dbea_blog_small_thumb', 430, 280, true);
add_image_size('dbea_blog_large_thumb', 960, 480, true); //add_image_size('dbea_blog_large_thumb', 960, 545, true);
if ( class_exists('WooCommerce') ) {
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 315,
'gallery_thumbnail_image_width' => 145,
'single_image_width' => 640,
));
}
//Setup the WordPress core custom background & custom header feature.
$default_background = array(
'default-color' => '#FFF',
);
add_theme_support( 'custom-background', $default_background );
$default_header = array();
add_theme_support( 'custom-header', $default_header );
// Register navigations
register_nav_menus(
array(
'main_navigation' => __( 'Main navigation', 'dbea' ),
'user_navigation' => __( 'User navigation', 'dbea' ),
)
);
}
add_action ( 'after_setup_theme', 'dbea_setup' );
}
/**
Add class for body
**/
add_filter( 'body_class', 'dbea_bodyclass' );
function dbea_bodyclass( $classes ) {
$layouttype = dbea_layouttype('layouttype');
$classes[] = 'layout-type-'.$layouttype;
if ( $layouttype == 'l-m' && '' == dbea_get_sb('leftsidebar') ) {
$classes[] = 'no-leftcol';
}
if ( $layouttype == 'm-r' && '' == dbea_get_sb('rightsidebar') ) {
$classes[] = 'no-rightcol';
}
if( dbea_themeoption('advance_tooltip', 1) == 1){
$classes[] = 'use-tooltip';
}
if( dbea_getoption('use_stickmenu') == 1){
$classes[] = 'use_stickmenu';
}
if ( dbea_themeoption('woo_uselazyload', 0) == 1 ){
$classes[] = 'use_lazyload';
}
if ( is_404() ) {
$classes[] = 'page-404';
}
if ( is_page() && dbea_metabox('useslideshow') == 1 && dbea_metabox('revolutionslider') != '' ) {
$classes[] = 'use-slideshow';
}
if ( is_page() && dbea_metabox('page_class') != '' ) {
$classes[] = dbea_metabox('page_class');
}
$classes[] = 'header-'.dbea_getoption('header_style', 'style1');
$classes[] = 'footer-'.dbea_getoption('footer_layout', '1');
if ( dbea_getoption('enable_search_cat') == true ) $classes[] = 'enable-search-cat';
$breadcrumbbg = '';
if ( is_front_page() || is_404() ) {
$showbreadcrumb = '2';
}else{
$showbreadcrumb = dbea_getoption('showbreadcrump', '1');
$breadcrumbbg = dbea_getoption('breadcrumbbg', '', 'image');
}
if(class_exists('WooCommerce')){
global $product;
$classes[] = 'woocommerce';
if( is_product() && $product->get_type() === 'variable' && dbea_themeoption('woo_designvariations', 1) == 1 && dbea_getoption('use_variation_thumb', 1) == 1 ){
$classes[] = 'use-variation-thumb';
}
if( is_product() && dbea_getoption('woo_gallery_type', 'h') == 'n2' ){
$classes[] = 'use-gallery-type-n2';
}
if( is_product_category() ){
$showbreadcrumb = dbea_woo_cat_option('showbreadcrump');
$breadcrumbbg = dbea_woo_cat_option('breadcrumbbg', '', 'image');
}
}
$has_bgimg = true;
if ( class_exists('WooCommerce') && is_product() ) {
$has_bgimg = false;
}elseif ( is_singular('post') ) {
$has_bgimg = false;
}
if ( $showbreadcrumb == '2' ) {
$classes[] = 'no-breadcrumb';
}elseif ( $has_bgimg == true && $showbreadcrumb == '1' && !is_array($breadcrumbbg) && $breadcrumbbg != '' ) {
$classes[] = 'have-breadcrumb-img';
}
return $classes;
}
function dbea_widgetlocations(){
// Register widgetized locations
if(function_exists('register_sidebar')) {
register_sidebar(array(
'name' => __( 'Blog Sidebar','dbea' ),
'id' => 'blog-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title"><span>',
'after_title' => '</span></h3>',
));
register_sidebar(array(
'name' => __( 'WooCommerce Sidebar','dbea' ),
'id' => 'woo-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title"><span>',
'after_title' => '</span></h3>',
));
register_sidebar(array(
'name' => __( 'WooCommerce Sidebar - Sticky','dbea' ),
'id' => 'woo-sidebar-sticky',
'before_widget' => '<div id="%1$s" class="widget woo-sidebar-sticky %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widget-title">',
'after_title' => '</h4>'
));
}
}
add_action( 'widgets_init', 'dbea_widgetlocations' );
/**
* Add styles & scripts
**/
function dbea_scripts() {
global $dbea_opt, $wp_query;
$optimize = '.min'; $optimize = '';
$css_file = dbea_css_file();
// Enqueue style
wp_enqueue_style('bootstrap', DBEA_THEME_URI . '/assets/css/bootstrap.min.css');
wp_enqueue_style('owlcarousel', DBEA_THEME_URI . '/assets/css/owl.carousel.min.css');
wp_enqueue_style('slick', DBEA_THEME_URI . '/assets/css/slick.min.css');
wp_enqueue_style('select2', DBEA_THEME_URI . '/assets/css/select2.min.css' );
wp_enqueue_style('font-awesome', DBEA_THEME_URI . '/assets/fonts/fontawesome-5/css/all.min.css');
wp_enqueue_style('font-ionicons', DBEA_THEME_URI . '/assets/fonts/ionicons/css/ionicons.min.css');
wp_enqueue_style('dbea-theme-style', DBEA_THEME_URI . '/assets/css/' . $css_file);
if ( !class_exists( 'Redux_Framework_Plugin' ) ) {
wp_enqueue_style( 'dbea-google-fonts', 'https://fonts.googleapis.com/css2?family=K2D:wght@400;700;800&display=swap' );
}
// Dequeue style
wp_dequeue_style('simple-share-buttons-adder-font-awesome');
wp_dequeue_style('yith-wcwl-font-awesome');
// Register script
wp_register_script('isotope', DBEA_THEME_URI . '/assets/js/isotope.pkgd.min.js', array('jquery'), '', true);
wp_register_script('dbea-blog-ajax', DBEA_THEME_URI . '/assets/js/sns-blog-ajax.js', array('jquery'), '', true);
wp_register_script('jquery-countdown', DBEA_THEME_URI . '/assets/countdown/jquery.countdown.min.js', array('jquery'), '2.1.0', true);
wp_register_script( 'waypoints' , DBEA_THEME_URI . '/assets/js/waypoints.min.js', array('jquery'), '', true);
wp_register_script('threesixty', DBEA_THEME_URI . '/assets/js/threesixty.min.js', array('jquery'), '', true);
// Enqueue script
wp_enqueue_script('bootstrap', DBEA_THEME_URI . '/assets/js/bootstrap.min.js', array('jquery'), '', true);
wp_enqueue_script('bootstrap-tabdrop', DBEA_THEME_URI . '/assets/js/bootstrap-tabdrop.min.js', array('jquery'), '', true);
wp_enqueue_script('bootstrap-input-spinner', DBEA_THEME_URI . '/assets/js/bootstrap-input-spinner.min.js', array('jquery'), '', true);
wp_enqueue_script('owlcarousel', DBEA_THEME_URI . '/assets/js/owl.carousel.min.js', array('jquery'), '', true);
wp_enqueue_script('slick', DBEA_THEME_URI . '/assets/js/slick.min.js', array('jquery'), '', true);
wp_enqueue_script('select2', DBEA_THEME_URI.'/assets/js/select2.min.js', array(), '', true);
wp_enqueue_script('jquery-waitforimages', DBEA_THEME_URI.'/assets/js/jquery.waitforimages.min.js', array(), '', true);
if(class_exists('WooCommerce')){
if( dbea_themeoption('woo_uselazyload', 0) == 1 ) {
wp_enqueue_script('jquery-lazyload', DBEA_THEME_URI . '/assets/js/jquery.lazyload.min.js', array('jquery'), '', true);
}
wp_enqueue_script('resizesensor', DBEA_THEME_URI . '/assets/js/resizesensor.min.js', array('jquery'), '', true);
wp_enqueue_script('sticky-sidebar', DBEA_THEME_URI . '/assets/js/sticky-sidebar.min.js', array('jquery'), '', true);
if( dbea_themeoption('woo_usecloudzoom', 1) == 1 ) {
wp_enqueue_script('jquery-elevatezoom', DBEA_THEME_URI.'/assets/js/jquery.elevatezoom.min.js', array('jquery'), '', true);
}
wp_enqueue_script('dbea-woo', DBEA_THEME_URI.'/assets/js/sns-woo.js', array('jquery', 'woocommerce', 'wc-single-product'), '', true);
}
wp_enqueue_script('dbea-script', DBEA_THEME_URI . '/assets/js/sns-script.js', array('jquery'), '', true);
// Inline style after dbea-theme-style, The conten render by function dbea_cssinline()
wp_add_inline_style( 'dbea-theme-style', dbea_cssinline() );
// Inline scritp after dbea-script. The conten render by function dbea_jsinline()
wp_add_inline_script( 'dbea-script', dbea_jsinline() );
// Code to declare the URL to the file handing the AJAX request
$js_params = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'query_vars' => $wp_query->query_vars
);
wp_localize_script('ajax-request', 'sns', $js_params);
}
add_action( 'wp_enqueue_scripts', 'dbea_scripts' );
/**
* Remove inline style after FontAwesome
**/
function dbea_remove_cssinline(){
wp_styles()->add_data( 'font-awesome', 'after', '' );
}
add_action( 'wp_print_styles', 'dbea_remove_cssinline' );
/**
* Inline style, with style depend config in Theme Option
**/
function dbea_cssinline(){
global $dbea_opt;
$bodycss = ''; $body_font_css = ''; $headlinecss = ''; $three_fontcss = ''; $breadcrumpcss = '';
$body_font = array( "font-family" => "K2D", "font-weight" => "400", "font-size" => "14px", "color" => "#626262" );
if(isset($dbea_opt['body_font']) && is_array($dbea_opt['body_font'])) {
$body_font = $dbea_opt['body_font'];
}
foreach($body_font as $propety => $value)
if($value != 'true' && $value != 'false' && $value != '' && $propety != 'subsets' && $propety != 'google' )
$body_font_css .= $propety . ':' . $value . ';';
if($body_font_css != '') $bodycss .= $body_font_css;
if(isset($dbea_opt['headline_font']) && is_array($dbea_opt['headline_font'])) {
$headline_font = '';
foreach($dbea_opt['headline_font'] as $propety => $value)
if($value != 'true' && $value != 'false' && $value != '' && $propety != 'subsets' && $propety != 'google' )
$headline_font .= $propety . ':' . $value . ';';
if ($headline_font != '' && isset($dbea_opt['hfont_target']) and $dbea_opt['hfont_target']!='' ) $headlinecss .= $dbea_opt['hfont_target'].'{'.$headline_font.'}';
}
if(isset($dbea_opt['three_font']) && is_array($dbea_opt['three_font'])) {
$three_font = '';
foreach($dbea_opt['three_font'] as $propety => $value)
if($value != 'true' && $value != 'false' && $value != '' && $propety != 'subsets' && $propety != 'google' )
$three_font .= $propety . ':' . $value . ';';
if ($three_font != '' && isset($dbea_opt['threefont_target']) and $dbea_opt['threefont_target']!='' ) $three_fontcss .= $dbea_opt['threefont_target'].'{'.$three_font.'}';
}
if( class_exists('WooCommerce') && is_woocommerce() && is_product_category() ){
$showbreadcrump = dbea_woo_cat_option('showbreadcrump');
$breadcrumbbg = dbea_woo_cat_option('breadcrumbbg', '', 'image');
}else {
$showbreadcrump = dbea_getoption('showbreadcrump', '1');
$breadcrumbbg = dbea_getoption('breadcrumbbg', '', 'image');
}
$css_bgimg = true;
if ( class_exists('WooCommerce') && is_product() ) {
$css_bgimg = false;
}elseif ( is_singular('post') ) {
$css_bgimg = false;
}
if ( $css_bgimg == true && $showbreadcrump == '1' && !is_array($breadcrumbbg) && $breadcrumbbg != '' ) {
$breadcrumpcss = '#sns_breadcrumbs.wrap{ background-image:url('.$breadcrumbbg.');}';
}
return 'body {'.$bodycss.'}'.$headlinecss.$three_fontcss.$breadcrumpcss;
}
/*
* Inline script, with js variables depend config in Theme Option & Product Option
*/
function dbea_jsinline() {
$output = '';
ob_start();
if(class_exists('WooCommerce')){ ?>
if ( typeof wc_single_product_params !== 'undefined' ) {
wc_single_product_params.sns_thumbnum = '<?php echo esc_html(dbea_themeoption('woo_thumb_num', 5)) ; ?>';
wc_single_product_params.sns_product_video = '<?php echo esc_html(get_post_meta( get_the_id(), 'dbea_product_video', true )); ?>';
}
<?php
global $product;
$theID = get_the_id();
$product = wc_get_product( $theID );
if( is_product() && $product->get_type() === 'variable' && dbea_themeoption('woo_designvariations', 1) == 1 ){
$attributes = $product->get_attributes();
?>
/* Declaring sns_arr_attr variable if Product Type is Variable Product */
var sns_arr_attr = {};
<?php
foreach ( $attributes as $attribute ) :
if ( empty( $attribute['is_visible'] ) || ( $attribute['is_taxonomy'] && ! taxonomy_exists( $attribute['name'] ) ) ) {
continue;
} else {}
$terms = wc_get_product_terms( $product->get_id(), $attribute['name'], array( 'fields' => 'all' ) );
$type = '';
$key_val = array();
$i = 0;
if ( is_array($terms) && empty($terms) ) {
$terms = $attribute['options'];
foreach ($terms as $term) { $i++;
$key_val[$term] = $term;
}
}else{
foreach ($terms as $term) { $i++;
$type = dbea_get_term_byid($term->term_id, 'dbea_product_attribute_type', 'text');
$available_variations = $product->get_available_variations();
$image_src = ''; $color_code = '';
foreach ($available_variations as $available_variation) {
if( dbea_getoption('use_variation_thumb', 1) == 1 && isset($available_variation['attributes']["attribute_$term->taxonomy"]) && $term->slug === $available_variation['attributes']["attribute_$term->taxonomy"] ){
$image_src = get_post_thumbnail_id( $available_variation['variation_id'] );
$image_src = wp_get_attachment_image_src( $image_src, 'shop_thumbnail');
$image_src = isset($image_src['0']) ? $image_src['0'] : '';
}
}
$color_code = dbea_get_term_byid($term->term_id, 'dbea_product_attribute_color', '');
if ( $type == 'color' ) {
if ( $image_src != '' ) {
$key_val[$term->slug] = $image_src;
}elseif( trim($color_code) != '' ){
$key_val[$term->slug] = $color_code;
}else{
$key_val[$term->slug] = $term->name;
}
}else{
$key_val[$term->slug] = $term->name;
}
}
}?>
var attributeName = '<?php echo esc_attr( strtolower($attribute['name']) ) ?>';
var data_type = '<?php echo esc_attr($type); ?>';
var key_val = {};
<?php foreach ($key_val as $key => $value):?>
key_val['<?php echo esc_attr($key) ?>'] = '<?php echo esc_attr($value) ?>';
<?php endforeach;?>
sns_arr_attr['attribute_' + attributeName] = {'type': data_type, key_val};
<?php
endforeach;
}
} ?>
/* Declaring ajaxurl variable */
if (typeof ajaxurl == 'undefined') {
var ajaxurl = '<?php echo esc_js( admin_url('admin-ajax.php') ); ?>';
}
<?php
$output = '/* <![CDATA[ */ ' . ob_get_clean() . '/* ]]> */';
return $output;
}
/*
* Enqueue admin styles and scripts
*/
function dbea_admin_styles_scripts(){
wp_enqueue_style('dbea-admin-style', DBEA_THEME_URI.'/assets/css/admin-style.css');
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style('font-awesome', DBEA_THEME_URI . '/assets/fonts/awesome/css/font-awesome.min.css');
wp_enqueue_media();
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script('dbea-admin-template-js', DBEA_THEME_URI.'/assets/js/sns-admin-template.js', array( 'jquery', 'wp-color-picker' ), false, true);
}
add_action('admin_enqueue_scripts', 'dbea_admin_styles_scripts');
/**
* Editor style
**/
add_editor_style('assets/css/editor-style.css');
/*
* Add tpl footer
*/
function dbea_tplfooter() {
ob_start();
require DBEA_THEME_DIR . '/tpl-footer.php';
echo ob_get_clean();
}
add_action('wp_footer', 'dbea_tplfooter');
/**
* Tile for page, post
**/
function dbea_pagetitle(){
// Disable title in page
if ( class_exists('WooCommerce') ) {
if( is_shop() && dbea_metabox('showtitle') == '2' ) return;
}
if( is_front_page() || ( is_page() && dbea_metabox('showtitle') == '2' ) ) return;
// Show title in page, single post
if ( is_singular('post') ) : return; ?>
<h3 class="page-header">
<span><?php echo esc_html__('Blog', 'dbea'); ?></span>
</h3>
<?php
elseif( is_page() || ( is_home() && get_option( 'show_on_front' ) == 'page' ) ) : ?>
<h1 class="page-header">
<span><?php the_title(); ?></span>
</h1>
<?php
// Show title for category page
elseif ( is_category() ) : ?>
<h1 class="page-header">
<span><?php single_cat_title(); ?></span>
</h1>
<?php
// Author
elseif ( is_author() ) : ?>
<h1 class="page-header">
<span>
<?php
printf( __( 'All posts by: %s', 'dbea' ), get_the_author() );
?>
</span>
</h1>
<?php if ( get_the_author_meta( 'description' ) ) : ?>
<header class="archive-header">
<div class="author-description"><p><?php the_author_meta( 'description' ); ?></p></div>
</header>
<?php endif; ?>
<?php
// Tag
elseif ( is_tag() ) : ?>
<h1 class="page-header">
<span>
<?php printf( __( 'Tag Archives: %s', 'dbea' ), single_tag_title( '', false ) ); ?>
</span>
</h1>
<?php
$term_description = term_description();
if ( ! empty( $term_description ) ) : ?>
<header class="archive-header">
<?php printf( '<div class="taxonomy-description">%s</div>', $term_description ); ?>
</header>
<?php endif; ?>
<?php
// Search
elseif ( is_search() ) : ?>
<h1 class="page-header"><span><?php printf( __( 'Search Results for: %s', 'dbea' ), get_search_query() ); ?></span></h1>
<?php
// Archive
elseif ( is_archive() ) : ?>
<h1 class="page-header">
<?php
if ( class_exists('WooCommerce') && is_woocommerce() ) {
woocommerce_page_title();
}else{
the_archive_title();
}
?>
</h1>
<?php
if( get_the_archive_description() ): ?>
<header class="archive-header">
<?php the_archive_description( '<div class="taxonomy-description">', '</div>' ); ?>
</header>
<?php
endif;
?>
<?php
// Default
else : ?>
<h1 class="page-header">
<span><?php the_title(); ?></span>
</h1>
<?php
endif;
}
// Excerpt Function
if(!function_exists('dbea_excerpt')){
function dbea_excerpt($limit, $afterlimit='[...]') {
$limit = ($limit) ? $limit : 55 ;
$excerpt = get_the_excerpt();
if( $excerpt != '' ){
$excerpt = explode(' ', strip_tags( $excerpt ), intval($limit));
}else{
$excerpt = explode(' ', strip_tags(get_the_content( )), intval($limit));
}
if ( count($excerpt) >= $limit ) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' '.$afterlimit;
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return strip_shortcodes( $excerpt );
}
}
// Word Limiter
function dbea_limitwords($string, $word_limit) {
$words = explode(' ', $string);
if ( $word_limit < count($words) ){
return implode(' ', array_slice($words, 0, $word_limit));
}else{
return implode(' ', array_slice($words, 0, $word_limit));
}
}
function dbea_limitcharacter($string, $character_limit) {
if ( $character_limit < strlen($string) ){
return substr($string, 0, $character_limit) . ' ...';
}else{
return $string;
}
}
//
if(!function_exists('dbea_sharebox')){
function dbea_sharebox(){
if ( class_exists('SimpleShareButtonsAdder\Plugin') ) {
?>
<div class="post-share-block">
<?php echo do_shortcode('[ssba-buttons]'); ?>
</div>
<?php
}
}
}
//
if(!function_exists('dbea_relatedpost')){
function dbea_relatedpost(){
global $post;
if($post){
$post_id = $post->ID;
}
$relate_count = dbea_themeoption('related_num');
$get_related_post_by = dbea_themeoption('related_posts_by');
$args = array(
'post_status' => 'publish',
'posts_per_page' => $relate_count,
'orderby' => 'date',
'ignore_sticky_posts' => 1,
'post__not_in' => array ($post_id)
);
if($get_related_post_by == 'cat'){
$categories = wp_get_post_categories($post_id);
$args['category__in'] = $categories;
}else{
$posttags = wp_get_post_tags($post_id);
$array_tags = array();
if($posttags){
foreach ($posttags as $tag){
$tags = $tag->term_id;
array_push($array_tags, $tags);
}
}
$args['tag__in'] = $array_tags;
}
$relates = new WP_Query( $args );
$template_name = '/framework/tpl/posts/related_post.php';
if(is_file(DBEA_THEME_DIR.$template_name)) {
include(DBEA_THEME_DIR.$template_name);
}
wp_reset_postdata();
}
}
/*
* Function to display number of posts.
*/
function dbea_get_post_views($post_id){
$count_key = 'post_views_count';
$count = get_post_meta($post_id, $count_key, true);
if($count == ''){
delete_post_meta($post_id, $count_key);
add_post_meta($post_id, $count_key, '0');
return esc_html__('0 view', 'dbea');
}
return $count. esc_html__(' View', 'dbea');
}
/*
* Redmore for excerpt
*/
function dbea_excerpt_more( $link ) {
$link = '';
if ( is_admin() ) {
return $link;
}
if ( !is_search() ) {
$link = sprintf(
'<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
esc_url( get_permalink( get_the_ID() ) ),
'<span>'.__('Read More', 'dbea').'</span><span class="meta-nav">→</span>'
);
}
return $link;
}
add_filter( 'excerpt_more', 'dbea_excerpt_more' );
/*
* Function to count views.
*/
function dbea_set_post_views($post_id){
$count_key = 'post_views_count';
$count = get_post_meta($post_id, $count_key, true);
if($count == ''){
$count = 0;
delete_post_meta($post_id, $count_key);
add_post_meta($post_id, $count_key, '0');
}else{
$count++;
update_post_meta($post_id, $count_key, $count);
}
}
function dbea_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<?php $add_below = ''; ?>
<li <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<div class="comment-body">
<div class="comment-user-meta">
<?php echo get_avatar($comment, 80); ?>
<div class="comment-head">
<h4 class="comment-user"><?php echo get_comment_author_link(); ?>
<span class="date">
<?php
printf(__('%1$s at %2$s', 'dbea'), get_comment_date(), get_comment_time())
?>
</span>
</h4>
</div>
<?php if ($comment->comment_type != 'pingback'): ?>
<div class="comment-content">
<?php if ($comment->comment_approved == '0') : ?>
<p>
<em><?php echo esc_html__('Your comment is awaiting moderation.', 'dbea') ?></em><br />
</p>
<?php endif; ?>
<?php comment_text() ?>
</div>
<?php endif; ?>
<div class="comment-meta">
<?php comment_reply_link(array_merge( $args, array('reply_text' => esc_html__('Reply', 'dbea'), 'add_below' => 'comment', 'depth' => $depth, 'max_depth' => $args['max_depth'])))?>
<?php edit_comment_link(esc_html__('Edit', 'dbea'),' ','') ?>
</div>
</div>
</div>
<?php
}
/**
* Breadcrumbs
**/
add_action( 'dbea_before_sns_content', 'dbea_getbigbreadcrumbs', 5 );
function dbea_getbigbreadcrumbs(){
$showbreadcrump = '';
if( class_exists('WooCommerce') && is_woocommerce() && is_product_category() ){
$showbreadcrump = dbea_woo_cat_option('showbreadcrump');
$breadcrumbbg = dbea_woo_cat_option('breadcrumbbg', '', 'image');
}else {
$showbreadcrump = dbea_getoption('showbreadcrump', '1');
$breadcrumbbg = dbea_getoption('breadcrumbbg', '', 'image');
}
if ( $showbreadcrump == '2' ) return;
$bread_class = 'wrap';
if ( !is_front_page() && !is_404() ) : ?>
<div id="sns_breadcrumbs" class="<?php echo esc_attr($bread_class); ?>">
<div class="container">
<?php
if( is_file( DBEA_THEME_DIR . '/tpl-breadcrumb.php' ) ) {
echo '<div class="row inner"><div class="col-md-12">';
if ( is_page() ) {
if( $showbreadcrump == '3' || ( $showbreadcrump == '1' && !is_array($breadcrumbbg) && $breadcrumbbg == '' ) ){
// do nothing
}else{
dbea_pagetitle();
}
}elseif ( is_tag() || is_category() || is_singular() || ( class_exists('WooCommerce') && ( is_product_tag() || is_product_category() || is_product() ) ) ) {
// do nothing
}else{
dbea_pagetitle();
}
include( DBEA_THEME_DIR . '/tpl-breadcrumb.php' );
echo '</div></div>';
}
?>
</div>
</div>
<?php endif;
}
/**
* Search Ajax From
**/
if( !function_exists('dbea_get_searchform') ){
function dbea_get_searchform($search_box_type = 'def'){
$exists_woo = (class_exists('WooCommerce'))?true:false;
if( $exists_woo ){
$taxonomy = 'product_cat';
$post_type = 'product';
$placeholder_text = esc_attr__('Search product...', 'dbea');
}else{
$taxonomy = 'category';
$post_type = 'post';
$placeholder_text = esc_attr__('Enter keywords...', 'dbea');
}
$options = '<option value="">'.esc_html__('All categories', 'dbea').'</option>';
$options .= dbea_get_searchform_option($taxonomy, 0, 0);
$uq = rand().time();
if( $search_box_type != 'hide_cat' ){
echo '<div class="sns-searchwrap container" data-useajaxsearch="true" data-usecat-ajaxsearch="true">';
}else{
echo '<div class="sns-searchwrap container" data-useajaxsearch="true" data-usecat-ajaxsearch="false">';
}
echo '<div class="sns-ajaxsearchbox">
<form method="get" id="search_form_' . $uq . '" action="' . esc_url( home_url( '/' ) ) . '">';
if( $search_box_type != 'hide_cat' ){
echo '<select class="select-cat" name="cat">' . $options . '</select>';
}
echo '
<div class="search-input">
<input type="text" value="' . get_search_query() . '" name="s" id="s_' . $uq . '" placeholder="' . esc_attr($placeholder_text) . '" autocomplete="off" />
<button type="submit">
'. esc_html__('Search', 'dbea') .'
</button>
<input type="hidden" name="post_type" value="' . esc_attr($post_type) . '" />';
if ( $search_box_type != 'hide_cat' ) { echo '<input type="hidden" name="taxonomy" value="' . esc_attr($taxonomy) . '" />'; }
echo '</div>
</form></div></div>';
}
}
if( !function_exists('dbea_get_searchform_option') ){
function dbea_get_searchform_option($taxonomy = 'product_cat', $parent = 0, $level = 0){
$options = '';
$spacing = '';
for( $i = 0; $i < $level * 3 ; $i++ ){
$spacing .= ' ';
}
$args = array(
'number' => '',
'hide_empty' => 1,
'orderby' =>'date',
'order' =>'desc',
'parent' => $parent
);
$select = '';
$categories = get_terms($taxonomy, $args);
if( is_search() && isset($_GET['cat']) && $_GET['cat'] != '' ){
$select = $_GET['cat'];
}
$level++;
if( is_array($categories) ){
foreach( $categories as $cat ){
$options .= '<option value="' . esc_attr($cat->slug) . '"';
if ($select == $cat->slug) {
$options .= ' selected';
}
$options .= '>' . esc_html($spacing) . esc_html($cat->name) . '</option>';
$options .= dbea_get_searchform_option($taxonomy, $cat->term_id, $level);
}
}
return $options;
}
}
/**
* Search by Title only From
**/
function dbea_search_by_title_only( $search ) {
global $wpdb, $wp_query;
if ( empty( $search ) )
return $search; // skip processing - no search term in query
$q = $wp_query->query_vars;
$n = ( isset( $q['exact'] ) && ! empty( $q['exact'] ) ) ? '' : '%';
$search = '';
$searchand = '';
foreach ( (array) $q['search_terms'] as $term ) {
$term = esc_sql( $wpdb->esc_like( $term ) );
$like = $n . $term . $n;
$search .= $wpdb->prepare( "{$searchand}($wpdb->posts.post_title LIKE %s)", $like );
$searchand = ' AND ';
}
if ( ! empty( $search ) ) {
$search = " AND ({$search}) ";
if ( ! class_exists('WooCommerce') && ! is_user_logged_in() ) { // Just for post
$search .= " AND ($wpdb->posts.post_password = '') ";
}
}
return $search;
}
/**
* Ajax search action
**/
add_action( 'wp_ajax_dbea_ajax_search', 'dbea_ajax_search' );
add_action( 'wp_ajax_nopriv_dbea_ajax_search', 'dbea_ajax_search' );
if( !function_exists('dbea_ajax_search') ){
function dbea_ajax_search(){
global $post, $wp_query;
$exists_woo = ( class_exists('WooCommerce') ) ? true : false ;
if( $exists_woo ){
$taxonomy = 'product_cat';
$post_type = 'product';
}else{
$taxonomy = 'category';
$post_type = 'post';
}
$num_result = dbea_getoption('search_limit', -1);
$keywords = $_POST['keywords'];
$category = isset($_POST['category'])? $_POST['category']: '';
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
's' => $keywords,
'posts_per_page' => $num_result
);
if( $category != '' ){
$args['tax_query'] = array(
array(
'taxonomy' => $taxonomy,
'terms' => $category,
'field' => 'slug'
)
);
}
$results = new WP_Query($args);
if( $results->have_posts() ){
$extra_class = '';
if( isset($results->post_count, $results->found_posts) && $results->found_posts > $results->post_count ){
$extra_class = 'allcat-result';
}
$html = '<ul class="'.esc_attr($extra_class).'">';
while( $results->have_posts() ){
$results->the_post();
$link = get_permalink($post->ID);
$image = '';
if( $post_type == 'product' ){
$product = wc_get_product($post->ID);
$image = $product->get_image();
}
else if( has_post_thumbnail($post->ID) ){
$image = get_the_post_thumbnail($post->ID, 'thumbnail');
}
$html .= '<li>';
if( $image ){
$html .= '<div class="thumbnail">';
$html .= '<a href="'.esc_url($link).'">'. $image .'</a>';
$html .= '</div>';
}
$html .= '<div class="meta">';
$html .= '<a href="'.esc_url($link).'" class="title">'. dbea_ajaxsearch_highlight_key($post->post_title, $keywords) .'</a>';
if( $post_type == 'product' ){
$html .= '<span class="price">'. $product->get_price_html() .'</span>';
}
$html .= '</div>';
$html .= '</li>';
}
$html .= '</ul>';
if( isset($results->post_count, $results->found_posts) && $results->found_posts > $results->post_count ){
$html .= '<div class="viewall-result">';
$html .= '<a href="#">'. sprintf( __('View all %d results', 'dbea'), $results->found_posts ) .'</a>';
$html .= '</div>';
}
wp_reset_postdata();
$return = array();
$return['html'] = $html;
$return['keywords'] = $keywords;
die( json_encode($return) );
}else{
wp_reset_postdata();
$return = array();
if( $exists_woo ){
$return['html'] = esc_html__('No products were found matching your selection', 'dbea');
}else{
$return['html'] = esc_html__('No post were found matching your selection', 'dbea');
}
$return['keywords'] = $keywords;
die( json_encode($return) );
}
}
}
/**
* Highlight search key
**/
if( !function_exists('dbea_ajaxsearch_highlight_key') ){
function dbea_ajaxsearch_highlight_key($string, $keywords){
$hl_string = '';
$position_left = stripos($string, $keywords);
if( $position_left !== false ){
$position_right = $position_left + strlen($keywords);
$hl_string_rightsection = substr($string, $position_right);
$highlight = substr($string, $position_left, strlen($keywords));
$hl_string_leftsection = stristr($string, $keywords, true);
$hl_string = $hl_string_leftsection . '<span class="hightlight">' . $highlight . '</span>' . $hl_string_rightsection;
} else{
$hl_string = $string;
}
return $hl_string;
}
}
/**
* Match with default search
**/
add_filter('woocommerce_get_catalog_ordering_args', 'dbea_woo_get_catalog_ordering_args');
if( !function_exists('dbea_woo_get_catalog_ordering_args') ){
function dbea_woo_get_catalog_ordering_args( $args ){
if( class_exists('WooCommerce') && is_search() && !isset($_GET['orderby']) && get_option( 'woocommerce_default_catalog_orderby' ) == 'menu_order' ){
$args['orderby'] = '';
$args['order'] = '';
}
return $args;
}
}
/**
* Slideshow wrap
**/
function dbea_slideshow_wrap($container = false, $extra_width = false){
if ( is_page() && dbea_metabox('useslideshow') == 1 ): ?>
<div id="sns_slideshow" class="wrap">
<?php
if ( $container == true ) {
if ( $extra_width == true ) {
echo '<div class="container extra-width">'.do_shortcode('[rev_slider '.esc_attr(dbea_metabox('revolutionslider')).' ]').'</div>';
}else{
echo '<div class="container">'.do_shortcode('[rev_slider '.esc_attr(dbea_metabox('revolutionslider')).' ]').'</div>';
}
}else{
echo do_shortcode('[rev_slider '.esc_attr(dbea_metabox('revolutionslider')).' ]');
}
?>
</div>
<?php
endif;
}
/**
* Sample data
**/
add_action( 'admin_enqueue_scripts', 'dbea_importlib' );
function dbea_importlib(){
wp_enqueue_script('sampledata', DBEA_THEME_URI . '/framework/sample-data/assets/script.js', array('jquery'), '', true);
wp_enqueue_style('sampledata-css', DBEA_THEME_URI . '/framework/sample-data/assets/style.css');
}
add_action( 'wp_ajax_sampledata', 'dbea_importsampledata' );
function dbea_importsampledata(){
include_once(DBEA_THEME_DIR . '/framework/sample-data/sns-importdata.php');
dbea_importdata();
}