kirki-framework/control-color-palette

Color palette control for the Kirki Customizer Framework

This package's canonical repository appears to be gone and the package has been frozen as a result.

v1.0.3 2022-01-18 07:50 UTC

This package is auto-updated.

Last update: 2023-01-18 09:57:12 UTC


README

A control-color-palette package for Kirki Customizer Framework.

Table of Contents

Installation

First, install the package using composer:

composer require kirki-framework/control-color-palette

Then make sure you have included the autoloader:

require_once "your/path/to/vendor/autoload.php";

Usage

This control can be consumed using Kirki API or using WordPress Customizer API.

Using Kirki API

new \Kirki\Field\Color_Palette(
	[
		'settings'    => 'your_control_setting_id',
		'label'       => esc_html__( 'Your Control Label', 'your-text-domain' ),
		'description' => esc_html__( 'Your control description.', 'your-text-domain' ),
		'section'     => 'your_section_id',
		'default'     => 5,
		'choices'     => [
			'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ],
			'shape'  => 'round', // Optional, default is 'square'.
			'size'   => 20, // Optional, default is 28.
		],
	]
);

Using WordPress Customizer API

/**
 * Register customizer settings and controls.
 *
 * @param \WP_Customize_Manager $wp_customize The Customizer object.
 */
function your_customize_register_function( $wp_customize ) {

	// Add setting.
	$wp_customize->add_setting(
		'your_control_setting_id',
		[
			'type'       => 'theme_mod', // Or 'option'.
			'capability' => 'edit_theme_options',
			'default'    => 5,
			'transport'  => 'postMessage', // Or 'refresh'.
			'sanitize'   => 'intval', // Or 'absint' or other int sanitization.
		]
	);

	// Add control.
	$wp_customize->add_control(
		new \Kirki\Control\Color_Palette(
			$wp_customize,
			'your_control_setting_id',
			[
				'label'       => esc_html__( 'Your Control Label', 'your-text-domain' ),
				'description' => esc_html__( 'Your control description.', 'your-text-domain' ),
				'section'     => 'your_section_id',
				'choices'     => [
					'colors' => [ '#000000', '#222222', '#444444', '#666666', '#888888', '#aaaaaa', '#cccccc', '#eeeeee', '#ffffff' ],
					'shape'  => 'round', // Optional, default is 'square'.
					'size'   => 20, // Optional, default is 28.
				],
			]
		)
	);

	// Add more settings...

	// Add more controls...

}
add_action( 'customize_register', 'your_customize_register_function' );

License

MIT License