@@ -408,7 +408,7 @@ public function get_meta_item( string $key, $default_value = null ) {
408408 * @param mixed $input Optional. The input data to validate. Default `null`.
409409 * @return true|WP_Error Returns true if valid or the WP_Error object if validation fails.
410410 */
411- protected function validate_input ( $ input = null ) {
411+ public function validate_input ( $ input = null ) {
412412 $ input_schema = $ this ->get_input_schema ();
413413 if ( empty ( $ input_schema ) ) {
414414 if ( null === $ input ) {
@@ -462,23 +462,20 @@ protected function invoke_callback( callable $callback, $input = null ) {
462462 /**
463463 * Checks whether the ability has the necessary permissions.
464464 *
465- * The input is validated against the input schema before it is passed to to permission callback.
465+ * Please note that input is not automatically validated against the input schema.
466+ * Use `validate_input()` method to validate input before calling this method if needed.
466467 *
467468 * @since 6.9.0
468469 *
469- * @param mixed $input Optional. The input data for permission checking. Default `null`.
470+ * @see validate_input()
471+ *
472+ * @param mixed $input Optional. The valid input data for permission checking. Default `null`.
470473 * @return bool|WP_Error Whether the ability has the necessary permission.
471474 */
472475 public function check_permissions ( $ input = null ) {
473- $ is_valid = $ this ->validate_input ( $ input );
474- if ( is_wp_error ( $ is_valid ) ) {
475- return $ is_valid ;
476- }
477-
478476 return $ this ->invoke_callback ( $ this ->permission_callback , $ input );
479477 }
480478
481-
482479 /**
483480 * Executes the ability callback.
484481 *
@@ -539,12 +536,14 @@ protected function validate_output( $output ) {
539536 * @return mixed|WP_Error The result of the ability execution, or WP_Error on failure.
540537 */
541538 public function execute ( $ input = null ) {
539+ $ is_valid = $ this ->validate_input ( $ input );
540+ if ( is_wp_error ( $ is_valid ) ) {
541+ return $ is_valid ;
542+ }
543+
542544 $ has_permissions = $ this ->check_permissions ( $ input );
543545 if ( true !== $ has_permissions ) {
544546 if ( is_wp_error ( $ has_permissions ) ) {
545- if ( 'ability_invalid_input ' === $ has_permissions ->get_error_code () ) {
546- return $ has_permissions ;
547- }
548547 // Don't leak the permission check error to someone without the correct perms.
549548 _doing_it_wrong (
550549 __METHOD__ ,
@@ -561,7 +560,7 @@ public function execute( $input = null ) {
561560 }
562561
563562 /**
564- * Fires before an ability gets executed and after permission check.
563+ * Fires before an ability gets executed, after input validation and permissions check.
565564 *
566565 * @since 6.9.0
567566 *
0 commit comments