The document discusses using the WordPress theme customizer API to create visual theme options. It covers adding sections, settings and controls to build a theme customizer interface. Custom controls can be created as custom PHP classes. Settings can be saved as options or theme modifications and refreshed on the page or via asynchronous postMessage updates. Resources for learning more about the theme customizer are provided.
13. drewf.us/wcyvr13
To Refresh or Not to Refresh
Settings Transports
– refresh (default)
– postMessage
Saturday, August 17, 13
14. drewf.us/wcyvr13
To Refresh or Not to Refresh
postMessage Transport
– Specified with the ‘transport’ argument in add_setting()
$wp_customize->add_setting( 'nubrick_site_width', array(
'default' => 860,
'transport' => ‘postMessage’
) );
$wp_customize->get_setting( 'blogname' )->transport =
'postMessage';
– Change built-in controls’ transports
Saturday, August 17, 13
15. drewf.us/wcyvr13
To Refresh or Not to Refresh
postMessage Transport
– Asynchronous updates using JavaScript
( function( $ ) {
// Site title and description.
wp.customize( 'blogname', function( value ) {
value.bind( function( to ) {
$( '.site-title a' ).text( to );
} );
} );
} )( jQuery );
– Enqueue scripts on the ‘customize_preview_init’ hook
Saturday, August 17, 13
18. drewf.us/wcyvr13
Custom Controls
function my_theme_customizer( $wp_customize ) {
class My_Customize_Control extends WP_Customize_Control {
// do magic
}
$wp_customize->add_control( new My_Customize_Control( $wp_customize,
'my_setting', array(
'label' => __( 'My Setting', 'textdomain' ),
'section' => 'my_section',
'settings' => 'my_setting'
) ) );
}
add_action( 'customize_register', 'my_theme_customizer' );
Saturday, August 17, 13
19. drewf.us/wcyvr13
Resources
Ottopress.com (Otto42)
– Customizer API series published last year
WordPress Theme Customizer Controls (paulund)
– https://github.com/paulund/Wordpress-Theme-Customizer-Custom-Controls
WordPress Theme Customizer Boilerplate (slobodan)
– https://github.com/slobodan/WordPress-Theme-Customizer-Boilerplate
Saturday, August 17, 13