@@ -400,6 +400,31 @@ public function get_meta_item( string $key, $default_value = null ) {
400400 return array_key_exists ( $ key , $ this ->meta ) ? $ this ->meta [ $ key ] : $ default_value ;
401401 }
402402
403+ /**
404+ * Normalizes the input for the ability, applying the default value from the input schema when needed.
405+ *
406+ * When no input is provided and the input schema is defined with a top-level `default` key, this method returns
407+ * the value of that key. If the input schema does not define a `default`, or if the input schema is empty,
408+ * this method returns null. If input is provided, it is returned as-is.
409+ *
410+ * @since 6.9.0
411+ *
412+ * @param mixed $input Optional. The raw input provided for the ability. Default `null`.
413+ * @return mixed The same input, or the default from schema, or `null` if default not set.
414+ */
415+ public function normalize_input ( $ input = null ) {
416+ if ( null !== $ input ) {
417+ return $ input ;
418+ }
419+
420+ $ input_schema = $ this ->get_input_schema ();
421+ if ( ! empty ( $ input_schema ) && array_key_exists ( 'default ' , $ input_schema ) ) {
422+ return $ input_schema ['default ' ];
423+ }
424+
425+ return null ;
426+ }
427+
403428 /**
404429 * Validates input data against the input schema.
405430 *
@@ -536,6 +561,7 @@ protected function validate_output( $output ) {
536561 * @return mixed|WP_Error The result of the ability execution, or WP_Error on failure.
537562 */
538563 public function execute ( $ input = null ) {
564+ $ input = $ this ->sanitize_input ( $ input );
539565 $ is_valid = $ this ->validate_input ( $ input );
540566 if ( is_wp_error ( $ is_valid ) ) {
541567 return $ is_valid ;
0 commit comments