From 486bec9939c41cdbe3facfd905afadfae7a89340 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Thu, 10 Nov 2022 03:01:14 +0000 Subject: [PATCH] Canonical: Protect against error for term not exists queries. Prevent term `NOT EXISTS` queries causing `redirect_canonical()` to throw a fatal error in PHP 8 and above, or a warning in earlier versions. This ensures the `tax_query`'s `terms` property both exists and is countable before attempting to count it. Props codesdnc, SergeyBiryukov, kadamwhite, costdev, miguelaxcar. Fixes #55955. Built from https://develop.svn.wordpress.org/trunk@54785 git-svn-id: http://core.svn.wordpress.org/trunk@54337 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 4 +++- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 9404ed6ea5..5e8efb0bae 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -331,7 +331,9 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { $term_count = 0; foreach ( $wp_query->tax_query->queried_terms as $tax_query ) { - $term_count += count( $tax_query['terms'] ); + if ( isset( $tax_query['terms'] ) && is_countable( $tax_query['terms'] ) ) { + $term_count += count( $tax_query['terms'] ); + } } $obj = $wp_query->get_queried_object(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 141f629705..0edff1c022 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.2-alpha-54782'; +$wp_version = '6.2-alpha-54785'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.