Current File : /home/kelaby89/alalamy.com.au/wp-content/themes/kaffen/functions.php |
<?php
/**
* kaffen functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package kaffen
*/
define( 'KAFFEN_EXTRA_PLUGINS_DIRECTORY', 'https://bslthemes.com/plugins-latest/kaffen/' );
define( 'KAFFEN_EXTRA_PLUGINS_PREFIX', 'Kaffen' );
if ( ! function_exists( 'kaffen_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function kaffen_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on kaffen, use a find and replace
* to change 'kaffen' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'kaffen', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'kaffen' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
// Image Sizes
add_image_size( 'kaffen_256x256', 800, 800, true );
add_image_size( 'kaffen_900x900', 900, 900, true );
add_image_size( 'kaffen_900xAuto', 900, 9999, false );
add_image_size( 'kaffen_1170x658', 1170, 658, true );
add_image_size( 'kaffen_1920xAuto', 1920, 9999, false );
}
endif;
add_action( 'after_setup_theme', 'kaffen_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function kaffen_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'kaffen_content_width', 900 );
}
add_action( 'after_setup_theme', 'kaffen_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function kaffen_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'kaffen' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'kaffen' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
if ( class_exists( 'WooCommerce' ) ) :
register_sidebar( array(
'name' => esc_html__( 'Shop Sidebar', 'kaffen' ),
'id' => 'shop-sidebar',
'description' => esc_html__( 'Sidebar that appears on the shop.', 'kaffen' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
endif;
}
add_action( 'widgets_init', 'kaffen_widgets_init' );
/**
* Register Default Fonts
*/
function kaffen_fonts_url() {
$fonts_url = '';
/* Translators: If there are characters in your language that are not
* supported by Lora, translate this to 'off'. Do not translate
* into your own language.
*/
$mulish = _x( 'on', 'Roboto: on or off', 'kaffen' );
if ( 'off' !== $mulish ) {
$font_families = array();
$font_families[] = 'Merienda:wght@400;700';
$font_families[] = 'Roboto:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900';
$font_families[] = 'Oswald:wght@200;300;400;500;600;700';
$query_args = array(
'family' => implode( '&family=', $font_families ),
'display' => urlencode( 'swap' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css2?family' );
}
return $fonts_url;
}
/**
* Enqueue scripts and styles.
*/
function kaffen_stylesheets() {
// Web fonts
wp_enqueue_style( 'kaffen-fonts', kaffen_fonts_url(), array(), null );
$text_font_family = get_field( 'text_font_family', 'options' );
$primary_font_family = get_field( 'primary_font_family', 'options' );
$heading_font_family = get_field( 'heading_font_family', 'options' );
// Custom fonts
if ( $text_font_family ) {
wp_enqueue_style( 'kaffen-text-font', $text_font_family['url'] , array(), null );
}
if ( $primary_font_family ) {
wp_enqueue_style( 'kaffen-primary-font', $primary_font_family['url'] , array(), null );
}
if ( $heading_font_family ) {
wp_enqueue_style( 'kaffen-heading-font', $heading_font_family['url'] , array(), null );
}
/*Styles*/
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/styles/vendors/bootstrap.css', '1.0' );
wp_enqueue_style( 'kaffen-font-awesome', get_template_directory_uri() . '/assets/fonts/font-awesome/css/font-awesome.css', '1.0' );
wp_enqueue_style( 'kaffen-line-awesome', get_template_directory_uri() . '/assets/fonts/font-awesome/css/line-awesome.css', '1.0' );
wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/styles/vendors/magnific-popup.css', '1.0' );
wp_enqueue_style( 'splitting', get_template_directory_uri() . '/assets/styles/vendors/splitting.css', '1.0' );
wp_enqueue_style( 'kaffen-swiper', get_template_directory_uri() . '/assets/styles/vendors/swiper.css', '1.0' );
wp_enqueue_style( 'animate', get_template_directory_uri() . '/assets/styles/vendors/animate.css', '1.0' );
wp_enqueue_style( 'kaffen-main', get_stylesheet_uri(), array( 'bootstrap', 'magnific-popup', 'splitting', 'kaffen-swiper', 'animate', 'kaffen-font-awesome', 'kaffen-line-awesome' ) );
}
add_action( 'wp_enqueue_scripts', 'kaffen_stylesheets' );
function kaffen_scripts() {
/*Default Scripts*/
wp_enqueue_script( 'kaffen-skip-link-focus-fix', get_template_directory_uri() . '/assets/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/*Theme Scripts*/
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'swiper', get_template_directory_uri() . '/assets/js/swiper.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'splitting', get_template_directory_uri() . '/assets/js/splitting.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'paroller', get_template_directory_uri() . '/assets/js/jquery.paroller.min.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'magnific-popup', get_template_directory_uri() . '/assets/js/magnific-popup.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'parallax', get_template_directory_uri() . '/assets/js/parallax.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'imagesloaded-pkgd', get_template_directory_uri() . '/assets/js/imagesloaded.pkgd.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'isotope-pkgd', get_template_directory_uri() . '/assets/js/isotope.pkgd.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'scrolla', get_template_directory_uri() . '/assets/js/jquery.scrolla.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'skrollr', get_template_directory_uri() . '/assets/js/skrollr.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'jquery-easy-number-animate', get_template_directory_uri() . '/assets/js/jquery.easy_number_animate.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'kaffen-common', get_template_directory_uri() . '/assets/js/common.js', array('jquery'), '1.0.0', true );
if ( is_singular() ) {
$kaffen_rrssb_init = 'jQuery(document).ready(function ($) { $(".social-share").rrssb({ title: "' . esc_attr( get_the_title() ) . '", url: "' . esc_url( get_the_permalink() ) . '" }); });';
wp_enqueue_script( 'kaffen-rrssb', get_template_directory_uri() . '/assets/js/rrssb.js', array('jquery'), '1.0.0', true );
wp_add_inline_script('kaffen-rrssb', $kaffen_rrssb_init );
}
}
add_action( 'wp_enqueue_scripts', 'kaffen_scripts' );
/**
* TGM
*/
require get_template_directory() . '/inc/plugins/plugins.php';
/**
* ACF Options
*/
function kaffen_acf_fa_version( $version ) {
$version = 5;
return $version;
}
add_filter( 'ACFFA_override_major_version', 'kaffen_acf_fa_version' );
function kaffen_acf_json_load_point( $paths ) {
$paths = array( get_template_directory() . '/inc/acf-json' );
if( is_child_theme() ) {
$paths[] = get_stylesheet_directory() . '/inc/acf-json';
}
return $paths;
}
add_filter('acf/settings/load_json', 'kaffen_acf_json_load_point');
if ( function_exists( 'acf_add_options_page' ) ) {
// Hide ACF field group menu item
add_filter( 'acf/settings/show_admin', '__return_false' );
add_filter( 'acf/settings/show_updates', '__return_false', 100 );
// Add ACF Options Page
acf_add_options_page( array(
'page_title' => esc_html__( 'Kaffen Options', 'kaffen' ),
'menu_title' => esc_html__( 'Kaffen Options', 'kaffen' ),
'menu_slug' => 'theme-options',
'capability' => 'edit_theme_options',
'icon_url' => 'dashicons-bslthemes',
'position' => 3,
) );
}
function kaffen_acf_json_save_point( $path ) {
// update path
$path = get_stylesheet_directory() . '/inc/acf-json';
// return
return $path;
}
add_filter( 'acf/settings/save_json', 'kaffen_acf_json_save_point' );
function kaffen_acf_fallback() {
// ACF Plugin fallback
if ( ! is_admin() && ! function_exists( 'get_field' ) ) {
function get_field( $field = '', $id = false ) {
return false;
}
function the_field( $field = '', $id = false ) {
return false;
}
function have_rows( $field = '', $id = false ) {
return false;
}
function has_sub_field( $field = '', $id = false ) {
return false;
}
function get_sub_field( $field = '', $id = false ) {
return false;
}
function the_sub_field( $field = '', $id = false ) {
return false;
}
}
}
add_action( 'init', 'kaffen_acf_fallback' );
/**
* OCDI
*/
require get_template_directory() . '/inc/ocdi-setup.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
/**
* Include Skin Options
*/
require get_template_directory() . '/inc/skin-options.php';
/**
* Include Infinite Scroll
*/
require get_template_directory() . '/inc/infinite-scroll.php';
/**
* Include Custom Breadcrumbs
*/
require get_template_directory() . '/inc/custom-breadcrumbs.php';
/**
* Get Archive Title
*/
function kaffen_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_post_type_archive( 'portfolio' ) ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( esc_html__( 'Tag: ', 'kaffen' ), false );
} elseif ( is_author() ) {
$title = esc_html__( 'Author: ', 'kaffen' ) . get_the_author();
}
return $title;
}
add_filter( 'get_the_archive_title', 'kaffen_archive_title' );
/**
* Excerpt
*/
function kaffen_custom_excerpt_length( $length ) {
return 44;
}
add_filter( 'excerpt_length', 'kaffen_custom_excerpt_length' );
function kaffen_new_excerpt_more( $more ) {
return esc_html__( '... ', 'kaffen' ) . '<div class="readmore"><a href="' . esc_url( get_permalink() ) . '" class="kf-btn-link"><span>' . esc_html__( 'Read more', 'kaffen' ) . '</span> <i class="fas fa-chevron-right"></i></a></div>';
}
add_filter( 'excerpt_more', 'kaffen_new_excerpt_more' );
/**
* Disable CF7 Auto Paragraph
*/
add_filter('wpcf7_autop_or_not', '__return_false');
/**
* Add class to sub-menu
*/
function kaffen_change_wp_nav_menu( $classes, $args, $depth ) {
if( $args->theme_location == 'primary' && get_field( 'menu_type', 'option' ) == 2 ) {
$classes[] = '';
} else if( $args->theme_location == 'primary' && get_field( 'menu_type', 'option' ) == 1 ) {
$classes[] = '';
}
return $classes;
}
add_filter( 'nav_menu_submenu_css_class', 'kaffen_change_wp_nav_menu', 10, 3 );
/**
* Top Menu
*/
class Kaffen_Topmenu_Walker extends Walker_Nav_menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = '';
if ( isset( $args->link_after ) ) {
$args->link_after = '';
}
$args->after = '';
if ( is_array($item->classes) ) {
if ( in_array('menu-item-has-children', $item->classes ) ) {
array_push( $item->classes, 'has-children' );
}
if ( in_array('menu-item-has-children', $item->classes ) && $depth == 0 ) {
$args->after = '<i class="las la-angle-down"></i>';
}
}
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = '';
$class_names = join(' ', $classes);
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$attributes = ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) . '"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) . '"' : '';
if ( has_nav_menu( 'primary' ) ) {
$output .= $indent . '<li id="menu-item-'. esc_attr( $item->ID ) . '"' . $class_names . '>';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_url( $item->url ) . '"' : '';
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID );
$item_output .= $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
}
/**
* Woocommerce Support
*/
function kaffen_add_woocommerce_support() {
add_theme_support( 'woocommerce', array(
'thumbnail_image_width' => 800,
'gallery_thumbnail_image_width' => 200,
'single_image_width' => 800,
'product_grid' => array(
'default_rows' => 3,
'min_rows' => 2,
'max_rows' => 5,
'default_columns' => 3,
'min_columns' => 2,
'max_columns' => 5,
),
) );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
}
add_action( 'after_setup_theme', 'kaffen_add_woocommerce_support' );
/**
* Update contents AJAX mini-cart
*/
function kaffen_woocommerce_update_count_mini_cart( $fragments ) {
ob_start();
?>
<span class="cart-count">
<?php echo sprintf (_n( '%d', '%d', WC()->cart->get_cart_contents_count(), 'kaffen' ), WC()->cart->get_cart_contents_count() ); ?>
</span>
<?php
$fragments['span.cart-count'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'kaffen_woocommerce_update_count_mini_cart' );
function kaffen_woocommerce_update_content_mini_cart( $fragments ) {
ob_start();
?>
<div class="cart-widget">
<?php woocommerce_mini_cart(); ?>
</div>
<?php
$fragments['div.cart-widget'] = ob_get_clean();
return $fragments;
}
add_filter( 'woocommerce_add_to_cart_fragments', 'kaffen_woocommerce_update_content_mini_cart' );