wppaste
WordPress

WP_Abilities_Registry

Since
6.9.0
Source
wp-includes/abilities-api/class-wp-abilities-registry.php:20
Manages the registration and lookup of abilities.

Compatibility

WordPress
since 6.9.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 3 of the 5 tracked releases, added in 6.9.0.

Hooks and filters fired · 2

Every hook that fires from inside WP_Abilities_Registry, in the order it appears in the class, grouped by the method that fires it.

Properties · 2

$instanceself|nullprivate static
The singleton instance of the registry.
$registered_abilitiesWP_Ability[]private
Holds the registered abilities.

Methods · 8

Source code

final class WP_Abilities_Registry {	/**	 * The singleton instance of the registry.	 *	 * @since 6.9.0	 * @var self|null	 */	private static $instance = null; 	/**	 * Holds the registered abilities.	 *	 * @since 6.9.0	 * @var WP_Ability[]	 */	private $registered_abilities = array(); 	/**	 * Registers a new ability.	 *	 * Do not use this method directly. Instead, use the `wp_register_ability()` function.	 *	 * @since 6.9.0	 *	 * @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 array<string, mixed> $args {	 *     An associative array of arguments for the ability.	 *	 *     @type string               $label                 The human-readable label for the ability.	 *     @type string               $description           A detailed description of what the ability does.	 *     @type string               $category              The ability category slug this ability belongs to.	 *     @type callable             $execute_callback      A callback function to execute when the ability is invoked.	 *                                                       Receives optional mixed input and returns mixed result or WP_Error.	 *     @type callable             $permission_callback   A callback function to check permissions before execution.	 *                                                       Receives optional mixed input and returns bool or WP_Error.	 *     @type array<string, mixed> $input_schema          Optional. JSON Schema definition for the ability's input.	 *     @type array<string, mixed> $output_schema         Optional. JSON Schema definition for the ability's output.	 *     @type array<string, mixed> $meta                  {	 *         Optional. Additional metadata for the ability.	 *	 *         @type array<string, bool|null> $annotations  {	 *             Optional. Semantic annotations describing the ability's behavioral characteristics.	 *             These annotations are hints for tooling and documentation.	 *	 *             @type bool|null $readonly    Optional. If true, the ability does not modify its environment.	 *             @type bool|null $destructive Optional. If true, the ability may perform destructive updates to its environment.	 *                                          If false, the ability performs only additive updates.	 *             @type bool|null $idempotent  Optional. If true, calling the ability repeatedly with the same arguments	 *                                          will have no additional effect on its environment.	 *         }	 *         @type bool                     $public       Optional. Whether the ability is meant to be available	 *                                                      to clients such as the REST API, MCP, or AI agents.	 *                                                      Seeds the default for per-channel flags like	 *                                                      `$show_in_rest`. Defaults to false.	 *         @type bool                     $show_in_rest Optional. Whether to expose this ability in the REST API.	 *                                                      Default is the value of `$public` when set, false otherwise.	 *     }	 *     @type string               $ability_class         Optional. Custom class to instantiate instead of WP_Ability.	 * }	 * @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 ) ) {			_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.'				),				'6.9.0'			);			return null;		} 		if ( $this->is_registered( $name ) ) {			_doing_it_wrong(				__METHOD__,

Changelog

Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

Signature, return type and hooks compared across 3 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/abilities-api/class-wp-abilities-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.