<?php 
/**
 * Breadcrumb init file
 * @since 1.0
 * @package RoyalNews
 */
royalnews_file_include( array(
	'third-party/breadcrumb/class-breadcrumb',
));

if( !function_exists( 'royalnews_breadcrumb_trail' ) ){	
	/**
	 * Shows a breadcrumb for all types of pages.  This is a wrapper function for the Breadcrumb_Trail class,
	 * which should be used in theme templates.
	 *
	 * @since  0.1.0
	 * @access public
	 * @param  array $args Arguments to pass to Breadcrumb_Trail.
	 * @return void
	 */
	function royalnews_breadcrumb_trail( $args = array() ) {
		$breadcrumb = apply_filters( 'royalnews_breadcrumb_trail_object', null, $args );

		if ( ! is_object( $breadcrumb ) )
			$breadcrumb = new RoyalNews_Breadcrumb_Trail( $args );

		return $breadcrumb->trail();
	}
}

if( !function_exists( 'royalnews_breadcrumb' ) ){
	/**
	 * Calling the main breadcrumb
	 * @since 1.0
	 * @package RoyalNews
	 */
	function royalnews_breadcrumb(){
		if( !royalnews_value( 'enable_breadcrumb' ) ){
			return;
		}
		if( is_home() || is_front_page() || is_404() ){
			return;
		}
		$args = array(
		    'container'   => 'div',
		    'show_browse' => false,
		);
		$args = apply_filters( 'royalnews-breadcrumb-args', $args );
		echo '<div class="royalnews-breadcrumb-wrapper">';
			royalnews_breadcrumb_trail( $args );
		echo '</div>';
	}
}

/**
 * Change home to icon
 * @since 1.0
 * @package RoyalNews
 */
function royalnews_change_home_title( $defaults ){
	$defaults[ 'home' ] = '<i class="fas fa-home"></i>';
	return $defaults;
}
add_filter( 'royalnews_breadcrumb_trail_labels', 'royalnews_change_home_title' );