Code Modernization: Correct the check for negative post IDs in WP_Query::parse_query() to work as expected on PHP 8.

PHP 8 changes the way string to number comparisons are performed: https://wiki.php.net/rfc/string_to_number_comparison

In particular, checking if an empty string is less than zero in PHP 8 evaluates to `true`, not `false`.

For `WP_Query`, this resulted in unintentionally returning a 404 error for most of front-end requests, instead of the relevant content.

By explicitly casting the value to `int`, we make sure to compare both values as numbers, rather than a string and a number.

Follow-up to [38288].

Props trepmal.
See #50913.

git-svn-id: https://develop.svn.wordpress.org/trunk@48960 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-09-09 02:33:22 +00:00
parent 427d72c8a1
commit f6f117a0a9

View File

@ -759,7 +759,7 @@ class WP_Query {
$this->is_favicon = true; $this->is_favicon = true;
} }
if ( ! is_scalar( $qv['p'] ) || $qv['p'] < 0 ) { if ( ! is_scalar( $qv['p'] ) || (int) $qv['p'] < 0 ) {
$qv['p'] = 0; $qv['p'] = 0;
$qv['error'] = '404'; $qv['error'] = '404';
} else { } else {