<?php
/**
 * Custom functions that act independently of the theme templates
 *
 * Eventually, some of the functionality here could be replaced by core features
 */


/**
 * Adds custom classes to the array of body classes.
 *
 * @param $classes
 *
 * @return array
 */
function good_body_classes( $classes ) {

	$classes[] = good_get_option( 'layout_text_align' ) ? 'center-aligned' : '';
	$classes[] = good_get_option( 'sticky_navigation' ) ? 'sticky-navigation' : '';

	// Adds a class of group-blog to blogs with more than 1 published author
	if ( is_multi_author() ) {
		$classes[] = 'group-blog';
	}

	return $classes;
}

add_filter( 'body_class', 'good_body_classes' );


/**
 * Set the excerpt length.
 *
 * @param $length
 *
 * @return int
 */
function good_excerpt_length( $length ) {
	return 40;
}

add_filter( 'excerpt_length', 'good_excerpt_length', 999 );


/**
 * Set the excerpt more text
 *
 * @param $more
 *
 * @return string
 */
function good_excerpt_more( $more ) {
	return '...';
}

add_filter( 'excerpt_more', 'good_excerpt_more' );


/**
 * Exclude some posts with certain categories from recent posts stream
 *
 * @param $query WP_Query
 */
function good_exclude_categories( $query ) {

	if ( $query->is_home() && $query->is_main_query() && good_get_option( 'exclude_categories' ) ) {
		$query->query_vars['category__not_in'] = good_get_option( 'exclude_categories' );
	}

}

add_action( 'pre_get_posts', 'good_exclude_categories' );
