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.
Merges [54785] to the 6.1 branch.
Fixes #55955.
Built from https://develop.svn.wordpress.org/branches/6.1@54793


git-svn-id: http://core.svn.wordpress.org/branches/6.1@54345 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2022-11-10 16:25:14 +00:00
parent 98d234aef0
commit c5374bbbdc
2 changed files with 4 additions and 2 deletions

View File

@ -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();

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1.1-alpha-54792';
$wp_version = '6.1.1-alpha-54793';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.