<?php
/**
 * @package Charity Trust
 */

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

	return $updated_defaults;
}
add_filter( 'charity_trust_customizer_defaults', 'charity_trust_customizer_add_defaults' );

function charity_trust_gtm( $option ) {
	$defaults = apply_filters( 'charity_trust_customizer_defaults', true );

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

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

		$length	= charity_trust_gtm( 'charity_trust_excerpt_length' );

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