Constructor.
Description
Do not use this constructor directly. Instead, use the wp_register_ability() function.
See also
Parameters
$namestringrequired- The name of the ability, with its namespace.
- 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.
@typebool|null$readonly Optional. If true, the ability does not modify its environment.
@typebool|null$destructive Optional. If true, the ability may perform destructive updates to its environment.
If false, the ability performs only additive updates.
@typebool|null$idempotent Optional. If true, calling the ability repeatedly with the same arguments will have no additional effect on its environment.
} @type bool $show_in_rest Optional. Whether to expose this ability in the REST API. Default false.
} }
Source
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;
}
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.