<?php

function kindrex_sanitize_html( $html ) {
	return wp_filter_post_kses( $html );
}

function kindrex_sanitize_checkbox( $input ) {
	return ( ( isset( $input ) && true === $input ) ? true : false );
}

//select sanitization function
function kindrex_sanitize_select( $input, $setting ) {
	//input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only
	$input = sanitize_key( $input );

	//get the list of possible select options
	$choices = $setting->manager->get_control( $setting->id )->choices;

	//return input if valid or return default option
	return ( array_key_exists( $input, $choices ) ? $input : $setting->default );

}

//makes replying look neat
if ( ! function_exists( 'kindrex_threaded_comments' ) ) :
	function kindrex_threaded_comments() {
		if ( get_option( 'thread_comments' ) ) {
			wp_enqueue_script( 'comment-reply' );
		}
	}
	add_action( 'wp_enqueue_scripts', 'kindrex_threaded_comments' );
endif;

// displays "Comments are closed" instead of comment form when comments are closed.
if ( ! function_exists( 'kindrex_closed_comments' ) ) :
	function kindrex_closed_comments() {
		echo '<p>', esc_html__( 'Comments are closed.', 'kindrex' ), '</p>';
	}
	add_action( 'comment_form_comments_closed', 'kindrex_closed_comments' );
endif;
