From 1607f6e3710b7a2aea6fe1d6e285f5d96680b498 Mon Sep 17 00:00:00 2001 From: Ben Word Date: Thu, 5 Nov 2015 20:06:24 -0600 Subject: [PATCH] Add support for theme customizer --- CHANGELOG.md | 1 + assets/manifest.json | 5 +++++ assets/scripts/customizer.js | 8 ++++++++ functions.php | 11 ++++++----- lib/customizer.php | 21 +++++++++++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 assets/scripts/customizer.js create mode 100644 lib/customizer.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ca629c90ba..407fb69e37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### HEAD * Drop support for older browsers ([#1571](https://github.com/roots/sage/pull/1571)) +* Add support for theme customizer ([#1573](https://github.com/roots/sage/pull/1573)) * Remove extraneous no-js ([#1562](https://github.com/roots/sage/pull/1562)) * Simplify/speed up editor style process ([#1560](https://github.com/roots/sage/pull/1560)) diff --git a/assets/manifest.json b/assets/manifest.json index abf01a339b..aca495c846 100644 --- a/assets/manifest.json +++ b/assets/manifest.json @@ -12,6 +12,11 @@ ], "main": true }, + "customizer.js": { + "files": [ + "scripts/customizer.js" + ] + }, "jquery.js": { "bower": ["jquery"] } diff --git a/assets/scripts/customizer.js b/assets/scripts/customizer.js new file mode 100644 index 0000000000..76e3b56eb8 --- /dev/null +++ b/assets/scripts/customizer.js @@ -0,0 +1,8 @@ +(function($) { + // Site title + wp.customize('blogname', function(value) { + value.bind(function(to) { + $('.brand').text(to); + }); + }); +})(jQuery); diff --git a/functions.php b/functions.php index e44777b024..35df8db212 100644 --- a/functions.php +++ b/functions.php @@ -10,11 +10,12 @@ * @link https://github.com/roots/sage/pull/1042 */ $sage_includes = [ - 'lib/assets.php', // Scripts and stylesheets - 'lib/extras.php', // Custom functions - 'lib/setup.php', // Theme setup - 'lib/titles.php', // Page titles - 'lib/wrapper.php' // Theme wrapper class + 'lib/assets.php', // Scripts and stylesheets + 'lib/extras.php', // Custom functions + 'lib/setup.php', // Theme setup + 'lib/titles.php', // Page titles + 'lib/wrapper.php', // Theme wrapper class + 'lib/customizer.php' // Theme customizer ]; foreach ($sage_includes as $file) { diff --git a/lib/customizer.php b/lib/customizer.php new file mode 100644 index 0000000000..d0253f9409 --- /dev/null +++ b/lib/customizer.php @@ -0,0 +1,21 @@ +get_setting('blogname')->transport = 'postMessage'; +} +add_action('customize_register', __NAMESPACE__ . '\\customize_register'); + +/** + * Customizer JS + */ +function customize_preview_js() { + wp_enqueue_script('sage/customizer', Assets\asset_path('scripts/customizer.js'), ['customize-preview'], null, true); +} +add_action('customize_preview_init', __NAMESPACE__ . '\\customize_preview_js');