Commit 291dbbd190 for wordpress.org

commit 291dbbd1906278c60fa2045f5a823cdd2ea9cd3d
Author: gziolo <gziolo@git.wordpress.org>
Date:   Thu Dec 3 12:02:04 2026 +0000

    Abilities API: Clarify errors when output validation fails

    When output validation fails, the callback has already run. The error did not say so, and a caller could retry an action that had already taken effect.

    The error message now says that the ability ran. Unless the ability has the `readonly` annotation set to `true`, it also asks the caller to check the outcome before retrying.

    Two error codes replace `ability_invalid_output`:

    * `ability_output_schema_mismatch` when the output does not match the schema.
    * `ability_output_rejected` when the `wp_ability_validate_output` filter returns `false`.

    Code that checks for `ability_invalid_output` needs to handle the new codes. A `WP_Error` returned by the filter is still passed through unchanged.

    Developed in https://github.com/WordPress/wordpress-develop/pull/16122.
    Follow-up to r61032, r62398.

    Props micahele, gziolo, jorgefilipecosta, zaguiini, mamaduka.
    Fixes #66433.



    Built from https://develop.svn.wordpress.org/trunk@65878


    git-svn-id: http://core.svn.wordpress.org/trunk@64907 1a063a9b-81f0-0310-95a4-ce76da25c4cd

diff --git a/wp-includes/abilities-api/class-wp-ability.php b/wp-includes/abilities-api/class-wp-ability.php
index 3e9dc2c18f..a778056118 100644
--- a/wp-includes/abilities-api/class-wp-ability.php
+++ b/wp-includes/abilities-api/class-wp-ability.php
@@ -936,15 +936,23 @@ class WP_Ability {
 	}

 	/**
-	 * Validates output data against the output schema.
+	 * Validates output data against the output schema after execution.
 	 *
 	 * @since 6.9.0
 	 * @since 7.1.0 Added the `wp_ability_validate_output` filter.
+	 * @since 7.3.0 Clarifies that execution completed when output validation fails.
 	 *
 	 * @param mixed $output The output data to validate.
 	 * @return true|WP_Error Returns true if valid, or a WP_Error object if validation fails.
 	 */
 	protected function validate_output( $output ) {
+		$annotations = $this->get_meta_item( 'annotations' );
+		$message     = is_array( $annotations ) && true === ( $annotations['readonly'] ?? null )
+			/* translators: 1: Ability name, 2: Output validation error. */
+			? __( 'Ability "%1$s" returned a result that failed validation. Reason: %2$s' )
+			/* translators: 1: Ability name, 2: Output validation error. */
+			: __( 'Ability "%1$s" ran, but its result failed validation. The requested action may already have taken effect. Check the outcome before retrying. Reason: %2$s' );
+
 		$output_schema = $this->get_output_schema();
 		if ( empty( $output_schema ) ) {
 			$is_valid = true;
@@ -952,10 +960,9 @@ class WP_Ability {
 			$valid_output = rest_validate_value_from_schema( $output, $output_schema, 'output' );
 			if ( is_wp_error( $valid_output ) ) {
 				$is_valid = new WP_Error(
-					'ability_invalid_output',
+					'ability_output_schema_mismatch',
 					sprintf(
-						/* translators: %1$s ability name, %2$s error message. */
-						__( 'Ability "%1$s" has invalid output. Reason: %2$s' ),
+						$message,
 						$this->name,
 						$valid_output->get_error_message()
 					)
@@ -974,6 +981,10 @@ class WP_Ability {
 		 * override it. If default validation passed, the filter can add additional
 		 * validation checks and return a WP_Error if those checks fail.
 		 *
+		 * Schema errors use the `ability_output_schema_mismatch` code and include execution context.
+		 * A filter returning false uses `ability_output_rejected`. For abilities that are not read-only,
+		 * both errors include retry guidance. Custom errors returned by the filter are passed through unchanged.
+		 *
 		 * @since 7.1.0
 		 *
 		 * @param true|WP_Error $is_valid     The validation result from default validation.
@@ -982,7 +993,10 @@ class WP_Ability {
 		 */
 		$validity = apply_filters( 'wp_ability_validate_output', $is_valid, $output, $this->name );
 		if ( false === $validity ) {
-			return new WP_Error( 'ability_invalid_output', __( 'Invalid output.' ) );
+			return new WP_Error(
+				'ability_output_rejected',
+				sprintf( $message, $this->name, __( 'Not specified.' ) )
+			);
 		}
 		if ( is_wp_error( $validity ) && $validity->has_errors() ) {
 			return $validity;
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 0e553b0686..fd4b11b5b8 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
  *
  * @global string $wp_version
  */
-$wp_version = '7.3-alpha-65877';
+$wp_version = '7.3-alpha-65878';

 /**
  * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.