Customizer? I barely know ‘er!

Customizer is WordPress’s Theme Customization API and is becoming part of core soon. Very helpful to allow the global theme style to be more customizable.

WordCamp Fayetteville 2015
Customizer? I barely know ‘er!
Sky Shabatura
  • create theme settings and controls (menus) with a consistent control panel interface
  • live preview of theme changes
  • allows developers to build things for Decisions not Options

Adding settings to theme

Class: WP_Customize_Manager

  • Attributes: priority, capability, theme_supports, etc.
  • add_panel('panel_name', array('attribute' => 'value'))
  • add_setting('panel_name', array('attribute' => 'value'))

Setting/Control groups into Sections grouped into Panels.

Setting: What gets stored in the database (the model side). Can be a type ‘option’ or ‘theme_mod’.
Control: How the user sets a setting and where the interaction is displayed (the view/control side). Shares a name with the related setting.

Can create a custom control by extended the WP_Customize_Control class, then using add_control and passing in a new instance of your custom class (while passing in the $wp_customize global object).

Using settings

Get the value of the current setting with get_theme_mod('setting_name', 'default_value'); for use in theme files.

You can also use the values inside the live preview window via Javascript for better UX on live preview using the transport=>'postMessage' attribute. Start by enqueuing the javascript with customize_preview_init hook and wp_enqueue script. Uses a Javascript object wp.customize and bind the value to the particular DOM value.