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

Conditions class does not match its JS counterpart #9043

danyj opened this issue Sep 10, 2019 · 1 comment


Copy link

commented Sep 10, 2019

JS Conditions function has contains

case 'contains':
return -1 !== leftValue.indexOf( rightValue );
case '!contains':
return -1 === leftValue.indexOf( rightValue );

which works right in the editor to check if the string is in the control that has array as value

				'conditions' => array(
					'terms' => array(
							'name' => 'meta_elements',
							'operator' => 'contains',
							'value' => 'author',

this option does not exists in the php version of the Conditions class

public static function compare( $left_value, $right_value, $operator ) {
switch ( $operator ) {
case '==':
return $left_value == $right_value;
case '!=':
return $left_value != $right_value;
case '!==':
return $left_value !== $right_value;
case 'in':
return false !== array_search( $left_value, $right_value );
case '!in':
return false === array_search( $left_value, $right_value );
case '<':
return $left_value < $right_value;
case '<=':
return $left_value <= $right_value;
case '>':
return $left_value > $right_value;
case '>=':
return $left_value >= $right_value;
return $left_value === $right_value;

Although this works in the editor to show/hide conditional controls, the value is always null in the frontend because the missing cases.

A simple in_array would match both switches

			case 'contains':
				return false !== in_array($right_value,$left_value);
			case '!contains':
				return false === in_array( $right_value, $left_value );

This comment has been minimized.

Copy link

commented Sep 10, 2019



Well be patched.

KingYes added a commit that referenced this issue Sep 10, 2019
Added missing contains and !contains conditions in PHP closes #9043
@KingYes KingYes closed this in 2c4ea2f Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.