Skip to content

Commit

Permalink
Merge pull request #1573 from roots/add-customizer-support
Browse files Browse the repository at this point in the history
Add support for theme customizer
  • Loading branch information
retlehs committed Nov 9, 2015
2 parents 0e60cbb + 1607f6e commit 32dddb0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

Expand Down
5 changes: 5 additions & 0 deletions assets/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
],
"main": true
},
"customizer.js": {
"files": [
"scripts/customizer.js"
]
},
"jquery.js": {
"bower": ["jquery"]
}
Expand Down
8 changes: 8 additions & 0 deletions assets/scripts/customizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(function($) {
// Site title
wp.customize('blogname', function(value) {
value.bind(function(to) {
$('.brand').text(to);
});
});
})(jQuery);
11 changes: 6 additions & 5 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions lib/customizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Roots\Sage\Customizer;

use Roots\Sage\Assets;

/**
* Add postMessage support
*/
function customize_register($wp_customize) {
$wp_customize->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');

0 comments on commit 32dddb0

Please sign in to comment.