Make WordPress Core

Changeset 54785

Timestamp:
11/10/2022 02:59:56 AM (21 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.

Location:
trunk
Files:
2 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
  • trunk/tests/phpunit/tests/canonical.php

    r53043 r54785  
    376376        delete_option( 'page_on_front' );
    377377    }
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
    378405}
Note: See TracChangeset for help on using the changeset viewer.