Skip to content

Commit

Permalink
Fixes strpos in ComparisonOperation for PHP 8 (#44007)
Browse files Browse the repository at this point in the history
* Fixes

* Changelog

* Add breaks
  • Loading branch information
ilyasfoo authored and opr committed Jan 24, 2024
1 parent 4869918 commit 7a3d5f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix strpos php8 compliant and payment gateway recommendation rule default value
Expand Up @@ -968,7 +968,7 @@ public static function get_rules_selling_offline() {
'option_name' => 'woocommerce_onboarding_profile',
'operation' => 'in',
'value' => array( 'no_im_selling_offline', 'im_selling_both_online_and_offline' ),
'default' => array(),
'default' => '',
);
}

Expand Down
Expand Up @@ -36,22 +36,34 @@ public static function compare( $left_operand, $right_operand, $operation ) {
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;
Expand Down

0 comments on commit 7a3d5f8

Please sign in to comment.