get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; $wp_customize->add_setting( 'bestblogger_primary_color', array( 'default' => '#1a73e8', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'bestblogger_primary_color', array( 'label' => __( 'Primary Color', 'bestblogger' ), 'section' => 'colors', 'settings' => 'bestblogger_primary_color', 'priority' => 3, ) ) ); $wp_customize->add_setting( 'bestblogger_secondary_color', array( 'default' => '#656565', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'bestblogger_secondary_color', array( 'label' => __( 'Secondary Color', 'bestblogger' ), 'section' => 'colors', 'settings' => 'bestblogger_secondary_color', 'priority' => 5, ) ) ); $wp_customize->add_setting( 'bestblogger_text_color', array( 'default' => '#333333', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'bestblogger_text_color', array( 'label' => __( 'Text Color', 'bestblogger' ), 'section' => 'colors', 'settings' => 'bestblogger_text_color', 'priority' => 7, ) ) ); $wp_customize->add_setting( 'bestblogger_hover_color', array( 'default' => '#2382ff', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_hex_color', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'bestblogger_hover_color', array( 'label' => __( 'Hover Color', 'bestblogger' ), 'section' => 'colors', 'settings' => 'bestblogger_hover_color', 'priority' => 8, ) ) ); $wp_customize->add_section( 'bestblogger_theme_options', array( 'title' => __( 'Theme options', 'bestblogger' ), 'priority' => 30, ) ); $wp_customize->add_setting( 'bestblogger_sidebar_pos', array( 'default' => 'right', 'transport' => 'postMessage', 'sanitize_callback' => 'sanitize_text_field', ) ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'bestblogger_sidebar_pos', array( 'label' => __( 'Sidebar Position', 'bestblogger' ), 'section' => 'bestblogger_theme_options', 'settings' => 'bestblogger_sidebar_pos', 'type' => 'radio', 'choices' => array( 'right' => __( 'Right sidebar', 'bestblogger' ), 'no' => __( 'No sidebar', 'bestblogger' ), ), ) ) ); $wp_customize->add_setting( 'bestblogger_footer_copyright', array( 'default' => 'Copyright', 'transport' => 'postMessage', 'sanitize_callback' => 'wp_kses_post', ) ); $wp_customize->add_control( 'bestblogger_footer_copyright', array( 'type' => 'textarea', 'section' => 'bestblogger_theme_options', 'label' => __( 'Footer Copyright', 'bestblogger' ), 'description' => __( 'Add Custom Copyright Text here.', 'bestblogger' ), ) ); $wp_customize->add_setting( 'bestblogger_footer_copyright_right', array( 'default' => 'Copyright', 'transport' => 'postMessage', 'sanitize_callback' => 'wp_kses_post', ) ); $wp_customize->add_control( 'bestblogger_footer_copyright_right', array( 'type' => 'textarea', 'section' => 'bestblogger_theme_options', 'label' => __( 'Footer Copyright (Right)', 'bestblogger' ), 'description' => __( 'Add Custom Copyright Text here.', 'bestblogger' ), ) ); if ( isset( $wp_customize->selective_refresh ) ) { $wp_customize->selective_refresh->add_partial( 'blogname', array( 'selector' => '.site-title a', 'render_callback' => 'bestblogger_customize_partial_blogname', ) ); $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 'selector' => '.site-description', 'render_callback' => 'bestblogger_customize_partial_blogdescription', ) ); $wp_customize->selective_refresh->add_partial( 'bestblogger_dynamic_css', array( 'selector' => '#bestblogger_dynamic_css', 'render_callback' => 'bestblogger_customizer_dynamic_css', 'settings' => array( 'bestblogger_primary_color', 'bestblogger_secondary_color', 'bestblogger_text_color', 'bestblogger_hover_color', ), ) ); $wp_customize->selective_refresh->add_partial( 'theme_name_here_sidebar_pos', array( 'selector' => '.empty-node', 'render_callback' => '__return_empty_string', ) ); $wp_customize->selective_refresh->add_partial( 'bestblogger_footer_copyright', array( 'selector' => '#footer_copyright', 'render_callback' => 'bestblogger_customize_partial_footer_copyright', ) ); $wp_customize->selective_refresh->add_partial( 'bestblogger_footer_copyright_right', array( 'selector' => '#footer_copyright_right', 'render_callback' => 'bestblogger_customize_partial_footer_copyright_right', ) ); } } add_action( 'customize_register', 'bestblogger_customize_register' ); /** * Render the site title for the selective refresh partial. */ function bestblogger_customize_partial_blogname() { bloginfo( 'name' ); } /** * Render the site tagline for the selective refresh partial. */ function bestblogger_customize_partial_blogdescription() { bloginfo( 'description' ); } /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function bestblogger_customize_preview_js() { wp_enqueue_script( 'bestblogger-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20151215', true ); } add_action( 'customize_preview_init', 'bestblogger_customize_preview_js' ); /** * Fix for load customizer from js only */ function bestblogger_append_empty_node() { printf( '' ); } add_action( 'wp_footer', 'bestblogger_append_empty_node' ); /** * Generate dynamic css based on users selection. */ function bestblogger_customizer_dynamic_css() { $primary_color = esc_attr( get_theme_mod( 'bestblogger_primary_color', '#1a73e8' ) ); $secondary_color = esc_attr( get_theme_mod( 'bestblogger_secondary_color', '#656565' ) ); $text_color = esc_attr( get_theme_mod( 'bestblogger_text_color', '#333333' ) ); $hover_color = esc_attr( get_theme_mod( 'bestblogger_hover_color', '#2382ff' ) ); printf( '.primary-bg, .btn-primary, .site-header .bootsnipp-search .search-form .input-group-btn > .search-submit, .navbar-default .navbar-nav > .current-menu-item > a:after, .widget .widget-title:after, .comment-form .form-submit input[type="submit"], .calendar_wrap > table > tbody tr td#today, .page-header:after, .page .entry-header:after, .comment-list .comment .reply .comment-reply-link { background-color: %s; }', $primary_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( 'a, .primary-text { color: %s; }', $primary_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( '.navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav > .current-menu-item > a, .sub-menu > li > a:hover { color: %s; }', $primary_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( '.secondary-bg { background-color: %s; }', $secondary_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( '.secondary-text { color: %s; }', $secondary_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( 'html, body { color: %s; }', $text_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( '.btn-primary:hover, .btn-primary:focus, .site-header .bootsnipp-search .search-form .input-group-btn > .search-submit:hover, .comment-form .form-submit input[type="submit"]:hover, .comment-form .form-submit input[type="submit"]:focus, .comment-list .comment .reply .comment-reply-link:hover, .comment-list .comment .reply .comment-reply-link:focus { background-color: %s; }', $hover_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped printf( 'a:focus, a:hover { color: %s; }', $hover_color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Binds dynamic css for colors. */ function bestblogger_color_styles() { printf( '' ); } add_action( 'wp_head', 'bestblogger_color_styles' ); /** * Partial render for copyright text. */ function bestblogger_customize_partial_footer_copyright() { $copyright_text = esc_html( get_theme_mod( 'bestblogger_footer_copyright', 'Copyright' ), array( 'a' => array( 'href' => array(), 'title' => array() ), 'br' => array(), 'em' => array(), 'strong' => array(), ) ); printf( '

%s

', $copyright_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Render function for Footer copyright. */ function bestblogger_footer_copyright() { printf( '' ); } /** * Partial render for copyright right side text. */ function bestblogger_customize_partial_footer_copyright_right() { $copyright_text = esc_html( get_theme_mod( 'bestblogger_footer_copyright_right', 'Copyright' ), array( 'a' => array( 'href' => array(), 'title' => array() ), 'br' => array(), 'em' => array(), 'strong' => array(), ) ); printf( '

%s

', $copyright_text ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Render function for Footer copyright right side text. */ function bestblogger_footer_copyright_right() { printf( '' ); }