Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active October 5, 2017 02:57
Show Gist options
  • Save westonruter/fa261e53208a17a890960b015e5ad4bd to your computer and use it in GitHub Desktop.
Save westonruter/fa261e53208a17a890960b015e5ad4bd to your computer and use it in GitHub Desktop.
wp.customize.bind( 'ready', function() {
'use strict';
var api = this, sectionId = 'templated_controls';
api.section.add( new api.Section( sectionId, {
title: 'Templated Controls',
customizeAction: 'Testing things out...',
priority: 0
} ) );
api.control.add( new api.Control( 'templated_button', {
label: 'HELLO!',
type: 'button',
setting: 'blogname',
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_text', {
label: 'Text',
type: 'text',
setting: 'blogname',
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_textarea', {
label: 'Textarea',
type: 'textarea',
setting: 'blogname',
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_checkbox', {
label: 'Checkbox',
type: 'checkbox',
setting: new api.Value( true ),
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_select', {
label: 'Select',
type: 'select',
setting: new api.Value( 'blue' ),
choices: {
'red': 'RED!',
'blue': 'BLUE!',
'green': 'GREEN!'
},
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_select2', {
label: 'Select2',
type: 'select',
setting: new api.Value( 'green' ),
choices: [
{ 'value': 'red', 'text': 'RED!???' },
{ 'value': 'blue', 'text': 'BLUE!??' },
{ 'value': 'green', 'text': 'GREEN!!!!' }
],
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_radio', {
label: 'Radio',
type: 'radio',
setting: new api.Value( 'blue' ),
choices: {
'red': 'RED!',
'blue': 'BLUE!',
'green': 'GREEN!'
},
section: sectionId
} ) );
api.control.add( new api.Control( 'templated_radio2', {
label: 'Radio2',
type: 'radio',
setting: new api.Value( 'green' ),
choices: [
{ 'value': 'red', 'text': 'RED!???' },
{ 'value': 'blue', 'text': 'BLUE!??' },
{ 'value': 'green', 'text': 'GREEN!!!!' }
],
section: sectionId
} ) );
} );
<?php
/**
* Plugin Name: Trac #30738: Templates for base Customizer controls.
* Author: Weston Ruter, XWP
*/
add_action( 'customize_controls_enqueue_scripts', function() {
wp_enqueue_script( 'trac-30738', plugin_dir_url( __FILE__ ) . '/trac-30738.js', array( 'customize-controls' ) );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment