<?php
/**
 * Custom header implementation
 */

function dinero_custom_header_setup() {
	add_theme_support( 'custom-header', apply_filters( 'dinero_custom_header_args', array(
		'default-image'      => get_parent_theme_file_uri( '/assets/images/header-default.png' ),
		'header-text' 	     =>	false,
		'width'              => 1400,
		'height'             => 400,
		'flex-width'         => true,
		'flex-height'        => true,
		'wp-head-callback'   => 'dinero_header_style',
	) ) );

	register_default_headers( array(
		'default-image' => array(
			'url'           => '%s/assets/images/header-default.png',
			'thumbnail_url' => '%s/assets/images/header-default.png',
			'description'   => __( 'Default Header Image', 'dinero' ),
		),
	) );
}

add_action( 'after_setup_theme', 'dinero_custom_header_setup' );

if ( ! function_exists( 'dinero_header_style' ) ) :
/**
 * Styles the header image and text displayed on the blog
 *
 * @see dinero_custom_header_setup().
 */
add_action( 'wp_enqueue_scripts', 'dinero_header_style' );
function dinero_header_style() {
	//Check if user has defined any header image.
	if ( get_header_image() ) :

		if( !is_singular() ){
			$dinero_custom_style = " #inner-pages-header {
				background-image:url('".esc_url(get_header_image())."');
				background-size: cover;
				background-repeat: no-repeat;
			}";
		   	wp_add_inline_style( 'dinero-basic-style', $dinero_custom_style );
	   }
	endif;
}
endif; // dinero_header_style