<?php 
/**
 * bestblogger functions and definitions
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 *
 * @package blogger-spot
 */
function blogger_features()
{
    register_nav_menu('HeaderMenuLocation','Header menu');
    register_nav_menu('FooterMenuLocation','Footer Menu');
    add_theme_support('title-tag');
    add_theme_support('custom-logo');
    add_theme_support( 'post-thumbnails' );
    add_theme_support('automatic-feed-links');
    add_theme_support( 'html5', array(
        'search-form',
        'comment-form',
        'comment-list',
        'gallery',
        'caption',
    ) );
    add_theme_support( "wp-block-styles" );
	add_theme_support( "responsive-embeds" );
    add_theme_support( 'align-wide' );
    
}
add_action('after_setup_theme','blogger_features');

function blogger_files()
{
    wp_enqueue_style( 'wpb-google-fonts', 'https://fonts.googleapis.com/css2?family=Crete+Round', false ); 
    wp_enqueue_style( 'wpb-google-fonts-two', 'https://fonts.googleapis.com/css2?family=Work+Sans:wght@500;600&display=swap', false ); 
    wp_enqueue_style('blogger_pluginstyleone', get_theme_file_uri('/plugins/bootstrap/bootstrap.min.css'));
    wp_enqueue_style('blogger_pluginstyletwo', get_theme_file_uri('/plugins/tabler-icons/tabler-icons.min.css'));
    wp_enqueue_style('blogger_mainstyle', get_theme_file_uri('/assets/css/style.css'));
    wp_enqueue_script('blogger_jquery', get_theme_file_uri('/plugins/jquery/jquery.min.js'), array('jquery'), '1.0', true);
    wp_enqueue_script('blogger_boot', get_theme_file_uri('/plugins/bootstrap/bootstrap.min.js'), array('jquery'), '1.0', true);
    wp_enqueue_script('blogger_light', get_theme_file_uri('/plugins/lightense/lightense.min.js'), array('jquery'), '1.0', true);
    wp_enqueue_script('blogger_main', get_theme_file_uri('/assets/js/script.js'), array('jquery'), '1.0', true);
    wp_enqueue_script('blogger_header', get_theme_file_uri('/assets/js/header.js'), array('jquery'), '1.0', true);
    
   
   
}
add_action('wp_enqueue_scripts','blogger_files');

function add_additional_class_on_li($classes, $item, $args) {
    if(isset($args->add_li_class)) {
        $classes[] = $args->add_li_class;
    }
    return $classes;
}
add_filter('nav_menu_css_class', 'add_additional_class_on_li', 1, 3);

function add_additional_class_on_a($classes, $item, $args)
{
    if (isset($args->add_a_class)) {
        $classes['class'] = $args->add_a_class;
    }
    return $classes;
}

add_filter('nav_menu_link_attributes', 'add_additional_class_on_a', 1, 3);

function get_breadcrumb() {
    echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
    if (is_category() || is_single()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        the_category(' &bull; ');
            if (is_single()) {
                echo " &nbsp;&nbsp;&#187;&nbsp;&nbsp; ";
                the_title();
            }
    } elseif (is_page()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
        echo the_title();
    } elseif (is_search()) {
        echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;Search Results for... ";
        echo '"<em>';
        echo the_search_query();
        echo '</em>"';
    }
}

// Estimated Reading Time
function vpsb_estimated_reading_time( $content = '') {
    $wpm = 200;          // Word Per Minute (200 Average)
    $text_content = strip_shortcodes( $content );     // Remove Shortcodes
    $str_content = strip_tags( $text_content );       // Remove Tags
    $word_count = str_word_count( $str_content );
    $readtime = ceil( $word_count / $wpm );
    if ($readtime == 1) {
        $postfix = " minute";
    } else {
        $postfix = " minutes";
    }
    $readingtime = $readtime . $postfix;
    return $readingtime;
}

add_filter( "term_links-post_tag", 'add_tag_class');

function add_tag_class($links) {
return str_replace('<a href="', '<a class="bg-white" href="', $links);
}

function gb_comment_form_tweaks ($fields) {
    //add placeholders and remove labels
    $fields['author'] = '<input id="author" name="author" value="" placeholder="Name*" size="30" maxlength="245" required="required" type="text">';

    $fields['email'] = '<input id="email" name="email" type="email" value="" placeholder="Email*" size="30" maxlength="100" aria-describedby="email-notes" required="required">';	

    //unset comment so we can recreate it at the bottom
    unset($fields['comment']);

    $fields['comment'] = '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" placeholder="Comment*" required="required"></textarea>';

    //remove website
    unset($fields['url']);

    return $fields;
}

add_filter('comment_form_fields', 'gb_comment_form_tweaks');


function bloggerspot_customize_register( $wp_customize ) {
    //All our sections, settings, and controls will be added here
 
     $wp_customize->add_panel('panel_id',array(
         'panel'=>'panel_id',
         'title'=>__('Theme Options', 'blogger-spot'),
         'priority'=>10,
     ));
 
     // Sections here.
     $wp_customize->add_section( 'header_section' , array(
         'panel' => 'panel_id',
     'title'      => __( 'Header Banner Text', 'blogger-spot' ),
     'priority'   => 10,
     ) );
 
     $wp_customize->add_section('footer_section', array(
         'panel' => 'panel_id',
         'title' => __('Footer Copyright Text', 'blogger-spot'),
         'priority' => 20,
     ));

     $wp_customize->add_section('top_section', array(
        'panel' => 'panel_id',
        'title' => __('Top Bar', 'blogger-spot'),
        'priority' => 30,
    ));
 
 
 
     // First Section.
   // Add setting
   $wp_customize->add_setting( 'header_text_block', array(
    'default'           => __( 'Add Your Text Here.', 'blogger-spot' ),
    'sanitize_callback' => 'sanitize_text'
) );
// Add control
$wp_customize->add_control( new WP_Customize_Control(
   $wp_customize,
   'header_text_block',
       array(
           'label'    => __( 'Home Banner Text', 'blogger-spot' ),
           'section'  => 'header_section',
           'settings' => 'header_text_block',
           'type'     => 'text',
           'priority' => 5,
       )
   )
);
     // Second Section 
     // Add Setting
     $wp_customize->add_setting( 'footer_text_block', array(
        'default'           => __( '© Copyright 2022 Blogger Spot.', 'blogger-spot' ),
        'sanitize_callback' => 'sanitize_text'
    ) );
    // Add control
    $wp_customize->add_control( new WP_Customize_Control(
       $wp_customize,
       'footer_text_block',
           array(
               'label'    => __( 'Footer Text', 'blogger-spot' ),
               'section'  => 'footer_section',
               'settings' => 'footer_text_block',
               'type'     => 'text',
               'priority' => 5,
           )
             
       )
    );

     // Third Section - one
     // Add Setting
     $wp_customize->add_setting( 'top_left_text_block', array(
        'default'           => __( 'Life is unpredictable.', 'blogger-spot' ),
        'sanitize_callback' => 'sanitize_text'
    ) );
    // Add control
    $wp_customize->add_control( new WP_Customize_Control(
       $wp_customize,
       'top_left_text_block',
           array(
               'label'    => __( 'Top Left Text', 'blogger-spot' ),
               'section'  => 'top_section',
               'settings' => 'top_left_text_block',
               'type'     => 'text',
               'priority' => 5,
           )
             
       )
    );

    // Third Section - two
     // Add Setting
     $wp_customize->add_setting( 'top_right_text_block', array(
        'default'           => __( 'Your Contact Details.', 'blogger-spot' ),
        'sanitize_callback' => 'sanitize_text'
    ) );
    // Add control
    $wp_customize->add_control( new WP_Customize_Control(
       $wp_customize,
       'top_right_text_block',
           array(
               'label'    => __( 'Top Right Text', 'blogger-spot' ),
               'section'  => 'top_section',
               'settings' => 'top_right_text_block',
               'type'     => 'text',
               'priority' => 5,
           )
             
       )
    );
   // Sanitize text
   function sanitize_text( $text ) {
    return sanitize_text_field( $text );
}
  
 }
add_action( 'customize_register', 'bloggerspot_customize_register' );


function home_banner_text(){
    echo esc_html(get_theme_mod( 'header_text_block'));
}
add_action('banner_text', 'home_banner_text');

function footer_copyright_text(){
    echo esc_html(get_theme_mod('footer_text_block'));
}
add_action('footer_text','footer_copyright_text');

function top_left_text(){
    echo esc_html(get_theme_mod('top_left_text_block'));
}
add_action('top_left_text','top_left_text');

function top_right_text(){
    echo esc_html(get_theme_mod('top_right_text_block'));
}
add_action('top_right_text','top_right_text');

function bloggerspot_widgets_init() {

    // First footer widget area, located in the footer. Empty by default.
	register_sidebar( array(
		'name' => __( 'First Footer Widget Area', 'blogger-spot' ),
		'id' => 'first-footer-widget-area',
		'description' => __( 'The first footer widget area', 'blogger-spot' ),
		'before_widget' => '<div id="%1$s" class="widget-container %2$s">',
		'after_widget' => '</div>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
		
}

// Register sidebars by running bloggerspot_widgets_init() on the widgets_init hook.
add_action( 'widgets_init', 'bloggerspot_widgets_init' );

function creator_theme()
{
    echo 'Developed by <a target="_blank" href="https://gouravbagora.com/">Gourav bagora</a>';
}
add_action('creator_theme','creator_theme');
?>