Make WordPress Core


Ignore:
Timestamp:
10/27/2026 03:22:19 AM (2 weeks ago)
Author:
westonruter
Message:

Docs: Add class-level PHPStan annotations.

Members that WP_Theme and WP_Query serve through their magic methods were unknown to static analysis, so every access to one was reported as an undefined or private property and recorded in the PHPStan baselines. These are now declared at the class level: the WP_Theme properties with @property-read, since they are public back-compat API that belongs in the developer docs, and the private WP_Query members that its $compat_fields and $compat_methods expose with PHPStan-only tags. Where a WP_Theme property comes from a method that can return false, its type includes false, which surfaces a few existing cases in WP_Debug_Data that pass such a value on as a string.

WP_Block_List declares the key and value types of the Iterator and ArrayAccess interfaces it implements, so that iterating over or indexing a block list yields WP_Block instances. The WP_Widget::update_callback() and WP_Widget::form_callback() methods are marked @final, as their documentation already says not to override them. The same note on WP_Widget::display_callback() is not enforced, since at least one popular plugin overrides it.

The annotations are adopted from the function map of the php-stubs/wordpress-stubs package.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13891.
Follow-up to r31151, r48159, r63020.

Props swissspidy, marian1, westonruter.
See #65817.

File:
1 edited

Legend:

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

    r64677 r64794  
    66 * @subpackage Theme
    77 * @since 3.4.0
     8 *
     9 * @property-read string|false   $name
     10 * @property-read string|false   $title
     11 * @property-read string|false   $version
     12 * @property-read string|false   $parent_theme
     13 * @property-read string         $template_dir
     14 * @property-read string         $stylesheet_dir
     15 * @property-read string         $template
     16 * @property-read string         $stylesheet
     17 * @property-read string|false   $screenshot
     18 * @property-read string|false   $description
     19 * @property-read string|false   $author
     20 * @property-read string[]|false $tags
     21 * @property-read string         $theme_root
     22 * @property-read string         $theme_root_uri
    823 *
    924 * @phpstan-type Theme_Key 'Name'|'Version'|'Status'|'Title'|'Author'|'Author Name'|'Author URI'|'Description'|'Template'|'Stylesheet'|'Template Files'|'Stylesheet Files'|'Template Dir'|'Stylesheet Dir'|'Screenshot'|'Tags'|'Theme Root'|'Theme Root URI'|'Parent Theme'
Note: See TracChangeset for help on using the changeset viewer.