From 7c60a660f19005ee808c2123a89737dbc6fd770a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 9 Sep 2020 02:35:06 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@48960 git-svn-id: http://core.svn.wordpress.org/trunk@48722 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-query.php | 2 +- wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-includes/class-wp-query.php b/wp-includes/class-wp-query.php index 49ac5540c5..a2451bcd01 100644 --- a/wp-includes/class-wp-query.php +++ b/wp-includes/class-wp-query.php @@ -759,7 +759,7 @@ class WP_Query { $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['error'] = '404'; } else { diff --git a/wp-includes/version.php b/wp-includes/version.php index 1466ce01a0..feb53399cd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-48958'; +$wp_version = '5.6-alpha-48960'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.