Make WordPress Core

Changeset 62640


Ignore:
Timestamp:
07/06/2026 04:12:52 AM (2 months ago)
Author:
westonruter
Message:

Docs: Add numeric-string types to DB-backed class properties.

Add @phpstan-var numeric-string annotations to string properties which hold integer database values:

  • WP_Comment::$comment_ID
  • WP_Comment::$comment_post_ID
  • WP_Comment::$comment_karma
  • WP_Comment::$comment_parent
  • WP_Comment::$user_id
  • the eight WP_Site properties backed by integer columns of the wp_blogs table
  • the private WP_Network::$blog_id property

Previously the numeric-string nature of such properties was only indicated in the property description:

A numeric string, for compatibility reasons.

Additionally, document the magic WP_Network::$blog_id property, which is exposed via __get() as a numeric string but was missing from the class-level @property tags.

Finally, correct the documented types of three magic properties:

  • WP_Site::$post_count is lazy-loaded via get_option(), so it is a numeric string once read back from the database and false when the option is not set (new sites with no published posts); it holds an integer only when served from the options cache in the same request that updated it.
  • WP_User::$user_status always holds a numeric string coming raw off the users table row.
  • WP_User::$user_level resolves through user metadata as a numeric string (or an empty string when the metadata is absent), holding an integer only after WP_User::update_user_level_from_caps() has assigned one to the instance in the same request.

Developed in https://github.com/WordPress/wordpress-develop/pull/12408.
Follow-up to r37657, r37870, r38630, r48941, r62437.

See #44723, #64896, #64898.

Location:
trunk/src/wp-includes
Files:
4 edited

Legend:

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

    r61789 r62640  
    2323         * @since 4.4.0
    2424         * @var string
     25         * @phpstan-var numeric-string
    2526         */
    2627        public $comment_ID;
     
    3334         * @since 4.4.0
    3435         * @var string
     36         * @phpstan-var numeric-string
    3537         */
    3638        public $comment_post_ID = '0';
     
    99101         * @since 4.4.0
    100102         * @var string
     103         * @phpstan-var numeric-string
    101104         */
    102105        public $comment_karma = '0';
     
    134137         * @since 4.4.0
    135138         * @var string
     139         * @phpstan-var numeric-string
    136140         */
    137141        public $comment_parent = '0';
     
    144148         * @since 4.4.0
    145149         * @var string
     150         * @phpstan-var numeric-string
    146151         */
    147152        public $user_id = '0';
  • trunk/src/wp-includes/class-wp-network.php

    r59020 r62640  
    1919 * @since 4.4.0
    2020 *
    21  * @property int $id
    22  * @property int $site_id
     21 * @property int    $id
     22 * @property string $blog_id
     23 * @property int    $site_id
     24 *
     25 * @phpstan-property numeric-string $blog_id
    2326 */
    2427#[AllowDynamicProperties]
     
    6265         * @since 4.4.0
    6366         * @var string
     67         * @phpstan-var numeric-string
    6468         */
    6569        private $blog_id = '0';
  • trunk/src/wp-includes/class-wp-site.php

    r61789 r62640  
    1616 * @since 4.5.0
    1717 *
    18  * @property int    $id
    19  * @property int    $network_id
    20  * @property string $blogname
    21  * @property string $siteurl
    22  * @property int    $post_count
    23  * @property string $home
     18 * @property int              $id
     19 * @property int              $network_id
     20 * @property string           $blogname
     21 * @property string           $siteurl
     22 * @property int|string|false $post_count
     23 * @property string           $home
     24 *
     25 * @phpstan-property int|numeric-string|false $post_count
    2426 */
    2527#[AllowDynamicProperties]
     
    3537         * @since 4.5.0
    3638         * @var string
     39         * @phpstan-var numeric-string
    3740         */
    3841        public $blog_id;
     
    6467         * @since 4.5.0
    6568         * @var string
     69         * @phpstan-var numeric-string
    6670         */
    6771        public $site_id = '0';
     
    9094         * @since 4.5.0
    9195         * @var string
     96         * @phpstan-var numeric-string
    9297         */
    9398        public $public = '1';
     
    100105         * @since 4.5.0
    101106         * @var string
     107         * @phpstan-var numeric-string
    102108         */
    103109        public $archived = '0';
     
    113119         * @since 4.5.0
    114120         * @var string
     121         * @phpstan-var numeric-string
    115122         */
    116123        public $mature = '0';
     
    123130         * @since 4.5.0
    124131         * @var string
     132         * @phpstan-var numeric-string
    125133         */
    126134        public $spam = '0';
     
    133141         * @since 4.5.0
    134142         * @var string
     143         * @phpstan-var numeric-string
    135144         */
    136145        public $deleted = '0';
     
    143152         * @since 4.5.0
    144153         * @var string
     154         * @phpstan-var numeric-string
    145155         */
    146156        public $lang_id = '0';
  • trunk/src/wp-includes/class-wp-user.php

    r62553 r62640  
    1515 *              Existing passwords may still be hashed using phpass.
    1616 *
    17  * @property string $nickname
    18  * @property string $description
    19  * @property string $user_description
    20  * @property string $first_name
    21  * @property string $user_firstname
    22  * @property string $last_name
    23  * @property string $user_lastname
    24  * @property string $user_login
    25  * @property string $user_pass
    26  * @property string $user_nicename
    27  * @property string $user_email
    28  * @property string $user_url
    29  * @property string $user_registered
    30  * @property string $user_activation_key
    31  * @property string $user_status
    32  * @property int    $user_level
    33  * @property string $display_name
    34  * @property string $spam
    35  * @property string $deleted
    36  * @property string $locale
    37  * @property string $rich_editing
    38  * @property string $syntax_highlighting
    39  * @property string $use_ssl
     17 * @property string     $nickname
     18 * @property string     $description
     19 * @property string     $user_description
     20 * @property string     $first_name
     21 * @property string     $user_firstname
     22 * @property string     $last_name
     23 * @property string     $user_lastname
     24 * @property string     $user_login
     25 * @property string     $user_pass
     26 * @property string     $user_nicename
     27 * @property string     $user_email
     28 * @property string     $user_url
     29 * @property string     $user_registered
     30 * @property string     $user_activation_key
     31 * @property string     $user_status
     32 * @property int|string $user_level
     33 * @property string     $display_name
     34 * @property string     $spam
     35 * @property string     $deleted
     36 * @property string     $locale
     37 * @property string     $rich_editing
     38 * @property string     $syntax_highlighting
     39 * @property string     $use_ssl
     40 *
     41 * @phpstan-property numeric-string        $user_status
     42 * @phpstan-property int|numeric-string|'' $user_level
    4043 */
    4144#[AllowDynamicProperties]
Note: See TracChangeset for help on using the changeset viewer.