Make WordPress Core


Ignore:
Timestamp:
03/03/2026 05:53:52 AM (9 months ago)
Author:
westonruter
Message:

Code Quality: Normalize object as type being supplied as comment, post, site, term, and user.

When constructing these objects, the specific instance type is redundantly used in a union with a generic object. A generic object can be passed directly from database row result. This also hardens get_post() to account for passing an object that lacks an ID property. Similarly, sanitize_term() is hardened to account for an object lacking a term_id property. Comprehensive unit tests are added for get_post() and sanitize_term().

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11096

Props westonruter, apermo.
See #64238, #64225.

File:
1 edited

Legend:

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

    r61445 r61789  
    193193         * @since 4.4.0
    194194         *
    195          * @param WP_Term|object $term Term object.
     195         * @param object $term Term object.
    196196         */
    197197        public function __construct( $term ) {
Note: See TracChangeset for help on using the changeset viewer.