<?php
/**
 * @package Ice Cream Dish
 */

function ice_cream_dish_customizer_add_defaults( $default_options) {
	$defaults = array(
		'ice_cream_dish_excerpt_length'    => 30,
	);
	$updated_defaults = wp_parse_args( $defaults, $default_options );

	return $updated_defaults;
}
add_filter( 'ice_cream_dish_customizer_defaults', 'ice_cream_dish_customizer_add_defaults' );

function ice_cream_dish_gtm( $option ) {
	$defaults = apply_filters( 'ice_cream_dish_customizer_defaults', true );

	return isset( $defaults[ $option ] ) ? get_theme_mod( $option, $defaults[ $option ] ) : get_theme_mod( $option );
}

if ( ! function_exists( 'ice_cream_dish_excerpt_length' ) ) :
	function ice_cream_dish_excerpt_length( $length ) {
		if ( is_admin() ) {
			return $length;
		}

		$length	= ice_cream_dish_gtm( 'ice_cream_dish_excerpt_length' );

		return absint( $length );
	} 
endif;
add_filter( 'excerpt_length', 'ice_cream_dish_excerpt_length', 999 );