Invokes a callable, ensuring the input is passed through only if the input schema is defined.
Parameters
$callbackcallablerequired- The callable to invoke.
$inputmixedoptional- The input data for the ability.
Default:
null
Source
protected function invoke_callback( callable $callback, $input = null ) {
$args = array();
if ( ! empty( $this->get_input_schema() ) ) {
$args[] = $input;
}
try {
return $callback( ...$args );
} catch ( Throwable $e ) {
return new WP_Error(
'ability_callback_exception',
sprintf(
/* translators: 1: Ability name, 2: Exception message. */
__( 'Ability "%1$s" callback threw an exception: %2$s' ),
esc_html( $this->name ),
esc_html( $e->getMessage() )
)
);
}
}
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |

User Contributed Notes
You must log in before being able to contribute a note or feedback.