kirki icon indicating copy to clipboard operation
kirki copied to clipboard

Issues setting default swatches/palettes

Open oobi opened this issue 2 years ago • 0 comments

Issue description:

Bug setting default swatches in colour controls (WP_DEBUG active). When setting 'palettes' or 'swatches', it seems to attempt to backfill the remainder if you include fewer than eight values in the "palettes" array.

In the ReactColorul class at line 177:

if ( ! empty( $defined_swatches ) ) {
	$swatches       = $defined_swatches;
	$total_swatches = count( $swatches );

	if ( $total_swatches < 8 ) {
		for ( $i = $total_swatches; $i <= 8; $i++ ) {
			$swatches[] = $total_swatches[ $i ];  // ===> $total_swatches is an integer
		}
	}
} else {
	$swatches = $default_swatches;
}

I'm not sure of the intended utility here, but the "if" block seems redundant. The 'else' is really what you're after, I think.

Version used:

4.1.1

Using theme_mods or options?

theme_mods

PHP error messages that might be related

Trying to access array offset on value of type int in <b>/wp-content/plugins/kirki/kirki-packages/control-react-colorful/src/Control/ReactColorful.php</b> on line <b>183</b>

Code to reproduce the issue (config + field(s))

new \Kirki\Field\Color(
	[
		'settings'     => "test",
		'label'       => __( 'Color Control (rgba)', 'kirki' ),
		'description' => esc_html__( 'Advanced color control with alpha channel.', 'kirki' ),
		'section'     	=> 'section_id',
		'default'     => '#0008DC',
		'choices'     => [
			'alpha' => true,
			'palettes' => ['#ff0000', '#00ff00', '#0000ff']
		],
	]
);

oobi avatar Apr 06 '23 08:04 oobi