themeum / kirki

Extending the customizer

Home Page:https://kirki.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible logic mistake on Kirki_Field class

danielortiz opened this issue · comments

Issue description:

I was reading through Kirki's code to try to find out another problem (#1425) I'm having, and I found this piece of code:

		if ( is_array( $config_id ) && empty( $args ) ) {
			$args = $config_id;
			$this->kirki_config = 'global';
		} 
		$this->kirki_config = trim( esc_attr( $config_id ) );

(class-kirki-field.php, line 320)
It seems to me that this logic may cause errors if one do what it's actually trying to prevent.
The if statement is verifying if only$args are being passed (no config_id), and set the $this->kirki_config = 'global', but then, when it leaves the if statement, it reasign $this->kirki_config to the output of trim( esc_attr( $config_id ) ), which in the case the user didn't pass it, will be an array and will output an error.
Possible fix would be to put an elsestatement there

		if ( is_array( $config_id ) && empty( $args ) ) {
			$args = $config_id;
			$this->kirki_config = 'global';
		} else {
		    $this->kirki_config = trim( esc_attr( $config_id ) );
		}

I didn't test it, but that'd probably do the trick.

I'd put a PR for it, but I didn't see anybody doing PRs here beside the plugin authors and I'm not sure the proper way to do that. So let me know the guidelines for it, if it's possible

Version used:

(Did you try using the develop branch from github? There's a chance your issue has already been adressed there)
3.0.5
edit: same thing on 3.0.6

Good catch! Fixed, will be included in 3.0.7 which will be released later today.
Thanks!