Make WordPress Core


Ignore:
Timestamp:
11/10/2022 02:59:56 AM (17 months ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r53043 r54785  
    332332
    333333            foreach ( $wp_query->tax_query->queried_terms as $tax_query ) {
    334                 $term_count += count( $tax_query['terms'] );
     334                if ( isset( $tax_query['terms'] ) && is_countable( $tax_query['terms'] ) ) {
     335                    $term_count += count( $tax_query['terms'] );
     336                }
    335337            }
    336338
Note: See TracChangeset for help on using the changeset viewer.