From e873b4159f260d1d134ad4d98c13e81e142aa06d Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 12 Aug 2022 02:27:33 +0200 Subject: [PATCH 1/5] Fix coding standards --- js/customizer-controls.js | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/js/customizer-controls.js b/js/customizer-controls.js index c88b4ad1..fa189dec 100644 --- a/js/customizer-controls.js +++ b/js/customizer-controls.js @@ -5,22 +5,25 @@ * when users open or close the front page sections section. */ - (function() { - wp.customize.bind( 'ready', function() { + ( function () { + wp.customize.bind( 'ready', function () { // Only show the navbar type setting when running Bootstrap 5. - wp.customize( 'understrap_bootstrap_version', function( setting ) { - wp.customize.control( 'understrap_navbar_type', function( control ) { - var visibility = function() { - if ( 'bootstrap5' === setting.get() ) { - control.container.slideDown( 180 ); - } else { - control.container.slideUp( 180 ); - } - }; + wp.customize( 'understrap_bootstrap_version', function ( setting ) { + wp.customize.control( + 'understrap_navbar_type', + function ( control ) { + const visibility = function () { + if ( 'bootstrap5' === setting.get() ) { + control.container.slideDown( 180 ); + } else { + control.container.slideUp( 180 ); + } + }; - visibility(); - setting.bind( visibility ); - }); - }); - }); -})(); + visibility(); + setting.bind( visibility ); + } + ); + } ); + } ); +} )(); From 83372151b19268e9c9a781233316623f4683415b Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 12 Aug 2022 02:44:45 +0200 Subject: [PATCH 2/5] Fix customizer preview --- inc/customizer.php | 29 ++++++++++++++++++++++---- js/customizer.js | 51 +++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 29 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index 8bee22bf..1f1224c0 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -22,6 +22,11 @@ if ( ! function_exists( 'understrap_customize_register' ) ) { $get_setting->transport = 'postMessage'; } } + + $custom_logo = $wp_customize->get_setting( 'custom_logo' ); + if ( $custom_logo instanceof WP_Customize_Setting ) { + $custom_logo->transport = 'refresh'; + } } } add_action( 'customize_register', 'understrap_customize_register' ); @@ -191,6 +196,10 @@ if ( ! function_exists( 'understrap_theme_customize_register' ) ) { ) ); + $understrap_site_info = $wp_customize->get_setting( 'understrap_site_info_override' ); + if ( $understrap_site_info instanceof WP_Customize_Setting ) { + $understrap_site_info->transport = 'postMessage'; + } } } // End of if function_exists( 'understrap_theme_customize_register' ). add_action( 'customize_register', 'understrap_theme_customize_register' ); @@ -231,11 +240,17 @@ if ( ! function_exists( 'understrap_customize_preview_js' ) ) { * Setup JS integration for live previewing. */ function understrap_customize_preview_js() { + $file = '/js/customizer.js'; + $version = filemtime( get_template_directory() . $file ); + if ( false === $version ) { + $version = time(); + } + wp_enqueue_script( 'understrap_customizer', - get_template_directory_uri() . '/js/customizer.js', + get_template_directory_uri() . $file, array( 'customize-preview' ), - '20130508', + (string) $version, true ); } @@ -250,11 +265,17 @@ if ( ! function_exists( 'understrap_customize_controls_js' ) ) { * Setup JS integration for live previewing. */ function understrap_customize_controls_js() { + $file = '/js/customizer-controls.js'; + $version = filemtime( get_template_directory() . $file ); + if ( false === $version ) { + $version = time(); + } + wp_enqueue_script( 'understrap_customizer', - get_template_directory_uri() . '/js/customizer-controls.js', + get_template_directory_uri() . $file, array( 'customize-preview' ), - '20130508', + (string) $version, true ); } diff --git a/js/customizer.js b/js/customizer.js index 29df8cec..7595c86e 100755 --- a/js/customizer.js +++ b/js/customizer.js @@ -1,42 +1,43 @@ /** - * File customizcustomizer.js. + * File: customizer.js. * * Theme Customizer enhancements for a better user experience. * * Contains handlers to make Theme Customizer preview reload changes asynchronously. */ -( function( $ ) { + ( function () { + let anchor = document.querySelector( '.navbar-brand' ); + console.log(anchor.tagName); + if ( 'H1' === anchor.tagName ) { + anchor = anchor.firstChild; + } - // Site title and description. - wp.customize( 'blogname', function( value ) { - value.bind( function( to ) { - $( '.site-title a' ).text( to ); - } ); - } ); - wp.customize( 'blogdescription', function( value ) { - value.bind( function( to ) { - $( '.site-description' ).text( to ); + // Site title. + wp.customize( 'blogname', function ( value ) { + value.bind( function ( to ) { + anchor.textContent = to; } ); } ); // Header text color. - wp.customize( 'header_textcolor', function( value ) { - value.bind( function( to ) { + wp.customize( 'header_textcolor', function ( value ) { + value.bind( function ( to ) { if ( 'blank' === to ) { - $( '.site-title a, .site-description' ).css( { - 'clip': 'rect(1px, 1px, 1px, 1px)', - 'position': 'absolute' - } ); + anchor.style.clip = 'rect(1px, 1px, 1px, 1px)'; + anchor.style.position = 'absolute'; } else { - $( '.site-title a, .site-description' ).css( { - 'clip': 'auto', - 'position': 'relative' - } ); - $( '.site-title a, .site-description' ).css( { - 'color': to - } ); + anchor.style.clip = 'auto'; + anchor.style.position = 'relative'; + anchor.style.color = to; } } ); } ); -} )( jQuery ); + + // Site info. + wp.customize( 'understrap_site_info_override', function ( value ) { + value.bind( function ( to ) { + document.querySelector( '.site-info' ).innerHTML = to; + } ); + } ); +} )(); From 6fa9c4c17b5bb3a9a7646f34ae08830dfd8d2543 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 12 Aug 2022 02:54:09 +0200 Subject: [PATCH 3/5] Remove blogdescription from setting `transport = 'postMessage'` --- inc/customizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/customizer.php b/inc/customizer.php index 1f1224c0..a63348e3 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -15,7 +15,7 @@ if ( ! function_exists( 'understrap_customize_register' ) ) { * @param WP_Customize_Manager $wp_customize Customizer reference. */ function understrap_customize_register( $wp_customize ) { - $settings = array( 'blogname', 'blogdescription', 'header_textcolor' ); + $settings = array( 'blogname', 'header_textcolor' ); foreach ( $settings as $setting ) { $get_setting = $wp_customize->get_setting( $setting ); if ( $get_setting instanceof WP_Customize_Setting ) { From ba3a7d6d2e1ca9999904f314ac7278672544e11d Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 12 Aug 2022 03:07:42 +0200 Subject: [PATCH 4/5] Remove console log --- js/customizer.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/customizer.js b/js/customizer.js index 7595c86e..97867795 100755 --- a/js/customizer.js +++ b/js/customizer.js @@ -8,7 +8,6 @@ ( function () { let anchor = document.querySelector( '.navbar-brand' ); - console.log(anchor.tagName); if ( 'H1' === anchor.tagName ) { anchor = anchor.firstChild; } From 8c636993331e9a9c22ab53bf961c083da6207325 Mon Sep 17 00:00:00 2001 From: IanDelMar <42134098+IanDelMar@users.noreply.github.com> Date: Fri, 12 Aug 2022 22:01:48 +0200 Subject: [PATCH 5/5] Fix preview for custom logo --- inc/customizer.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/inc/customizer.php b/inc/customizer.php index a63348e3..6f295243 100644 --- a/inc/customizer.php +++ b/inc/customizer.php @@ -10,7 +10,7 @@ defined( 'ABSPATH' ) || exit; if ( ! function_exists( 'understrap_customize_register' ) ) { /** - * Register basic support (site title, description, header text color) for the Theme Customizer. + * Register basic support (site title, header text color) for the Theme Customizer. * * @param WP_Customize_Manager $wp_customize Customizer reference. */ @@ -23,14 +23,35 @@ if ( ! function_exists( 'understrap_customize_register' ) ) { } } - $custom_logo = $wp_customize->get_setting( 'custom_logo' ); - if ( $custom_logo instanceof WP_Customize_Setting ) { - $custom_logo->transport = 'refresh'; - } + // Override default partial for custom logo. + $wp_customize->selective_refresh->add_partial( + 'custom_logo', + array( + 'settings' => array( 'custom_logo' ), + 'selector' => '.custom-logo-link', + 'render_callback' => 'understrap_customize_partial_custom_logo', + 'container_inclusive' => false, + ) + ); } } add_action( 'customize_register', 'understrap_customize_register' ); +if ( ! function_exists( 'understrap_customize_partial_custom_logo' ) ) { + /** + * Callback for rendering the custom logo, used in the custom_logo partial. + * + * @return string The custom logo markup or the site title. + */ + function understrap_customize_partial_custom_logo() { + if ( has_custom_logo() ) { + return get_custom_logo(); + } else { + return get_bloginfo( 'name' ); + } + } +} + if ( ! function_exists( 'understrap_theme_customize_register' ) ) { /** * Register individual settings through customizer's API.