Normalizes the input for the ability, applying the default value from the input schema when needed.
Description
When no input is provided and the input schema is defined with a top-level default key, this method returns the value of that key. If the input schema does not define a default, or if the input schema is empty, this method returns null. If input is provided, it is returned as-is.
The ‘wp_ability_normalize_input’ filter fires after the built-in default-value handling, allowing plugins to transform the result.
Parameters
$inputmixedoptional- The raw input provided for the ability.
Default:
null
Source
public function normalize_input( $input = null ) {
if ( null === $input ) {
$input_schema = $this->get_input_schema();
if ( array_key_exists( 'default', $input_schema ) ) {
$input = $input_schema['default'];
}
}
/**
* Filters the normalized input for an ability.
*
* Fires after `normalize_input()` has applied any default value declared in the input schema,
* giving plugins a chance to adjust the input before it is consumed downstream. Common uses
* include defaulting beyond what JSON Schema can express, prompt enrichment, and injecting
* caller metadata.
*
* Returning a `WP_Error` causes callers that propagate it (such as `execute()`) to halt
* before validation, permission checks, and the registered execute callback.
*
* @since 7.1.0
*
* @param mixed $input The normalized input data.
* @param string $ability_name The name of the ability.
* @param WP_Ability $ability The ability instance.
*/
return apply_filters( 'wp_ability_normalize_input', $input, $this->name, $this );
}
Hooks
- apply_filters( ‘wp_ability_normalize_input’,
mixed $input ,string $ability_name ,WP_Ability $ability ) Filters the normalized input for an ability.
User Contributed Notes
You must log in before being able to contribute a note or feedback.