Opened 8 weeks ago
Last modified 8 weeks ago
#64311 assigned enhancement
Abilities API: add filters for input and output validation
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | 6.9 |
| Component: | AI | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
The Abilities API currently validates ability input and output against JSON Schema using WordPress's built-in rest_validate_value_from_schema(), which supports only a subset of JSON Schema Draft 4 (aligning with WordPress core). This approach is reliable for core compatibility but limits extenders to dated JSON Schema features, missing newer ones like $ref references for composability and reusability, and not keyword to exclude patterns.
Developers extending the Abilities API that need more expressive schema validation have no way to override the default validator without forking or monkey-patching.
Proposed Solution
Introduce two hooks to allow custom validation:
/**
* Filters the input validation result for an ability.
*
* @since 7.0.0
*
* @param true|WP_Error $is_valid Validation result (true or WP_Error).
* @param mixed $input The input being validated.
* @param string $name The ability name.
*/
apply_filters( 'wp_ability_validate_input', $is_valid, $input, $name );
/**
* Filters the output validation result for an ability.
*
* @since 7.0.0
*
* @param true|WP_Error $is_valid Validation result (true or WP_Error).
* @param mixed $output The output being validated.
* @param string $name The ability name.
*/
apply_filters( 'wp_ability_validate_output', $is_valid, $output, $name );
Related
Change History (3)
This ticket was mentioned in PR #10557 on WordPress/wordpress-develop by @priethor.
8 weeks ago
#1
- Keywords has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/64311