Skip to content

Commit 1607f6e

Browse files
committed
Add support for theme customizer
1 parent 0e60cbb commit 1607f6e

File tree

5 files changed

+41
-5
lines changed

5 files changed

+41
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### HEAD
22
* Drop support for older browsers ([#1571](https://github.com/roots/sage/pull/1571))
3+
* Add support for theme customizer ([#1573](https://github.com/roots/sage/pull/1573))
34
* Remove extraneous no-js ([#1562](https://github.com/roots/sage/pull/1562))
45
* Simplify/speed up editor style process ([#1560](https://github.com/roots/sage/pull/1560))
56

assets/manifest.json

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
],
1313
"main": true
1414
},
15+
"customizer.js": {
16+
"files": [
17+
"scripts/customizer.js"
18+
]
19+
},
1520
"jquery.js": {
1621
"bower": ["jquery"]
1722
}

assets/scripts/customizer.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(function($) {
2+
// Site title
3+
wp.customize('blogname', function(value) {
4+
value.bind(function(to) {
5+
$('.brand').text(to);
6+
});
7+
});
8+
})(jQuery);

functions.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
* @link https://github.com/roots/sage/pull/1042
1111
*/
1212
$sage_includes = [
13-
'lib/assets.php', // Scripts and stylesheets
14-
'lib/extras.php', // Custom functions
15-
'lib/setup.php', // Theme setup
16-
'lib/titles.php', // Page titles
17-
'lib/wrapper.php' // Theme wrapper class
13+
'lib/assets.php', // Scripts and stylesheets
14+
'lib/extras.php', // Custom functions
15+
'lib/setup.php', // Theme setup
16+
'lib/titles.php', // Page titles
17+
'lib/wrapper.php', // Theme wrapper class
18+
'lib/customizer.php' // Theme customizer
1819
];
1920

2021
foreach ($sage_includes as $file) {

lib/customizer.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Roots\Sage\Customizer;
4+
5+
use Roots\Sage\Assets;
6+
7+
/**
8+
* Add postMessage support
9+
*/
10+
function customize_register($wp_customize) {
11+
$wp_customize->get_setting('blogname')->transport = 'postMessage';
12+
}
13+
add_action('customize_register', __NAMESPACE__ . '\\customize_register');
14+
15+
/**
16+
* Customizer JS
17+
*/
18+
function customize_preview_js() {
19+
wp_enqueue_script('sage/customizer', Assets\asset_path('scripts/customizer.js'), ['customize-preview'], null, true);
20+
}
21+
add_action('customize_preview_init', __NAMESPACE__ . '\\customize_preview_js');

0 commit comments

Comments
 (0)