Make WordPress Core


Ignore:
Timestamp:
08/26/2025 05:24:06 PM (15 months ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Check the result of get_term() in WP_Term_Query::get_terms().

get_term() can return WP_Error or null on failure, so the result should be verified as a WP_Term instance before accessing the count property.

This commit prevents a PHP warning if get_term() returns null for a child term:

Warning: Attempt to read property "count" on null

Follow-up to [27458], [37572].

Props josephscott, coleatkinson1, kebbet, jakariaistauk, sabernhardt, westonruter, SergeyBiryukov.
Fixes #63877.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-term-query.php

    r59325 r60661  
    850850                                                foreach ( $children as $child_id ) {
    851851                                                        $child = get_term( $child_id, $term->taxonomy );
    852                                                         if ( $child->count ) {
     852
     853                                                        if ( $child instanceof WP_Term && $child->count ) {
    853854                                                                continue 2;
    854855                                                        }
Note: See TracChangeset for help on using the changeset viewer.