Fixes `strpos` in `ComparisonOperation` for PHP 8 (#44007)

* Fixes

* Changelog

* Add breaks
This commit is contained in:
Ilyas Foo 2024-01-24 08:42:41 +08:00 committed by GitHub
parent 9b98a85380
commit f85d275c3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix strpos php8 compliant and payment gateway recommendation rule default value

View File

@ -968,7 +968,7 @@ class DefaultPaymentGateways {
'option_name' => 'woocommerce_onboarding_profile',
'operation' => 'in',
'value' => array( 'no_im_selling_offline', 'im_selling_both_online_and_offline' ),
'default' => array(),
'default' => '',
);
}

View File

@ -36,22 +36,34 @@ class ComparisonOperation {
if ( is_array( $left_operand ) && is_string( $right_operand ) ) {
return in_array( $right_operand, $left_operand, true );
}
return strpos( $right_operand, $left_operand ) !== false;
if ( is_string( $right_operand ) && is_string( $left_operand ) ) {
return strpos( $right_operand, $left_operand ) !== false;
}
break;
case '!contains':
if ( is_array( $left_operand ) && is_string( $right_operand ) ) {
return ! in_array( $right_operand, $left_operand, true );
}
return strpos( $right_operand, $left_operand ) === false;
if ( is_string( $right_operand ) && is_string( $left_operand ) ) {
return strpos( $right_operand, $left_operand ) === false;
}
break;
case 'in':
if ( is_array( $right_operand ) && is_string( $left_operand ) ) {
return in_array( $left_operand, $right_operand, true );
}
return strpos( $left_operand, $right_operand ) !== false;
if ( is_string( $left_operand ) && is_string( $right_operand ) ) {
return strpos( $left_operand, $right_operand ) !== false;
}
break;
case '!in':
if ( is_array( $right_operand ) && is_string( $left_operand ) ) {
return ! in_array( $left_operand, $right_operand, true );
}
return strpos( $left_operand, $right_operand ) === false;
if ( is_string( $left_operand ) && is_string( $right_operand ) ) {
return strpos( $left_operand, $right_operand ) === false;
}
break;
}
return false;