get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // Layout section $wp_customize->add_section( 'calibration_layout', array( 'priority' => 100, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => __( 'Layout', 'calibration' ), 'description' => __( 'Here you can customize the layout options.', 'calibration' ), ) ); // Layout choosing $wp_customize->add_setting( 'calibration_site_layout', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_radio', 'default' => $calibration_theme_mods['calibration_site_layout'], ) ); $wp_customize->add_control( 'calibration_site_layout', array( 'label' => esc_html__( 'Switch site layout', 'calibration' ), 'section' => 'calibration_layout', 'type' => 'radio', 'choices' => array( 'sidebar_r' => esc_html__( 'Right Sidebar','calibration' ), 'sidebar_l' => esc_html__( 'Left Sidebar','calibration' ), 'sidebar_b' => esc_html__( 'Bottom Sidebar','calibration' ), ) ) ); // Top menu hiding $wp_customize->add_setting( 'calibration_show_menu', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_checkbox', 'default' => $calibration_theme_mods['calibration_show_menu'], ) ); $wp_customize->add_control( 'calibration_show_menu', array( 'type' => 'checkbox', 'section' => 'menu_locations', 'label' => esc_html__( 'Display Top Menu', 'calibration' ), ) ); // Static Front page options $wp_customize->add_setting( 'calibration_show_front_title', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_checkbox', 'default' => $calibration_theme_mods['calibration_show_front_title'], ) ); $wp_customize->add_control( 'calibration_show_front_title', array( 'type' => 'checkbox', 'section' => 'static_front_page', 'label' => esc_html__( 'Display homepage title', 'calibration' ), ) ); $wp_customize->add_setting( 'calibration_front_layout', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_select', 'default' => $calibration_theme_mods['calibration_front_layout'], ) ); $wp_customize->add_control( 'calibration_front_layout', array( 'type' => 'select', 'section' => 'static_front_page', 'label' => esc_html__( 'Homepage layout', 'calibration' ), 'choices' => array( '' => sprintf( /* translators: %s: site layout choice label */ esc_html__('Site Layout %s','calibration'), "({$wp_customize->get_control( 'calibration_site_layout' )->choices[$calibration_theme_mods['calibration_site_layout']]})" ), 'sidebar_r' => esc_html__( 'Right Sidebar','calibration' ), 'sidebar_l' => esc_html__( 'Left Sidebar','calibration' ), 'sidebar_b' => esc_html__( 'Bottom Sidebar','calibration' ), ), ) ); // Posts section $wp_customize->add_section( 'calibration_posts', array( 'priority' => 150, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => esc_html__( 'Posts', 'calibration' ), 'description' => esc_html__( 'Here you can customize options for posts.', 'calibration' ), ) ); // Post list options $wp_customize->add_setting( 'calibration_show_post_as', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_select', 'default' => $calibration_theme_mods['calibration_show_post_as'], ) ); $wp_customize->add_control( 'calibration_show_post_as', array( 'type' => 'select', 'section' => 'calibration_posts', 'label' => esc_html__( 'Show post as', 'calibration' ), 'description' => esc_html__( 'What should the post list include on the front page or blog?', 'calibration' ), 'choices' => array( 'post_content' => esc_html__( 'Content', 'calibration' ), 'post_excerpt' => esc_html__( 'Excerpt', 'calibration' ), 'post_title' => esc_html__( 'Title', 'calibration' ), ), ) ); $wp_customize->add_setting( 'calibration_apply_post_format', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_checkbox', 'default' => $calibration_theme_mods['calibration_apply_post_format'], ) ); $wp_customize->add_control( 'calibration_apply_post_format', array( 'type' => 'checkbox', 'section' => 'calibration_posts', 'label' => esc_html__( 'Apply post format template', 'calibration' ), 'description' => esc_html__( 'Uncheck if you want all posts on the list to look similar regardless format.', 'calibration' ), ) ); // Default category hiding $wp_customize->add_setting( 'calibration_hide_default_category', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_checkbox', 'default' => $calibration_theme_mods['calibration_hide_default_category'], ) ); $wp_customize->add_control( 'calibration_hide_default_category', array( 'type' => 'checkbox', 'section' => 'calibration_posts', 'label' => sprintf( /* translators: %s: default category */ esc_html__( 'Hide default category: %s', 'calibration' ), get_cat_name( get_option( 'default_category' ) ) ), 'description' => sprintf( /* translators: %s: Built in "Uncategorized" category name */ esc_html__( 'Useful as long as you keep "%s" as default category.', 'calibration' ), __( 'Uncategorized' ) ), ) ); // Footer content section $wp_customize->add_section( 'calibration_footer_content', array( 'priority' => 150, 'capability' => 'edit_theme_options', 'theme_supports' => '', 'title' => esc_html__( 'Footer Content', 'calibration' ), 'description' => esc_html__( 'Here you can write your own footer content.', 'calibration' ), ) ); // Footer title text input $wp_customize->add_setting( 'calibration_footer_title', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_linked_text', 'default' => $calibration_theme_mods['calibration_footer_title'], ) ); $wp_customize->add_control( 'calibration_footer_title', array( 'type' => 'text', 'section' => 'calibration_footer_content', 'label' => esc_html__( 'Title', 'calibration' ), ) ); // Footer entry textarea $wp_customize->add_setting( 'calibration_footer_entry', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_linked_text', 'default' => $calibration_theme_mods['calibration_footer_entry'], ) ); $wp_customize->add_control( 'calibration_footer_entry', array( 'type' => 'textarea', 'priority' => 10, 'section' => 'calibration_footer_content', 'label' => esc_html__( 'Entry', 'calibration' ), ) ); // Display Privacy Policy link if ( function_exists( 'get_the_privacy_policy_link' ) ) : $wp_customize->add_setting( 'calibration_show_privacy_policy', array( 'capability' => 'edit_theme_options', 'transport' => 'postMessage', 'sanitize_callback' => 'calibration_sanitize_checkbox', 'default' => $calibration_theme_mods['calibration_show_privacy_policy'], ) ); $wp_customize->add_control( 'calibration_show_privacy_policy', array( 'type' => 'checkbox', 'section' => 'calibration_footer_content', 'label' => esc_html__( 'Display Privacy Policy Link', 'calibration' ), 'description' => '' . esc_html__( 'Privacy settings', 'calibration' ) . '', ) ); endif; // Add partials for selective refresh if ( isset( $wp_customize->selective_refresh ) ) : $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.logo', 'render_callback' => 'calibration_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.tagline', 'render_callback' => 'calibration_customize_partial_blogdescription', ) ); $wp_customize->selective_refresh->add_partial( 'calibration_partial_posts_list', array( 'selector' => '.wp-article-list', 'settings' => array( 'calibration_show_post_as', 'calibration_apply_post_format', 'calibration_hide_default_category' ), 'render_callback' => 'calibration_customize_partial_posts_list' ) ); $wp_customize->selective_refresh->add_partial( 'calibration_partial_footer_title', array( 'selector' => '.footer-title', 'settings' => array( 'calibration_footer_title' ), 'render_callback' => 'calibration_customize_partial_footer_title', ) ); $wp_customize->selective_refresh->add_partial( 'calibration_partial_footer_entry', array( 'selector' => '.footer-entry', 'settings' => array( 'calibration_footer_entry' ), 'render_callback' => 'calibration_customize_partial_footer_entry', ) ); endif; } /** * Render the site title for the selective refresh partial. * * @since 1.0.0 * * @return void */ function calibration_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. * * @since 1.0.0 * * @return void */ function calibration_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Render the posts list for the selective refresh partial. * * @since 1.0.0 * * @return void */ function calibration_customize_partial_posts_list() { while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', calibration_get_theme_mod( 'calibration_apply_post_format' ) ? get_post_format() : false ); endwhile; } /** * Render the footer title for the selective refresh partial. * * @since 1.0.0 * * @return void */ function calibration_customize_partial_footer_title() { echo nl2br( calibration_sanitize_linked_text( calibration_get_theme_mod( 'calibration_footer_title', true ) ) ); } /** * Render the footer entry for the selective refresh partial. * * @since 1.0.0 * * @return void */ function calibration_customize_partial_footer_entry() { echo nl2br( calibration_sanitize_linked_text( calibration_get_theme_mod( 'calibration_footer_entry', true ) ) ); } if ( ! function_exists( 'calibration_sanitize_radio' ) ) : /** * Handles radio sanitization. * * @since 1.0.0 * * @param string $input Setting value to be sanitized * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object. * @return string Chosen value */ function calibration_sanitize_radio( $input, $setting ) { $input = sanitize_key($input); $choices = $setting->manager->get_control( $setting->id )->choices; return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } endif; if ( ! function_exists( 'calibration_sanitize_checkbox' ) ) : /** * Handles checkbox sanitization. * * @since 1.0.0 * * @param boolean|null $checked Checked option if exists * @return boolean Checked value */ function calibration_sanitize_checkbox( $checked ) { return ( ( isset( $checked ) && true == $checked ) ? true : false ); } endif; if ( ! function_exists( 'calibration_sanitize_select' ) ) : /** * Handles select sanitization. * * @since 1.0.0 * * @param string $input Setting value to be sanitized * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object. * @return string Setting value */ function calibration_sanitize_select( $input, $setting ) { $input = sanitize_key( $input ); $choices = $setting->manager->get_control( $setting->id )->choices; return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); } endif; if ( ! function_exists( 'calibration_sanitize_linked_text' ) ) : /** * Handles sanitization for text including links. * * @since 1.0.0 * * @param string $text Text to be sanitized preserving links * @return string Text with links */ function calibration_sanitize_linked_text( $text ) { return wp_kses( $text, array( 'a' => array( 'id' => array(), 'class' => array(), 'href' => array(), 'title' => array(), 'target' => array(), ), 'span' => array( 'id' => array(), 'class' => array(), ), 'br' => array(), 'b' => array(), 'strong' => array(), 'i' => array(), 'em' => array(), ) ); } endif; add_action( 'customize_preview_init', 'calibration_customize_preview_js' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. * * Acion hook: 'customize_preview_init' * * @since 1.0.0 */ function calibration_customize_preview_js() { wp_enqueue_script( 'calib-customizer', CALIB_JS_URI . 'customizer.js', array( 'customize-preview' ), calibration_ver(), true ); // Set initial visibility for some elements $calibration_theme_mods = calibration_get_theme_mods(); $menu_visibility = ( $calibration_theme_mods['calibration_show_menu'] ? 'visible' : 'hidden' ); $front_title_display = ( $calibration_theme_mods['calibration_show_front_title'] ? 'block' : 'none' ); $privacy_policy_display = ( $calibration_theme_mods['calibration_show_privacy_policy'] ? 'block' : 'none' ); wp_add_inline_script( 'calib-customizer', " (function($) { $( '#nav' ).css('visibility', '$menu_visibility'); $( '.home h1.entry-title' ).css('display', '$front_title_display'); $( '#footer .privacy-policy-link' ).css('display', '$privacy_policy_display'); })(jQuery);" ); } add_action( 'customize_controls_enqueue_scripts', 'calibration_customize_controls_js' ); /** * Adds custom behaviour to Customizer controls. * * Acion hook: 'customize_controls_enqueue_scripts' * * @since 1.0.0 */ function calibration_customize_controls_js() { wp_enqueue_script( 'calib-customize-controls', CALIB_JS_URI . 'customizer-controls.js', array( 'customize-controls' ), calibration_ver(), true ); }