Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues setting default swatches/palettes #2502

Open
oobi opened this issue Apr 6, 2023 · 0 comments
Open

Issues setting default swatches/palettes #2502

oobi opened this issue Apr 6, 2023 · 0 comments

Comments

@oobi
Copy link

oobi commented Apr 6, 2023

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']
		],
	]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant