Make WordPress Core


Ignore:
Timestamp:
10/07/2026 08:51:38 PM (6 weeks ago)
Author:
westonruter
Message:

Docs: Add refined string types for PHPStan.

Adds non-empty-string, non-falsy-string, and lowercase-string return types where a function always produces such a string, mostly taken from ​php-stubs/wordpress-stubs. Where PHPStan cannot infer the refinement from the function body, such as from a static cache or a sprintf() call, the type is asserted inline so that the narrower types introduce no new errors.

Registration functions now require a lowercase key where it is documented or validated as lowercase. This covers post types, post statuses, and taxonomies, as well as the names used by the abilities, block bindings, block types, block templates, connectors, and icons registries. Static analysis describes what callers should supply, so these follow the documented contract even where a function lowercases the key itself. Admin menu slugs are only narrowed to non-falsy-string: although they are documented as lowercase, established plugins register mixed-case slugs which appear in admin URLs and cannot be changed without breaking links. Script and style handles are left as plain strings for the same reason, since mixed-case handles are widespread and other code must pass them verbatim as dependencies.

The only runtime change is in wp_internal_hosts(), which now re-indexes the deduplicated hosts with array_values() so that it returns a list.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/13892.
Follow-up to r55289, r64163.

Props marian1, swissspidy, westonruter.
See #65817.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-type-registry.php

    r63443 r64235  
    4545         *                                   on accepted arguments. Default empty array.
    4646         * @return WP_Block_Type|false The registered block type on success, or false on failure.
     47         *
     48         * @phpstan-param (lowercase-string&non-falsy-string)|WP_Block_Type $name
    4749         */
    4850        public function register( $name, $args = array() ) {
Note: See TracChangeset for help on using the changeset viewer.