<?php
/**
 * Custom functions for this theme.
 *
 * Eventually, some of the functionality here could be replaced by core features.
 *
 * @package Super_Blog
 */

//=============================================================
// Function to display featured image
//=============================================================
if ( ! function_exists( 'super_blog_featured_image_disaplay' ) ) :
/**
 * Display featured image of the post
 */
	function super_blog_featured_image_disaplay(){
		if ( has_post_thumbnail() && ! post_password_required() && ! is_attachment() ) {  // check if the post has a Post Thumbnail assigned to it. 
	        echo '<div class="featured-image">';
	            the_post_thumbnail('super-blog-full');
	        echo '</div>';
	    } 
	}
endif;

//=============================================================
// Function to change default excerpt
//=============================================================
if ( ! function_exists( 'super_blog_excerpt_more' ) ) :

	function super_blog_excerpt_more( $more ) {

		$read_more = get_theme_mod('readmore');

		$readmore = ( !empty( $read_more )) ? $read_more : __(' Read More', 'super-blog');

	    return '&hellip;<p class="read-more"><a class="btn btn-default" href="'. esc_url(get_permalink( get_the_ID() )) . '">' . esc_html($readmore) . '<span class="screen-reader-text"> '. __(' Read More', 'super-blog').'</span></a></p>';

	}

endif;
add_filter( 'excerpt_more', 'super_blog_excerpt_more' );

//=============================================================
// Function to change length of excerpt
//=============================================================
if ( ! function_exists( 'super_blog_excerpt_length' ) ) :

	function super_blog_excerpt_length( $length ) {

		$excerpt = get_theme_mod('excerpt_length');

		$excerpt_length = (!empty( $excerpt )) ? $excerpt : 60;

	    return absint($excerpt_length);
	}

endif;

add_filter( 'excerpt_length', 'super_blog_excerpt_length', 999 );

//=============================================================
// Function to check widget status
//=============================================================
 if ( ! function_exists( 'super_blog_widget_count' ) ) :

 function super_blog_widget_count( $sidebar_names ){

    $status = 0;

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

    return $status;        
 }

endif;

//=============================================================
// Menu Fallback function
//=============================================================

if ( !function_exists('super_blog_menu_fallback') ) :

function super_blog_menu_fallback(){

	echo '<ul id="menu-main-menu" class="menu">';
		echo '<li class="menu-item"><a href="' . esc_url( home_url( '/' ) ) . '">' . __( 'Home', 'super-blog' ). '</a></li>';
		wp_list_pages( array(
			'title_li' => '',
			'depth'    => 1,
			'number'   => 5,
		) );
		echo '</ul>';
	
}

endif;

/**
 * Register the required plugins for this theme.
 * 
 * This function is hooked into `tgmpa_register`, which is fired on the WP `init` action on priority 10.
 */
function super_blog_register_required_plugins() {
    /*
     * Array of plugin arrays. Required keys are name and slug.
     * If the source is NOT from the .org repo, then source is also required.
     */
    $plugins = array(      
        array(
            'name'      => esc_html__( 'Aarambha Demo Sites', 'super-blog' ), //The plugin name
            'slug'      => 'aarambha-demo-sites',  // The plugin slug (typically the folder name)
            'required'  => false,  // If false, the plugin is only 'recommended' instead of required.
            'force_activation'   => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
            'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
        ),    
              
    );

    $config = array(
        'id'           => 'super-blog',        // Unique ID for hashing notices for multiple instances of TGMPA.
        'default_path' => '',                      // Default absolute path to bundled plugins.     
        'has_notices'  => true,                    // Show admin notices or not.
        'dismissable'  => true,                    // If false, a user cannot dismiss the nag message.
        'dismiss_msg'  => '',                      // If 'dismissable' is false, this message will be output at top of nag.
        'is_automatic' => false,                   // Automatically activate plugins after installation or not.
        'message'      => '',                      // Message to output right before the plugins table.
        );

    tgmpa( $plugins, $config );
}
add_action( 'tgmpa_register', 'super_blog_register_required_plugins' );
