'theme_mod',
'capability' => 'manage_options',
]
);
/**
* Add a panel.
*
* @link https://kirki.org/docs/getting-started/panels.html
*/
new \Kirki\Panel(
'kirki_demo_panel',
[
'priority' => 10,
'title' => esc_html__( 'Kirki Demo Panel', 'kirki' ),
'description' => esc_html__( 'Contains sections for all kirki controls.', 'kirki' ),
]
);
/**
* Add Sections.
*
* We'll be doing things a bit differently here, just to demonstrate an example.
* We're going to define 1 section per control-type just to keep things clean and separate.
*
* @link https://kirki.org/docs/getting-started/sections.html
*/
$sections = [
'background' => [ esc_html__( 'Background', 'kirki' ), '' ],
'code' => [ esc_html__( 'Code', 'kirki' ), '' ],
'checkbox' => [ esc_html__( 'Checkbox', 'kirki' ), '' ],
'color' => [ esc_html__( 'Color', 'kirki' ), '' ],
'color_advanced' => [ esc_html__( 'Color — Advanced', 'kirki' ), '' ],
'color_palette' => [ esc_html__( 'Color Palette', 'kirki' ), '' ],
'custom' => [ esc_html__( 'Custom', 'kirki' ), '' ],
'dashicons' => [ esc_html__( 'Dashicons', 'kirki' ), '' ],
'date' => [ esc_html__( 'Date', 'kirki' ), '' ],
'dimension' => [ esc_html__( 'Dimension', 'kirki' ), '' ],
'dimensions' => [ esc_html__( 'Dimensions', 'kirki' ), '' ],
'dropdown-pages' => [ esc_html__( 'Dropdown Pages', 'kirki' ), '' ],
'editor' => [ esc_html__( 'Editor', 'kirki' ), '' ],
'fontawesome' => [ esc_html__( 'Font-Awesome', 'kirki' ), '' ],
'generic' => [ esc_html__( 'Generic', 'kirki' ), '' ],
'image' => [ esc_html__( 'Image', 'kirki' ), '' ],
'multicheck' => [ esc_html__( 'Multicheck', 'kirki' ), '' ],
'multicolor' => [ esc_html__( 'Multicolor', 'kirki' ), '' ],
'number' => [ esc_html__( 'Number', 'kirki' ), '' ],
'palette' => [ esc_html__( 'Palette', 'kirki' ), '' ],
'preset' => [ esc_html__( 'Preset', 'kirki' ), '' ],
'radio' => [ esc_html__( 'Radio', 'kirki' ), esc_html__( 'A plain Radio control.', 'kirki' ) ],
'radio-buttonset' => [ esc_html__( 'Radio Buttonset', 'kirki' ), esc_html__( 'Radio-Buttonset controls are essentially radio controls with some fancy styling to make them look cooler.', 'kirki' ) ],
'radio-image' => [ esc_html__( 'Radio Image', 'kirki' ), esc_html__( 'Radio-Image controls are essentially radio controls with some fancy styles to use images', 'kirki' ) ],
'repeater' => [ esc_html__( 'Repeater', 'kirki' ), '' ],
'select' => [ esc_html__( 'Select', 'kirki' ), '' ],
'slider' => [ esc_html__( 'Slider', 'kirki' ), '' ],
'sortable' => [ esc_html__( 'Sortable', 'kirki' ), '' ],
'switch' => [ esc_html__( 'Switch', 'kirki' ), '', 'outer' ],
'toggle' => [ esc_html__( 'Toggle', 'kirki' ), '', 'outer' ],
'typography' => [ esc_html__( 'Typography', 'kirki' ), '' ],
'upload' => [ esc_html__( 'Upload', 'kirki' ), '' ],
];
foreach ( $sections as $section_id => $section ) {
$section_args = [
'title' => $section[0],
'description' => $section[1],
'panel' => 'kirki_demo_panel',
];
if ( isset( $section[2] ) ) {
$section_args['type'] = $section[2];
}
new \Kirki\Section( str_replace( '-', '_', $section_id ) . '_section', $section_args );
}
new \Kirki\Section(
'pro_test',
[
'title' => esc_html__( 'Test Link Section', 'kirki' ),
'type' => 'link',
'button_text' => esc_html__( 'Pro', 'kirki' ),
'button_url' => 'https://kirki.org',
]
);
/**
* Background Control.
*
* @todo Triggers change on load.
*/
new \Kirki\Field\Background(
[
'settings' => 'kirki_demo_background',
'label' => esc_html__( 'Background Control', 'kirki' ),
'description' => esc_html__( 'Background conrols are pretty complex! (but useful if properly used)', 'kirki' ),
'section' => 'background_section',
'default' => [
'background-color' => 'rgba(20,20,20,.8)',
'background-image' => '',
'background-repeat' => 'repeat',
'background-position' => 'center center',
'background-size' => 'cover',
'background-attachment' => 'scroll',
],
]
);
/**
* Code control.
*
* @link https://kirki.org/docs/controls/code.html
*/
new \Kirki\Field\Code(
[
'settings' => 'kirki_demo_code_css',
'label' => esc_html__( 'Code Control — CSS', 'kirki' ),
'description' => esc_html__( 'Sample of code control in CSS format', 'kirki' ),
'section' => 'code_section',
'default' => '',
'choices' => [
'language' => 'css',
],
]
);
/**
* Checkbox control.
*
* @link https://kirki.org/docs/controls/checkbox.html
*/
new \Kirki\Field\Checkbox(
[
'settings' => 'kirki_demo_checkbox',
'label' => esc_html__( 'Checkbox Control', 'kirki' ),
'description' => esc_html__( 'Sample of checkbox control', 'kirki' ),
'section' => 'checkbox_section',
'default' => true,
]
);
/**
* Color Controls.
*
* @link https://kirki.org/docs/controls/color.html
*/
Kirki::add_field(
'kirki_demo_config',
[
'type' => 'color',
'settings' => 'kirki_demo_color_alpha_old',
'label' => 'Using Kirki::add_field
— With alpha',
'description' => esc_html__( 'This is a color control registered using `Kirki::add_field` with "alpha" => true (the old Kirki API).', 'kirki' ),
'section' => 'color_section',
'transport' => 'postMessage',
'default' => '#ff0055',
'choices' => [
'alpha' => true,
],
]
);
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_hex',
'label' => __( 'Hex only', 'kirki' ),
'description' => esc_html__( 'This is a color control without alpha channel.', 'kirki' ),
'section' => 'color_section',
'transport' => 'postMessage',
'default' => '#0008DC',
]
);
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_alpha',
'label' => __( 'With alpha channel', 'kirki' ),
'description' => esc_html__( 'This is a color control with alpha channel.', 'kirki' ),
'section' => 'color_section',
'transport' => 'postMessage',
'choices' => [
'alpha' => true,
],
]
);
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_hue',
'label' => __( 'Hue only.', 'kirki' ),
'description' => esc_html__( 'This is a color control with "mode" => "hue" (hue mode).', 'kirki' ),
'section' => 'color_section',
'transport' => 'postMessage',
'default' => 160,
'mode' => 'hue',
]
);
/**
* Color Control (Advanced)
*/
/**
* Color control with form_component value is HexColorPicker.
*
* The saved value will always be a string, for instance:
* "#ff0000"
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_hex',
'label' => __( 'v4 — form_component — HexColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is HexColorPicker.', 'kirki' ),
'section' => 'color_advanced_section',
'default' => '#ffff00',
'choices' => [
'form_component' => 'HexColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is RgbColorPicker.
*
* The saved value will be an rgba array.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* [
* 'r' => 255,
* 'g' => 255,
* 'b' => 45,
* 'a' => 0.5
* ]
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_rgb',
'label' => __( 'v4 — form_component — RgbColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is RgbColorPicker. The saved value will be an array.', 'kirki' ),
'section' => 'color_advanced_section',
'default' => '#ffff00',
'choices' => [
'form_component' => 'RgbColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is RgbStringColorPicker.
*
* The saved value will be an rgb string.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* "rgba(255, 255, 45)"
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_rgb_string',
'label' => __( 'v4 — form_component — RgbStringColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is RgbStringColorPicker. The saved value will be a string.', 'kirki' ),
'section' => 'color_advanced_section',
'default' => '#ffff00',
'choices' => [
'form_component' => 'RgbStringColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is RgbaColorPicker.
*
* The saved value will be an rgba array.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* [
* 'r' => 255,
* 'g' => 255,
* 'b' => 45,
* 'a' => 0.5
* ]
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_rgba',
'label' => __( 'v4 — form_component — RgbaColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is RgbaColorPicker. The saved value will be an array.', 'kirki' ),
'section' => 'color_advanced_section',
'default' => '#ffff00',
'choices' => [
'form_component' => 'RgbaColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is RgbaStringColorPicker.
*
* The saved value will be an rgba string.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* "rgba(255, 255, 45, 0.5)"
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_rgba_string',
'label' => __( 'v4 — form_component — RgbaStringColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is RgbaStringColorPicker. The saved value will be a string.', 'kirki' ),
'section' => 'color_advanced_section',
'default' => '#ffff00',
'choices' => [
'form_component' => 'RgbaStringColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is HslColorPicker.
*
* The saved value will be an hsl array.
* The format is following the `react-colorful` and `colord` formatting (int, without the percent sign), for instance:
* [
* 'h' => 180,
* 's' => 40, // Is int, without the percent sign.
* 'l' => 50, // Is int, without the percent sign.
* ]
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_hsl',
'label' => __( 'v4 — form_component — HslColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is HslColorPicker. The saved value will be an array', 'kirki' ),
'section' => 'color_advanced_section',
'default' => 'hsl(206, 23%, 25%)',
'choices' => [
'form_component' => 'HslColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is HslStringColorPicker.
*
* The saved value will be an hsl string.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* "hsl(180, 40%, 50%)"
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_hsl_string',
'label' => __( 'v4 — form_component — HslStringColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is HslStringColorPicker. The saved value will be a string', 'kirki' ),
'section' => 'color_advanced_section',
'default' => 'hsl(206, 23%, 25%)',
'choices' => [
'form_component' => 'HslStringColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is HslaColorPicker.
*
* The saved value will be an hsla array.
* The format is following the `react-colorful` and `colord` formatting (int, without the percent sign), for instance:
* [
* 'h' => 180,
* 's' => 40, // Is int, without the percent sign.
* 'l' => 50, // Is int, without the percent sign.
* 'a' => 0.5
* ]
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_hsla',
'label' => __( 'v4 — form_component — HslaColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is HslaColorPicker. The saved value will be an array', 'kirki' ),
'section' => 'color_advanced_section',
'default' => 'hsla(206, 23%, 25%, 0.7)',
'choices' => [
'form_component' => 'HslaColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* Color control with form_component value is HslaStringColorPicker.
*
* The saved value will be an hsla string.
* The format is following the `react-colorful` and `colord` formatting, for instance:
* "hsla(180, 40%, 50%, 0.5)"
*/
new \Kirki\Field\Color(
[
'settings' => 'kirki_demo_color_form_component_hsla_string',
'label' => __( 'v4 — form_component — HslaStringColorPicker', 'kirki' ),
'description' => esc_html__( 'This is a color control with form_component value is HslaStringColorPicker. The saved value will be a string', 'kirki' ),
'section' => 'color_advanced_section',
'default' => 'hsla(206, 23%, 25%, 0.7)',
'choices' => [
'form_component' => 'HslaStringColorPicker',
],
'transport' => 'postMessage',
]
);
/**
* DateTime Control.
*/
new \Kirki\Field\Date(
[
'settings' => 'kirki_demo_date',
'label' => esc_html__( 'Date Control', 'kirki' ),
'description' => esc_html__( 'This is a date control.', 'kirki' ),
'section' => 'date_section',
'default' => '',
]
);
new \Kirki\Field\Date(
[
'settings' => 'kirki_demo_date_2',
'label' => esc_html__( 'Date Control 2', 'kirki' ),
'description' => esc_html__( 'This is a date control.', 'kirki' ),
'section' => 'date_section',
'default' => '',
]
);
/**
* Editor Controls
*/
new \Kirki\Field\Editor(
[
'settings' => 'kirki_demo_editor_1',
'label' => esc_html__( 'First Editor Control', 'kirki' ),
'description' => esc_html__( 'This is an editor control.', 'kirki' ),
'section' => 'editor_section',
'default' => '',
]
);
new \Kirki\Field\Editor(
[
'settings' => 'kirki_demo_editor_2',
'label' => esc_html__( 'Second Editor Control', 'kirki' ),
'description' => esc_html__( 'This is a 2nd editor control just to check that we do not have issues with multiple instances.', 'kirki' ),
'section' => 'editor_section',
'default' => esc_html__( 'Default Text', 'kirki' ),
]
);
/**
* Color-Palette Controls.
*
* @link https://kirki.org/docs/controls/color-palette.html
*/
new \Kirki\Field\Color_Palette(
[
'settings' => 'kirki_demo_color_palette_simple',
'label' => esc_html__( 'Simple Colors Set', 'kirki' ),
'description' => esc_html__( 'With default size (28). The `size` here is inner size (without border)', 'kirki' ),
'section' => 'color_palette_section',
'default' => '#888888',
'transport' => 'postMessage',
'choices' => [
'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ],
'style' => 'round',
],
]
);
new \Kirki\Field\Color_Palette(
[
'settings' => 'kirki_demo_color_palette_material_all',
'label' => esc_html__( 'Material Design Colors — All', 'kirki' ),
'description' => esc_html__( 'Showing all material design colors using `round` shape and size is 17', 'kirki' ),
'section' => 'color_palette_section',
'default' => '#D1C4E9',
'transport' => 'postMessage',
'choices' => [
'colors' => Helper::get_material_design_colors( 'all' ),
'shape' => 'round',
'size' => 17,
],
]
);
new \Kirki\Field\Color_Palette(
[
'settings' => 'kirki_demo_color_palette_material_primary',
'label' => esc_html__( 'Material Design Colors — Primary', 'kirki' ),
'description' => esc_html__( 'Showing primary material design colors', 'kirki' ),
'section' => 'color_palette_section',
'choices' => [
'colors' => Helper::get_material_design_colors( 'primary' ),
'size' => 25,
],
]
);
new \Kirki\Field\Color_Palette(
[
'settings' => 'kirki_demo_color_palette_material_red',
'label' => esc_html__( 'Material Design Colors — Red', 'kirki' ),
'description' => esc_html__( 'Showing red material design colors', 'kirki' ),
'section' => 'color_palette_section',
'choices' => [
'colors' => Helper::get_material_design_colors( 'red' ),
'size' => 16,
],
]
);
new \Kirki\Field\Color_Palette(
[
'settings' => 'kirki_demo_color_palette_a100',
'label' => esc_html__( 'Material Design Colors — A100', 'kirki' ),
'description' => esc_html__( 'Showing "A100" variant of material design colors', 'kirki' ),
'section' => 'color_palette_section',
'default' => '#FF80AB',
'choices' => [
'colors' => Helper::get_material_design_colors( 'A100' ),
'size' => 60,
'style' => 'round',
],
]
);
Kirki::add_field(
'kirki_demo_config',
[
'type' => 'color-palette',
'settings' => 'kirki_demo_color_palette_old',
'label' => 'The Old Way',
'description' => 'Using `Kirki::add_field` in round shape',
'section' => 'color_palette_section',
'transport' => 'postMessage',
'choices' => [
'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ],
'style' => 'round',
],
]
);
add_action(
'customize_register',
function( $wp_customize ) {
/**
* The custom control class
*/
class Kirki_Demo_Custom_Control extends Kirki\Control\Base {
public $type = 'kirki-demo-custom-control';
public function render_content() {
$saved_value = $this->value();
?>
label ); ?>
description ); ?>