get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'blog_kit_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'blog_kit_customize_partial_blogdescription', ) ); } //Logo Options Setting Starts $wp_customize->add_setting('theme_options[site_identity]', array( 'default' => 'title-text', 'sanitize_callback' => 'blog_kit_sanitize_select' ) ); $wp_customize->add_control('theme_options[site_identity]', array( 'type' => 'radio', 'label' => esc_html__('Logo Options', 'blog-kit'), 'section' => 'title_tagline', 'choices' => array( 'logo-only' => esc_html__('Logo Only', 'blog-kit'), 'title-text' => esc_html__('Title + Tagline', 'blog-kit'), 'logo-desc' => esc_html__('Logo + Tagline', 'blog-kit') ) ) ); // Add Theme Options Panel. $wp_customize->add_panel( 'theme_option_panel', array( 'title' => esc_html__( 'Theme Options', 'blog-kit' ), 'priority' => 100, ) ); // Layout Section. $wp_customize->add_section( 'section_layout', array( 'title' => esc_html__( 'Layouts', 'blog-kit' ), 'priority' => 100, 'panel' => 'theme_option_panel', ) ); // Setting global_layout. $wp_customize->add_setting( 'theme_options[global_layout]', array( 'default' => 'right-sidebar', 'sanitize_callback' => 'blog_kit_sanitize_select', ) ); $wp_customize->add_control( 'theme_options[global_layout]', array( 'label' => esc_html__( 'Default Sidebar Layout', 'blog-kit' ), 'section' => 'section_layout', 'type' => 'radio', 'priority' => 100, 'choices' => array( 'left-sidebar' => esc_html__( 'Sidebar / Content', 'blog-kit' ), 'right-sidebar' => esc_html__( 'Content / Sidebar', 'blog-kit' ), ), ) ); // Setting excerpt_length. $wp_customize->add_setting( 'theme_options[excerpt_length]', array( 'default' => 40, 'sanitize_callback' => 'absint', ) ); $wp_customize->add_control( 'theme_options[excerpt_length]', array( 'label' => esc_html__( 'Excerpt Length', 'blog-kit' ), 'section' => 'section_layout', 'type' => 'number', 'priority' => 100, 'input_attrs' => array( 'min' => 1, 'max' => 500, 'style' => 'width: 55px;' ), ) ); // Setting readmore_text. $wp_customize->add_setting( 'theme_options[readmore_text]', array( 'default' => esc_html__( 'Read More', 'blog-kit' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'theme_options[readmore_text]', array( 'label' => esc_html__( 'Read More Text', 'blog-kit' ), 'section' => 'section_layout', 'type' => 'text', 'priority' => 100, ) ); // Footer Section. $wp_customize->add_section( 'section_footer', array( 'title' => esc_html__( 'Footer', 'blog-kit' ), 'priority' => 100, 'panel' => 'theme_option_panel', ) ); // Setting copyright_text. $wp_customize->add_setting( 'theme_options[copyright_text]', array( 'default' => esc_html__( 'Copyright © All rights reserved.', 'blog-kit' ), 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( 'theme_options[copyright_text]', array( 'label' => esc_html__( 'Copyright Text', 'blog-kit' ), 'section' => 'section_footer', 'type' => 'text', 'priority' => 100, ) ); } add_action( 'customize_register', 'blog_kit_customize_register' ); /** * Render the site title for the selective refresh partial. * * @return void */ function blog_kit_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @return void */ function blog_kit_customize_partial_blogdescription() { bloginfo( 'description' ); } if ( ! function_exists( 'blog_kit_sanitize_select' ) ) : /** * Sanitize select. * * @since 1.0.0 * * @param mixed $input The value to sanitize. * @param WP_Customize_Setting $setting WP_Customize_Setting instance. * @return mixed Sanitized value. */ function blog_kit_sanitize_select( $input, $setting ) { // Ensure input is clean. $input = sanitize_text_field( $input ); // Get list of choices from the control associated with the setting. $choices = $setting->manager->get_control( $setting->id )->choices; // If the input is a valid key, return it; otherwise, return the default. return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } endif; /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function blog_kit_customize_preview_js() { wp_enqueue_script( 'blog-kit-customizer', get_template_directory_uri() . '/assets/js/customizer.js', array( 'customize-preview' ), '1.0', true ); } add_action( 'customize_preview_init', 'blog_kit_customize_preview_js' );