/home/awneajlw/public_html/decenttraders.online/wp-content/themes/diziti/functions.php
<?php
require_once get_template_directory() . '/includes/loader.php';
add_action( 'after_setup_theme', 'diziti_setup_theme' );
add_action( 'after_setup_theme', 'diziti_load_default_hooks' );
function diziti_setup_theme() {
load_theme_textdomain( 'diziti', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
/*
* 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' );
add_theme_support( 'custom-header' );
add_theme_support( 'custom-background' );
/*
* 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' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'align-wide' );
add_theme_support( "title-tag" );
add_theme_support( "responsive-embeds" );
add_theme_support( "wp-block-styles" );
// Set the default content width.
$GLOBALS['content_width'] = 525;
/*---------- Register image sizes ----------*/
//Register image sizes
add_image_size( 'diziti_414x535', 414, 535, true ); //diziti_414x535 Team Grid
add_image_size( 'diziti_600x330', 600, 330, true ); //diziti_600x330 Blog Grid
add_image_size( 'diziti_410x300', 410, 300, true ); //diziti_410x300 Blog Grid
add_image_size( 'diziti_254x294', 254, 294, true ); //diziti_254x294 Blog Grid
add_image_size( 'diziti_510x537', 510, 537, true ); //diziti_510x537 Team Detail
/*---------- Register image sizes ends ----------*/
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'main_menu' => esc_html__( 'Main Menu', 'diziti' ),
'footer_menu' => esc_html__( 'Footer Menu', 'diziti' ),
'footer_menu2' => esc_html__( 'Footer Menu 02', 'diziti' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style();
add_action( 'admin_init', 'diziti_admin_init', 2000000 );
}
/**
* [diziti_admin_init]
*
* @param array $data [description]
*
* @return [type] [description]
*/
function diziti_admin_init() {
remove_action( 'admin_notices', array( 'ReduxFramework', '_admin_notices' ), 99 );
}
/*---------- Sidebar settings ----------*/
/**
* [diziti_widgets_init]
*
* @param array $data [description]
*
* @return [type] [description]
*/
function diziti_widgets_init() {
global $wp_registered_sidebars;
$theme_options = get_theme_mod( 'diziti' . '_options-mods' );
register_sidebar( array(
'name' => esc_html__( 'Default Sidebar', 'diziti' ),
'id' => 'default-sidebar',
'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'diziti' ),
'before_widget' => '<div id="%1$s" class="widget single-sidebar-box %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="sidebar-title"><h3> ',
'after_title' => '</h3></div>',
) );
register_sidebar(array(
'name' => esc_html__('Footer Widget', 'diziti'),
'id' => 'footer-sidebar',
'description' => esc_html__('Widgets in this area will be shown in Footer Area.', 'diziti'),
'before_widget'=>'<div class="footer-widget wow fadeInUp" data-wow-delay="1s"><div id="%1$s" class="ct-widget-footer footer-widget">',
'after_widget'=>'</div></div>',
'before_title' => '<h3 class="widget_title">',
'after_title' => '</h3>'
));
if ( class_exists( '\Elementor\Plugin' )){
register_sidebar(array(
'name' => esc_html__( 'Footer Widget Two', 'diziti' ),
'id' => 'footer-sidebar-2',
'description' => esc_html__('Widgets in this area will be shown in Footer Area.', 'diziti'),
'before_widget'=>'<div class="footer-widget wow fadeInUp" data-wow-delay="1s"><div id="%1$s" class="ct-widget-footer style2 footer-widget">',
'after_widget'=>'</div></div>',
'before_title' => '<h3 class="widget_title style2">',
'after_title' => '</h3>'
));
register_sidebar(array(
'name' => esc_html__( 'Project Listing', 'diziti' ),
'id' => 'project-sidebar',
'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'diziti' ),
'before_widget'=>'<div class="wow fadeInUp" data-wow-delay=".7s">',
'after_widget'=>'</div>',
'before_title' => '<div class="wid-title"><h3>',
'after_title' => '</h3></div>'
));
register_sidebar(array(
'name' => esc_html__( 'Service Listing', 'diziti' ),
'id' => 'service-sidebar',
'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'diziti' ),
'before_widget'=>'<div class="service-sidebar-widget wow fadeInUp" data-wow-delay=".7s">',
'after_widget'=>'</div>',
'before_title' => '<div class="wid-title"><h3>',
'after_title' => '</h3></div>'
));
register_sidebar(array(
'name' => esc_html__( 'Blog Listing', 'diziti' ),
'id' => 'blog-sidebar',
'description' => esc_html__( 'Widgets in this area will be shown on the right-hand side.', 'diziti' ),
'before_widget'=>'<div class="single-sidebar-widget wow fadeInUp widget" data-wow-delay=".7s">',
'after_widget'=>'</div>',
'before_title' => '<div class="wid-title"><h3> ',
'after_title' => '</h3></div>'
));
}
if ( ! is_object( diziti_WSH() ) ) {
return;
}
$sidebars = diziti_set( $theme_options, 'custom_sidebar_name' );
foreach ( array_filter( (array) $sidebars ) as $sidebar ) {
if ( diziti_set( $sidebar, 'topcopy' ) ) {
continue;
}
$name = $sidebar;
if ( ! $name ) {
continue;
}
$slug = str_replace( ' ', '_', $name );
register_sidebar( array(
'name' => $name,
'id' => sanitize_title( $slug ),
'before_widget' => '<div id="%1$s" class="%2$s widget single-sidebar-box">',
'after_widget' => '</div>',
'before_title' => '<div class="sidebar-title"><h3> ',
'after_title' => '</h3></div>',
) );
}
update_option( 'wp_registered_sidebars', $wp_registered_sidebars );
}
add_action( 'widgets_init', 'diziti_widgets_init' );
/*---------- Sidebar settings ends ----------*/
/*---------- Gutenberg settings ----------*/
function diziti_gutenberg_editor_palette_styles() {
add_theme_support( 'editor-color-palette', array(
array(
'name' => esc_html__( 'strong yellow', 'diziti' ),
'slug' => 'strong-yellow',
'color' => '#f7bd00',
),
array(
'name' => esc_html__( 'strong white', 'diziti' ),
'slug' => 'strong-white',
'color' => '#fff',
),
array(
'name' => esc_html__( 'light black', 'diziti' ),
'slug' => 'light-black',
'color' => '#242424',
),
array(
'name' => esc_html__( 'very light gray', 'diziti' ),
'slug' => 'very-light-gray',
'color' => '#797979',
),
array(
'name' => esc_html__( 'very dark black', 'diziti' ),
'slug' => 'very-dark-black',
'color' => '#000000',
),
) );
add_theme_support( 'editor-font-sizes', array(
array(
'name' => esc_html__( 'Small', 'diziti' ),
'size' => 10,
'slug' => 'small'
),
array(
'name' => esc_html__( 'Normal', 'diziti' ),
'size' => 15,
'slug' => 'normal'
),
array(
'name' => esc_html__( 'Large', 'diziti' ),
'size' => 24,
'slug' => 'large'
),
array(
'name' => esc_html__( 'Huge', 'diziti' ),
'size' => 36,
'slug' => 'huge'
)
) );
}
add_action( 'after_setup_theme', 'diziti_gutenberg_editor_palette_styles' );
/*---------- Gutenberg settings ends ----------*/
/*---------- Enqueue Styles and Scripts ----------*/
function diziti_enqueue_scripts() {
// Color Scheme Code
$options = diziti_WSH()->option();
$header_meta = get_post_meta( get_the_ID(), 'header_style_settings');
$header_option = $options->get( 'header_style_settings' );
$header = ( $header_meta ) ? $header_meta['0'] : $header_option;
if( $options->get( 'main_color_scheme' ) ){
$maincolor = str_replace( '#', '' , $options->get( 'main_color_scheme' ));
}else{
$maincolor = str_replace( '#', '' , '#ffffff' );
}
if( $options->get( 'secondary_color_scheme' ) ){
$secondcolor = str_replace( '#', '' , $options->get( 'secondary_color_scheme' ));
}
else{
$secondcolor = str_replace( '#', '' , '#EEFB13' );
}
if( $options->get( 'bg_color_scheme' ) ){
$bgcolor = str_replace( '#', '' , $options->get( 'bg_color_scheme' ));
}
else{
$bgcolor = str_replace( '#', '' , '#0B0B0B' );
}
if( $options->get( 'bg_color2_scheme' ) ){
$bgcolor2 = str_replace( '#', '' , $options->get( 'bg_color2_scheme' ));
}
else{
$bgcolor2 = str_replace( '#', '' , '#171717' );
}
//styles
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css' );
wp_enqueue_style( 'fontawesome', get_template_directory_uri() . '/assets/css/all.min.css' );
wp_enqueue_style( 'animate', get_template_directory_uri() . '/assets/css/animate.css' );
wp_enqueue_style( 'magnific-popup', get_template_directory_uri() . '/assets/css/magnific-popup.css' );
wp_enqueue_style( 'meanmenu', get_template_directory_uri() . '/assets/css/meanmenu.css' );
wp_enqueue_style( 'swiper-bundle', get_template_directory_uri() . '/assets/css/swiper-bundle.min.css' );
wp_enqueue_style( 'nice-select', get_template_directory_uri() . '/assets/css/nice-select.css' );
wp_enqueue_style( 'diziti-main', get_stylesheet_uri() );
wp_enqueue_style( 'diziti-main-style', get_template_directory_uri() . '/assets/css/main.css' );
wp_enqueue_style( 'diziti-custom', get_template_directory_uri() . '/assets/css/custom.css' );
wp_enqueue_style( 'diziti-default-color', get_template_directory_uri() . '/assets/css/color-themes/default-color.css' );
wp_enqueue_style( 'diziti-main-color-scheme', get_template_directory_uri() . '/assets/css/color.php?main_color='.$maincolor.'&second_color='.$secondcolor.'&bg_color='.$bgcolor.'&bg_color2='.$bgcolor2.'' );
//scripts
wp_enqueue_script( 'jquery-ui-core');
wp_enqueue_script( 'bootstrap-bundle', get_template_directory_uri().'/assets/js/bootstrap.bundle.min.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'waypoints', get_template_directory_uri().'/assets/js/jquery.waypoints.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'swiper-bundle', get_template_directory_uri().'/assets/js/swiper-bundle.min.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'meanmenu', get_template_directory_uri().'/assets/js/jquery.meanmenu.min.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'magnific-popup', get_template_directory_uri().'/assets/js/magnific-popup.min.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'nice-select', get_template_directory_uri().'/assets/js/nice-select.min.js', array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'diziti-main-custom-script', get_template_directory_uri().'/assets/js/main.js', array(), false, true );
if( is_singular() ) wp_enqueue_script('comment-reply');
}
add_action( 'wp_enqueue_scripts', 'diziti_enqueue_scripts' );
/*---------- Enqueue styles and scripts ends ----------*/
/*---------- Google fonts ----------*/
function diziti_fonts_url() {
$fonts_url = '';
$font_families['Inter'] = 'Inter:300,400,500,600,700,800,900';
$font_families['Syne'] = 'Syne:300,400,500,600,700,800,900';
$font_families = apply_filters( 'DIZITI/includes/classes/header_enqueue/font_families', $font_families );
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$protocol = is_ssl() ? 'https' : 'http';
$fonts_url = add_query_arg( $query_args, $protocol . '://fonts.googleapis.com/css' );
return esc_url_raw($fonts_url);
}
function diziti_theme_styles() {
wp_enqueue_style( 'diziti-theme-fonts', diziti_fonts_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'diziti_theme_styles' );
add_action( 'admin_enqueue_scripts', 'diziti_theme_styles' );
/*---------- Google fonts ends ----------*/
/*---------- More functions ----------*/
// 1) diziti_set function
/**
* [diziti_set description]
*
* @param array $data [description]
*
* @return [type] [description]
*/
if ( ! function_exists( 'diziti_set' ) ) {
function diziti_set( $var, $key, $def = '' ) {
if ( is_object( $var ) && isset( $var->$key ) ) {
return $var->$key;
} elseif ( is_array( $var ) && isset( $var[ $key ] ) ) {
return $var[ $key ];
} elseif ( $def ) {
return $def;
} else {
return false;
}
}
}
// 2) diziti_add_editor_styles function
function diziti_add_editor_styles() {
add_editor_style( 'editor-style.css' );
}
add_action( 'admin_init', 'diziti_add_editor_styles' );
// 3) Add specific CSS class by filter body class.
$options = diziti_WSH()->option();
if( diziti_set($options, 'boxed_wrapper') ){
add_filter( 'body_class', function( $classes ) {
$classes[] = 'boxed_wrapper';
return $classes;
} );
}
add_filter('doing_it_wrong_trigger_error', function () {return false;}, 10, 0);
//Related Products
function diziti_related_products_limit() {
global $product;
$args['posts_per_page'] = 6;
return $args;
}
function diziti_register_block_patterns() {
register_block_pattern(
'diziti/custom-pattern-1',
array(
'title' => __('Custom Pattern 1', 'diziti'),
'description' => __('Description of Custom Pattern 1.', 'diziti'),
'content' => '<!-- Your block pattern content here -->',
'categories' => array('text'),
'keywords' => array('pattern', 'layout', 'custom'),
)
);
// Add more block patterns as needed
}
add_action('init', 'diziti_register_block_patterns');
function diziti_register_block_styles() {
// Register custom block styles for specific blocks
register_block_style(
'core/paragraph',
array(
'name' => 'diziti-custom-style-1',
'label' => __('Custom Style 1', 'diziti'),
'style_handle' => 'diziti-custom-style-1-css', // Enqueue your custom style CSS
)
);
// Add more custom block styles as needed
}
add_action('init', 'diziti_register_block_styles');