Commit 45f3ce8d88 for wordpress.org
commit 45f3ce8d883c87090b59b152aa8d64665f76f51b
Author: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Date: Mon Feb 9 17:00:43 2026 +0000
Abilities API: Allow nested namespace ability names (2-4 segments).
Expand ability name validation from exactly 2 segments (`namespace/ability`) to 2-4 segments, enabling names like `my-plugin/resource/find` and `my-plugin/resource/sub/find`.
This allows plugins to organize abilities into logical resource groups. The validation regex changes from `/^[a-z0-9-]+\/[a-z0-9-]+$/` to `/^[a-z0-9-]+(?:\/[a-z0-9-]+){1,3}$/`, which accepts the first segment plus 1-3 additional slash-delimited segments.
Updates the validation regex, error messages, docblocks, and adds corresponding unit and REST API tests.
Props jorgefilipecosta, justlevine, jorbin.
Fixes #64596.
Built from https://develop.svn.wordpress.org/trunk@61602
git-svn-id: http://core.svn.wordpress.org/trunk@60913 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/abilities-api.php b/wp-includes/abilities-api.php
index 73ba658f3f..835bd535d2 100644
--- a/wp-includes/abilities-api.php
+++ b/wp-includes/abilities-api.php
@@ -132,7 +132,8 @@ declare( strict_types = 1 );
*
* Ability names must follow these rules:
*
- * - Include a namespace prefix (e.g., `my-plugin/my-ability`).
+ * - Contain 2 to 4 segments separated by forward slashes
+ * (e.g., `my-plugin/my-ability`, `my-plugin/resource/find`, `my-plugin/resource/sub/find`).
* - Use only lowercase alphanumeric characters, dashes, and forward slashes.
* - Use descriptive, action-oriented names (e.g., `process-payment`, `generate-report`).
*
@@ -225,9 +226,8 @@ declare( strict_types = 1 );
* @see wp_register_ability_category()
* @see wp_unregister_ability()
*
- * @param string $name The name of the ability. Must be a namespaced string containing
- * a prefix, e.g., `my-plugin/my-ability`. Can only contain lowercase
- * alphanumeric characters, dashes, and forward slashes.
+ * @param string $name The name of the ability. Must be the fully-namespaced
+ * string identifier, e.g. `my-plugin/my-ability` or `my-plugin/resource/my-ability`.
* @param array<string, mixed> $args {
* An associative array of arguments for configuring the ability.
*
@@ -318,7 +318,7 @@ function wp_register_ability( string $name, array $args ): ?WP_Ability {
* @see wp_register_ability()
*
* @param string $name The name of the ability to unregister, including namespace prefix
- * (e.g., 'my-plugin/my-ability').
+ * (e.g., 'my-plugin/my-ability' or 'my-plugin/resource/find').
* @return WP_Ability|null The unregistered ability instance on success, `null` on failure.
*/
function wp_unregister_ability( string $name ): ?WP_Ability {
@@ -351,7 +351,7 @@ function wp_unregister_ability( string $name ): ?WP_Ability {
* @see wp_get_ability()
*
* @param string $name The name of the ability to check, including namespace prefix
- * (e.g., 'my-plugin/my-ability').
+ * (e.g., 'my-plugin/my-ability' or 'my-plugin/resource/find').
* @return bool `true` if the ability is registered, `false` otherwise.
*/
function wp_has_ability( string $name ): bool {
@@ -383,7 +383,7 @@ function wp_has_ability( string $name ): bool {
* @see wp_has_ability()
*
* @param string $name The name of the ability, including namespace prefix
- * (e.g., 'my-plugin/my-ability').
+ * (e.g., 'my-plugin/my-ability' or 'my-plugin/resource/find').
* @return WP_Ability|null The registered ability instance, or `null` if not registered.
*/
function wp_get_ability( string $name ): ?WP_Ability {
diff --git a/wp-includes/abilities-api/class-wp-abilities-registry.php b/wp-includes/abilities-api/class-wp-abilities-registry.php
index ecd6dc2785..758dd2c252 100644
--- a/wp-includes/abilities-api/class-wp-abilities-registry.php
+++ b/wp-includes/abilities-api/class-wp-abilities-registry.php
@@ -43,9 +43,8 @@ final class WP_Abilities_Registry {
*
* @see wp_register_ability()
*
- * @param string $name The name of the ability. The name must be a string containing a namespace
- * prefix, i.e. `my-plugin/my-ability`. It can only contain lowercase
- * alphanumeric characters, dashes and the forward slash.
+ * @param string $name The name of the ability. Must be the fully-namespaced
+ * string identifier, e.g. `my-plugin/my-ability` or `my-plugin/resource/my-ability`.
* @param array<string, mixed> $args {
* An associative array of arguments for the ability.
*
@@ -78,11 +77,11 @@ final class WP_Abilities_Registry {
* @return WP_Ability|null The registered ability instance on success, null on failure.
*/
public function register( string $name, array $args ): ?WP_Ability {
- if ( ! preg_match( '/^[a-z0-9-]+\/[a-z0-9-]+$/', $name ) ) {
+ if ( ! preg_match( '/^[a-z0-9-]+(?:\/[a-z0-9-]+){1,3}$/', $name ) ) {
_doing_it_wrong(
__METHOD__,
__(
- 'Ability name must be a string containing a namespace prefix, i.e. "my-plugin/my-ability". It can only contain lowercase alphanumeric characters, dashes and the forward slash.'
+ 'Ability name must contain 2 to 4 segments separated by forward slashes, e.g. "my-plugin/my-ability" or "my-plugin/resource/my-ability". It can only contain lowercase alphanumeric characters, dashes, and forward slashes.'
),
'6.9.0'
);
diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index 967f164115..bdcb8c0bd0 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -52,7 +52,7 @@ class WP_Ability {
/**
* The name of the ability, with its namespace.
- * Example: `my-plugin/my-ability`.
+ * Examples: `my-plugin/my-ability`, `my-plugin/resource/find`.
*
* @since 6.9.0
* @var string
@@ -340,7 +340,7 @@ class WP_Ability {
/**
* Retrieves the name of the ability, with its namespace.
- * Example: `my-plugin/my-ability`.
+ * Examples: `my-plugin/my-ability`, `my-plugin/resource/find`.
*
* @since 6.9.0
*
diff --git a/wp-includes/version.php b/wp-includes/version.php
index a3ed90a601..eb9cbec47b 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.0-alpha-61601';
+$wp_version = '7.0-alpha-61602';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.