Skip to content

Commit 39bf7c9

Browse files
committed
dev: add wp_ability_class filter and pass-through $properties
1 parent 53b7ca1 commit 39bf7c9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

includes/abilities-api/class-wp-abilities-registry.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,23 @@ public function register( string $name, array $properties = array() ): ?WP_Abili
147147
return null;
148148
}
149149

150-
$ability = new WP_Ability(
150+
/**
151+
* Filters the class used to instantiate the ability.
152+
*
153+
* This is helpful for creating complex ability types that are not well expressed by array values and callbacks.
154+
*
155+
* @param string $ability_class The class name to instantiate the ability. Must extend \WP_Ability.
156+
* @param string $name The name of the ability being registered.
157+
* @param array<string,mixed> $properties The properties of the ability being registered. See
158+
* `wp_register_ability()` for the expected structure.
159+
*
160+
* @phpstan-param class-string<\WP_Ability> $ability_class
161+
*/
162+
$ability_class = apply_filters( 'wp_ability_class', WP_Ability::class, $name, $properties );
163+
164+
$ability = new $ability_class(
151165
$name,
152-
array(
153-
'label' => $properties['label'],
154-
'description' => $properties['description'],
155-
'input_schema' => $properties['input_schema'] ?? array(),
156-
'output_schema' => $properties['output_schema'] ?? array(),
157-
'execute_callback' => $properties['execute_callback'],
158-
'permission_callback' => $properties['permission_callback'] ?? null,
159-
'meta' => $properties['meta'] ?? array(),
160-
)
166+
$properties
161167
);
162168

163169
$this->registered_abilities[ $name ] = $ability;

0 commit comments

Comments
 (0)