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(
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; |
|
default: |
|
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 );
JS Conditions function has contains
elementor/assets/dev/js/editor/utils/conditions.js
Lines 20 to 23 in 5d257d0
which works right in the editor to check if the string is in the control that has array as value
this option does not exists in the php version of the Conditions class
elementor/includes/conditions.php
Lines 33 to 56 in 5d257d0
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_arraywould match both switches