WordPress/wp-content/themes/twentyseventeen/inc/customizer.php
Weston Ruter 8d1cb3068a Customize: Add hue-only mode to color picker.
The color control in the customizer can use the new mode by supplying the `mode` param with `hue` (as opposed to the new default `full` value). New control replaces the `range` control in Twenty Seventeen for `colorscheme_hue`. The `wpColorPicker` can opt for hue-only mode via supplying `hue` as the `type` option. Iris Color Picker is updated from v1.0.7 to v1.1.0-beta.

Props mattwiebe, celloexpressions.
Fixes #38263.

Built from https://develop.svn.wordpress.org/trunk@38931


git-svn-id: http://core.svn.wordpress.org/trunk@38874 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-25 22:33:30 +00:00

207 lines
6.8 KiB
PHP

<?php
/**
* Twenty Seventeen: Theme Customizer
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/
/**
* Add postMessage support for site title and description for the Theme Customizer.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
*/
function twentyseventeen_customize_register( $wp_customize ) {
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
/**
* Custom colors.
*/
$wp_customize->add_setting( 'colorscheme', array(
'default' => 'light',
'transport' => 'postMessage',
'sanitize_callback' => 'twentyseventeen_sanitize_colorscheme',
) );
$wp_customize->add_setting( 'colorscheme_hue', array(
'default' => 250,
'transport' => 'postMessage',
'sanitize_callback' => 'absint', // The hue is stored as a positive integer.
) );
$wp_customize->add_control( 'colorscheme', array(
'type' => 'radio',
'label' => __( 'Color Scheme', 'twentyseventeen' ),
'choices' => array(
'light' => __( 'Light', 'twentyseventeen' ),
'dark' => __( 'Dark', 'twentyseventeen' ),
'custom' => __( 'Custom', 'twentyseventeen' ),
),
'section' => 'colors',
'priority' => 5,
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'colorscheme_hue', array(
'mode' => 'hue',
'section' => 'colors',
'priority' => 6,
) ) );
/**
* Add the Theme Options section.
*/
$wp_customize->add_panel( 'options_panel', array(
'title' => __( 'Theme Options', 'twentyseventeen' ),
'description' => __( 'Configure your theme settings', 'twentyseventeen' ),
) );
// Page Options.
$wp_customize->add_section( 'page_options', array(
'title' => __( 'Single Page Layout', 'twentyseventeen' ),
'active_callback' => 'twentyseventeen_is_page',
'panel' => 'options_panel',
) );
$wp_customize->add_setting( 'page_options', array(
'default' => 'two-column',
'sanitize_callback' => 'twentyseventeen_sanitize_layout',
'transport' => 'postMessage',
) );
$wp_customize->add_control( 'page_options', array(
'label' => __( 'Page Layout', 'twentyseventeen' ),
'section' => 'page_options',
'type' => 'radio',
'description' => __( 'When no sidebar widgets are assigned, you can opt to display all pages with a one column or two column layout. When the two column layout is assigned, the page title is in one column and content is in the other.', 'twentyseventeen' ),
'choices' => array(
'one-column' => __( 'One Column', 'twentyseventeen' ),
'two-column' => __( 'Two Column', 'twentyseventeen' ),
),
) );
// Panel 1.
$wp_customize->add_section( 'panel_1', array(
'title' => __( 'Panel 1', 'twentyseventeen' ),
'active_callback' => 'is_front_page',
'panel' => 'options_panel',
'description' => __( 'Add an image to your panel by setting a featured image in the page editor. If you don&rsquo;t select a page, this panel will not be displayed.', 'twentyseventeen' ),
) );
$wp_customize->add_setting( 'panel_1', array(
'default' => false,
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control( 'panel_1', array(
'label' => __( 'Panel Content', 'twentyseventeen' ),
'section' => 'panel_1',
'type' => 'dropdown-pages',
) );
// Panel 2.
$wp_customize->add_section( 'panel_2', array(
'title' => __( 'Panel 2', 'twentyseventeen' ),
'active_callback' => 'is_front_page',
'panel' => 'options_panel',
'description' => __( 'Add an image to your panel by setting a featured image in the page editor. If you don&rsquo;t select a page, this panel will not be displayed.', 'twentyseventeen' ),
) );
$wp_customize->add_setting( 'panel_2', array(
'default' => false,
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control( 'panel_2', array(
'label' => __( 'Panel Content', 'twentyseventeen' ),
'section' => 'panel_2',
'type' => 'dropdown-pages',
) );
// Panel 3.
$wp_customize->add_section( 'panel_3', array(
'title' => __( 'Panel 3', 'twentyseventeen' ),
'active_callback' => 'is_front_page',
'panel' => 'options_panel',
'description' => __( 'Add an image to your panel by setting a featured image in the page editor. If you don&rsquo;t select a page, this panel will not be displayed.', 'twentyseventeen' ),
) );
$wp_customize->add_setting( 'panel_3', array(
'default' => false,
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control( 'panel_3', array(
'label' => __( 'Panel Content', 'twentyseventeen' ),
'section' => 'panel_3',
'type' => 'dropdown-pages',
) );
// Panel 4.
$wp_customize->add_section( 'panel_4', array(
'title' => __( 'Panel 4', 'twentyseventeen' ),
'active_callback' => 'is_front_page',
'panel' => 'options_panel',
'description' => __( 'Add an image to your panel by setting a featured image in the page editor. If you don&rsquo;t select a page, this panel will not be displayed.', 'twentyseventeen' ),
) );
$wp_customize->add_setting( 'panel_4', array(
'default' => false,
'sanitize_callback' => 'absint',
) );
$wp_customize->add_control( 'panel_4', array(
'label' => __( 'Panel Content', 'twentyseventeen' ),
'section' => 'panel_4',
'type' => 'dropdown-pages',
) );
}
add_action( 'customize_register', 'twentyseventeen_customize_register' );
/**
* Sanitize a radio button.
*/
function twentyseventeen_sanitize_layout( $input ) {
$valid = array(
'one-column' => __( 'One Column', 'twentyseventeen' ),
'two-column' => __( 'Two Column', 'twentyseventeen' ),
);
if ( array_key_exists( $input, $valid ) ) {
return $input;
}
return '';
}
/**
* Sanitize the colorscheme.
*/
function twentyseventeen_sanitize_colorscheme( $input ) {
$valid = array( 'light', 'dark', 'custom' );
if ( in_array( $input, $valid ) ) {
return $input;
}
return 'light';
}
/**
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
*/
function twentyseventeen_customize_preview_js() {
wp_enqueue_script( 'twentyseventeen-customizer', get_theme_file_uri( '/assets/js/customizer.js' ), array( 'customize-preview' ), '1.0', true );
}
add_action( 'customize_preview_init', 'twentyseventeen_customize_preview_js' );
/**
* Some extra JavaScript to improve the user experience in the Customizer for this theme.
*/
function twentyseventeen_panels_js() {
wp_enqueue_script( 'twentyseventeen-panel-customizer', get_theme_file_uri( '/assets/js/panel-customizer.js' ), array(), '1.0', true );
}
add_action( 'customize_controls_enqueue_scripts', 'twentyseventeen_panels_js' );