<?php


if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly


/*
 * Add chessgames to main RSS Feed.
 *
 * @since 1.0.8
 */
function chessgame_shizzle_rss_feed( $qv ) {

	if ( isset($qv['feed'] ) && ! isset($qv['post_type']) ) {
		if (get_option( 'chessgame_shizzle-rss', 'true') === 'true') {
			$qv['post_type'] = array( 'post', 'cs_chessgame' );
			return $qv;
		}
	} else if ( isset($qv['feed'] ) && isset($qv['post_type']) ) {
		if (get_option( 'chessgame_shizzle-rss', 'true') === 'true') {
			$qv['post_type'][] = 'cs_chessgame';
			return $qv;
		}
	}

	return $qv;

}
add_filter('request', 'chessgame_shizzle_rss_feed');


/*
 * Add chessgames to blog page.
 *
 * @since 1.3.3
 */
function chessgame_shizzle_blogpage( $query ) {

	if ( ! is_admin() && $query->is_main_query() && is_home() ) {
		if ( get_option( 'chessgame_shizzle-blogpage', false ) === 'true' ) {
			$post_type = $query->get( 'post_type' );
			if ( $post_type === '' || $post_type === 'post' ) {
				$query->set( 'post_type', array( 'post', 'cs_chessgame' ) );
			} else if ( is_array( $post_type ) ) {
				$post_type[] = 'cs_chessgame';
				$query->set( 'post_type', $post_type );
			}
		}
	}

}
add_action('pre_get_posts', 'chessgame_shizzle_blogpage');
