<?php
/**
 * Load files
 *
 * @package Wacko
 */

/**
 * Implement the Custom Header feature.
 */
require get_template_directory() . '/inc/custom-header.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';

/**
 * Include default theme options
 */
require_once get_template_directory() . '/inc/customizer/default.php';

/**
 * Customizer additions.
 */
require get_template_directory() . '/inc/customizer.php';

/**
 * Hook for page header
 */
require get_template_directory() . '/inc/hooks/page-header.php';

/**
 * Hook for home page content
 */
require get_template_directory() . '/inc/hooks/home-content.php';

/**
 * Hook for footer social media
 */
require get_template_directory() . '/inc/hooks/social-media.php';

/**
 * bootstrap navigation
 */
require get_template_directory() . '/inc/wp-bootstrap-navwalker.php';

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
    require get_template_directory() . '/inc/jetpack.php';
}

/**
 * Load Theme page
 */

if ( is_admin() ) {

    // Load About Wacko Info.
    require_once get_template_directory() . '/inc/about-wacko/about-wacko.php';

}


/**
 * welcome message
 */

function wacko_theme_activation_notice() {
    echo '<div class="notice notice-success is-dismissible">';
        echo '<p>'. esc_html__( 'Thank you for choosing Wacko ! Now you can visit our welcome page.', 'wacko' ) .'</p>';
        echo '<p><a href="'. esc_url( admin_url( 'themes.php?page=about-wacko' ) ) .'" class="button button-primary">'. esc_html__( 'Get Started with Wacko', 'wacko' ) .'</a></p>';
    echo '</div>';
}

/**
 * Filter the excerpt "read more" string.
 *
 * @param string $more "Read more" excerpt string.
 * @return string (Maybe) modified "read more" excerpt string.
 */
function wacko_excerpt_more( $more ) {
    return '&hellip;';
}
add_filter( 'excerpt_more', 'wacko_excerpt_more' );

/**
 * Filter the except length to 20 words.
 *
 * @param int $length Excerpt length.
 * @return int (Maybe) modified excerpt length.
 */
function wacko_custom_excerpt_length( $length ) {
    return 28;
}
if ( ! is_admin() ) {
    add_filter( 'excerpt_length', 'wacko_custom_excerpt_length', 999 );
}


/**
 * Function to check widget status
 */
 if ( ! function_exists( 'wacko_widget_count' ) ) :

 function wacko_widget_count( $sidebar_names ){

    $status = 0;

    foreach ($sidebar_names as $sidebar) {
      
        if( is_active_sidebar( $sidebar )){
            $status = $status+1;
        }
    }

    return $status;        
 }

endif;

/**
 * Function for owlcarousel dynamic slideSpeed and autoplayTimeout
 */
function wacko_load_owl_scripts() {

    $theme_options  = wacko_theme_options();

    wp_localize_script( 'wacko-custom', 'wacko_script_vars', array(
        'autoPlaySpeed'     => absint($theme_options['slider_transition_duration']*1000),
        'autoplayTimeout'   => absint($theme_options['slider_transition_delay']*1000),
        )
    );
 
}
add_action('wp_enqueue_scripts', 'wacko_load_owl_scripts');
