Make WordPress Core

Timestamp:
03/03/2026 05:53:52 AM (2 days 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-user.php

    r61387 r61789  
    122122     * @global wpdb $wpdb WordPress database abstraction object.
    123123     *
    124      * @param int|string|stdClass|WP_User $id      User's ID, a WP_User object, or a user object from the DB.
    125      * @param string                      $name    Optional. User's username
    126      * @param int                         $site_id Optional Site ID, defaults to current site.
     124     * @param int|string| $id      User's ID, a WP_User object, or a user object from the DB.
     125     * @param string            $name    Optional. User's username
     126     * @param int               $site_id Optional Site ID, defaults to current site.
    127127     */
    128128    public function __construct( $id = 0, $name = '', $site_id = 0 ) {
Note: See TracChangeset for help on using the changeset viewer.