<?php
/**
 * Smerk Customizer support
 *
 * @package WordPress
 * @subpackage Smerk
 * @since Smerk 1.0
 */

/**
 * Implement Customizer additions and adjustments.
 *
 * @since Smerk 1.0
 *
 * @param WP_Customize_Manager $wp_customize Customizer object.
 */
function smerk_customize_register( $wp_customize ) {
	// Add postMessage support for site title and description.
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';

    $wp_customize->remove_section( 'colors' );
	$wp_customize->remove_section( 'background_image' );
	$wp_customize->remove_section( 'header_image' );
	


	// Rename the label to "Display Site Title & Tagline" in order to make this option extra clear.
	$wp_customize->get_control( 'display_header_text' )->label = __( 'Display Site Title &amp; Tagline', 'smerk' );



    //******************************include Site Panel***********************************************//
	
    require get_template_directory() . '/inc/custom_customizer_settings/site.php';
	
	//**********************************include Header Panel****************************************//
	
	require get_template_directory() . '/inc/custom_customizer_settings/customizer_header.php';
	
	//**********************************include Navigation Panel***********************************//

	require get_template_directory() . '/inc/custom_customizer_settings/navigation.php';
	
	//**********************************include Footer Panel**************************************//
	
	require get_template_directory() . '/inc/custom_customizer_settings/customizer_footer.php';
	
    
	// Add the featured content section in case it's not already there.
	$wp_customize->add_section( 'featured_content', array(
		'title'           => __( 'Featured Content', 'smerk' ),
		'description'     => sprintf( __( 'Use a <a href="%1$s">tag</a> to feature your posts. If no posts match the tag, <a href="%2$s">sticky posts</a> will be displayed instead.', 'smerk' ),
			esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'smerk' ), admin_url( 'edit.php' ) ) ),
			admin_url( 'edit.php?show_sticky=1' )
		),
		'priority'        => 130,
		'active_callback' => 'is_front_page',
	) );

	
}
add_action( 'customize_register', 'smerk_customize_register' );

/**
 * Sanitize the Featured Content layout value.
 *
 * @since Smerk 1.0
 *
 * @param string $layout Layout type.
 * @return string Filtered layout type (grid|slider).
 */
function smerk_sanitize_layout( $layout ) {
	if ( ! in_array( $layout, array( 'grid', 'slider' ) ) ) {
		$layout = 'grid';
	}

	return $layout;
}

/**
 * Bind JS handlers to make Customizer preview reload changes asynchronously.
 *
 * @since Smerk 1.0
 */
function smerk_customize_preview_js() {
	wp_enqueue_script( 'smerk_customizer', get_template_directory_uri() . '/assets/js/customize-preview.js', array( 'customize-preview' ), '20131205', true );
}
add_action( 'customize_preview_init', 'smerk_customize_preview_js' );

/**
 * Add contextual help to the Themes and Post edit screens.
 *
 * @since Smerk 1.0
 */
function smerk_contextual_help() {
	if ( 'admin_head-edit.php' === current_filter() && 'post' !== $GLOBALS['typenow'] ) {
		return;
	}

	get_current_screen()->add_help_tab( array(
		'id'      => 'smerk',
		'title'   => __( 'Smerk', 'smerk' ),
		'content' =>
			'<ul>' .
				'<li>' . sprintf( __( 'The home page features your choice of up to 6 posts prominently displayed in a grid or slider, controlled by a <a href="%1$s">tag</a>; you can change the tag and layout in <a href="%2$s">Appearance &rarr; Customize</a>. If no posts match the tag, <a href="%3$s">sticky posts</a> will be displayed instead.', 'smerk' ), esc_url( add_query_arg( 'tag', _x( 'featured', 'featured content default tag slug', 'smerk' ), admin_url( 'edit.php' ) ) ), admin_url( 'customize.php' ), admin_url( 'edit.php?show_sticky=1' ) ) . '</li>' .
				'<li>' . sprintf( __( 'Enhance your site design by using <a href="%s">Featured Images</a> for posts you&rsquo;d like to stand out (also known as post thumbnails). This allows you to associate an image with your post without inserting it. Smerk uses featured images for posts and pages&mdash;above the title&mdash;and in the Featured Content area on the home page.', 'smerk' ), 'https://codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail' ) . '</li>' .
				'<li>' . sprintf( __( 'For an in-depth tutorial, and more tips and tricks, visit the <a href="%s">Smerk documentation</a>.', 'smerk' ), 'https://codex.wordpress.org/' ) . '</li>' .
			'</ul>',
	) );
}
add_action( 'admin_head-themes.php', 'smerk_contextual_help' );
add_action( 'admin_head-edit.php',   'smerk_contextual_help' );
