Commit 48a339e6f5 for wordpress.org

commit 48a339e6f53fbccf01a0bec96193b12aeb70ce51
Author: westonruter <westonruter@git.wordpress.org>
Date:   Thu Dec 3 19:02:04 2026 +0000

    Abilities API: Resolve the strict return.type PHPStan error.

    `WP_Ability_Categories_Registry::get_all_registered()` was documented as returning an array keyed by strings, but the slug check in `register()` accepts an all-digit slug such as `'123'`, which PHP stores under an integer key. The key type of the returned array, and of the property holding it, now includes integers, while the PHPStan-specific tags narrow it to the lowercase slugs and non-negative integers that can actually occur. This empties the strict return.type baseline, so it is removed. The `wp_get_ability_categories()` wrapper documents the same keys and points callers that need the slug as a string to `WP_Ability_Category::get_slug()`.

    Additionally, `is_registered()` and `wp_has_ability_category()` now assert the narrowed slug type when they return true, and `unregister()` and `get_registered()` check the array with `isset()` directly, so that PHPStan knows the entry exists when `reportPossiblyNonexistentGeneralArrayOffset` is enabled. Behavior is unchanged.

    Developed in https://github.com/WordPress/wordpress-develop/pull/16448.
    Follow-up to r61032, r65668.

    Props hmbashar, westonruter, lancewillett.
    See #66739.

    Built from https://develop.svn.wordpress.org/trunk@65895


    git-svn-id: http://core.svn.wordpress.org/trunk@64924 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/abilities-api.php b/wp-includes/abilities-api.php
index 50f4b6ac05..804dfe0166 100644
--- a/wp-includes/abilities-api.php
+++ b/wp-includes/abilities-api.php
@@ -822,6 +822,8 @@ function wp_unregister_ability_category( string $slug ): ?WP_Ability_Category {
  *
  * @param string $slug The slug of the ability category to check.
  * @return bool `true` if the ability category is registered, `false` otherwise.
+ *
+ * @phpstan-assert-if-true =lowercase-string&non-empty-string $slug
  */
 function wp_has_ability_category( string $slug ): bool {
 	$registry = WP_Ability_Categories_Registry::get_instance();
@@ -883,9 +885,15 @@ function wp_get_ability_category( string $slug ): ?WP_Ability_Category {
  * @see WP_Ability_Categories_Registry::get_all_registered()
  * @see wp_get_ability_category()
  *
- * @return WP_Ability_Category[] An array of registered ability category instances,
- *                               keyed by category slug. Returns an empty array if no ability categories
- *                               are registered or if the registry is unavailable.
+ * @return array<string|int, WP_Ability_Category> An array of registered ability category instances,
+ *                                                keyed by category slug. A numeric slug, such as `'123'`,
+ *                                                is keyed by an integer, since PHP casts numeric string
+ *                                                array keys to integers; use
+ *                                                {@see WP_Ability_Category::get_slug()} when a string slug is
+ *                                                needed. Returns an empty array if no ability categories
+ *                                                are registered or if the registry is unavailable.
+ *
+ * @phpstan-return array<(lowercase-string&non-empty-string)|non-negative-int, WP_Ability_Category>
  */
 function wp_get_ability_categories(): array {
 	$registry = WP_Ability_Categories_Registry::get_instance();
diff --git a/wp-includes/abilities-api/class-wp-ability-categories-registry.php b/wp-includes/abilities-api/class-wp-ability-categories-registry.php
index 92e6dbdd84..16b5188155 100644
--- a/wp-includes/abilities-api/class-wp-ability-categories-registry.php
+++ b/wp-includes/abilities-api/class-wp-ability-categories-registry.php
@@ -30,7 +30,9 @@ final class WP_Ability_Categories_Registry {
 	 * Holds the registered ability categories.
 	 *
 	 * @since 6.9.0
-	 * @var WP_Ability_Category[]
+	 * @var array<string|int, WP_Ability_Category>
+	 *
+	 * @phpstan-var array<(lowercase-string&non-empty-string)|non-negative-int, WP_Ability_Category>
 	 */
 	private $registered_categories = array();

@@ -121,7 +123,7 @@ final class WP_Ability_Categories_Registry {
 	 * @return WP_Ability_Category|null The unregistered ability category instance on success, null on failure.
 	 */
 	public function unregister( string $slug ): ?WP_Ability_Category {
-		if ( ! $this->is_registered( $slug ) ) {
+		if ( ! isset( $this->registered_categories[ $slug ] ) ) {
 			_doing_it_wrong(
 				__METHOD__,
 				/* translators: %s: Ability category slug. */
@@ -146,7 +148,9 @@ final class WP_Ability_Categories_Registry {
 	 *
 	 * @see wp_get_ability_categories()
 	 *
-	 * @return array<string, WP_Ability_Category> The array of registered ability categories.
+	 * @return array<string|int, WP_Ability_Category> The array of registered ability categories.
+	 *
+	 * @phpstan-return array<(lowercase-string&non-empty-string)|non-negative-int, WP_Ability_Category>
 	 */
 	public function get_all_registered(): array {
 		return $this->registered_categories;
@@ -163,6 +167,8 @@ final class WP_Ability_Categories_Registry {
 	 *
 	 * @param string $slug The slug of the ability category.
 	 * @return bool True if the ability category is registered, false otherwise.
+	 *
+	 * @phpstan-assert-if-true =lowercase-string&non-empty-string $slug
 	 */
 	public function is_registered( string $slug ): bool {
 		return isset( $this->registered_categories[ $slug ] );
@@ -181,7 +187,7 @@ final class WP_Ability_Categories_Registry {
 	 * @return WP_Ability_Category|null The registered ability category instance, or null if it is not registered.
 	 */
 	public function get_registered( string $slug ): ?WP_Ability_Category {
-		if ( ! $this->is_registered( $slug ) ) {
+		if ( ! isset( $this->registered_categories[ $slug ] ) ) {
 			_doing_it_wrong(
 				__METHOD__,
 				/* translators: %s: Ability category slug. */
diff --git a/wp-includes/version.php b/wp-includes/version.php
index c6756dc102..5704a3ecb6 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65894';
+$wp_version = '7.3-alpha-65895';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.