Skip to content

Commit

Permalink
Canonical: Protect against error for term not exists queries.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
peterwilsoncc committed Nov 10, 2022
1 parent 0f7fcc2 commit 486bec9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion wp-includes/canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 486bec9

Please sign in to comment.