Abilities API: Revert Allow nested namespace ability names.

Abilities should follow the same pattern as all other namespaces and use a single namespace.

Reverts [61602].

See #64596.
Props jorgefilipecosta, justlevine, audrasjb.

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


git-svn-id: http://core.svn.wordpress.org/trunk@61376 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin
2026-03-23 19:41:51 +00:00
parent ff72263643
commit 239e8edce5
4 changed files with 15 additions and 14 deletions

View File

@@ -132,8 +132,7 @@ declare( strict_types = 1 );
*
* Ability names must follow these rules:
*
* - Contain 2 to 4 segments separated by forward slashes
* (e.g., `my-plugin/my-ability`, `my-plugin/resource/find`, `my-plugin/resource/sub/find`).
* - Include a namespace prefix (e.g., `my-plugin/my-ability`).
* - Use only lowercase alphanumeric characters, dashes, and forward slashes.
* - Use descriptive, action-oriented names (e.g., `process-payment`, `generate-report`).
*
@@ -226,8 +225,9 @@ declare( strict_types = 1 );
* @see wp_register_ability_category()
* @see wp_unregister_ability()
*
* @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 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 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' or 'my-plugin/resource/find').
* (e.g., 'my-plugin/my-ability').
* @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' or 'my-plugin/resource/find').
* (e.g., 'my-plugin/my-ability').
* @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' or 'my-plugin/resource/find').
* (e.g., 'my-plugin/my-ability').
* @return WP_Ability|null The registered ability instance, or `null` if not registered.
*/
function wp_get_ability( string $name ): ?WP_Ability {

View File

@@ -43,8 +43,9 @@ final class WP_Abilities_Registry {
*
* @see wp_register_ability()
*
* @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 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 array<string, mixed> $args {
* An associative array of arguments for the ability.
*
@@ -77,11 +78,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-]+){1,3}$/', $name ) ) {
if ( ! preg_match( '/^[a-z0-9-]+\/[a-z0-9-]+$/', $name ) ) {
_doing_it_wrong(
__METHOD__,
__(
'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.'
'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.'
),
'6.9.0'
);

View File

@@ -52,7 +52,7 @@ class WP_Ability {
/**
* The name of the ability, with its namespace.
* Examples: `my-plugin/my-ability`, `my-plugin/resource/find`.
* Example: `my-plugin/my-ability`.
*
* @since 6.9.0
* @var string
@@ -340,7 +340,7 @@ class WP_Ability {
/**
* Retrieves the name of the ability, with its namespace.
* Examples: `my-plugin/my-ability`, `my-plugin/resource/find`.
* Example: `my-plugin/my-ability`.
*
* @since 6.9.0
*

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-beta6-62093';
$wp_version = '7.0-beta6-62094';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.