WP_Ability::__construct
Constructor.
Do not use this constructor directly. Instead, use the wp_register_ability()
Method of the class: WP_Ability{}
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
null. Nothing (null).
Usage
$WP_Ability = new WP_Ability(); $WP_Ability->__construct( $name, $args );
- $name(string) (required)
- The name of the ability, with its namespace.
- $args(array<string, mixed>) (required)
An associative array of arguments for the ability.
-
label(string)
The human-readable label for the ability. -
description(string)
A detailed description of what the ability does. -
category(string)
The ability category slug this ability belongs to. -
execute_callback(callable)
A callback function to execute when the ability is invoked. Receives optional mixed input and returns mixed result or WP_Error. -
permission_callback(callable)
A callback function to check permissions before execution. Receives optional mixed input and returns bool or WP_Error. -
mixed>(array<string,)
$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`. @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.
Default: false
-
Notes
| See: wp_register_ability() |
Changelog
| Since 6.9.0 | Introduced. |
WP_Ability::__construct() WP Ability:: construct code WP 7.1.4
public function __construct( string $name, array $args ) {
$this->name = $name;
$properties = $this->prepare_properties( $args );
foreach ( $properties as $property_name => $property_value ) {
if ( ! property_exists( $this, $property_name ) ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: %s: Property name. */
__( 'Property "%1$s" is not a valid property for ability "%2$s". Please check the %3$s class for allowed properties.' ),
'<code>' . esc_html( $property_name ) . '</code>',
'<code>' . esc_html( $this->name ) . '</code>',
'<code>' . __CLASS__ . '</code>'
),
'6.9.0'
);
continue;
}
$this->$property_name = $property_value;
}
}