RestAbility.php
38 lines
| 1 | <?php |
| 2 | /** |
| 3 | * REST Ability class file. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types=1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Abilities\REST; |
| 9 | |
| 10 | defined( 'ABSPATH' ) || exit; |
| 11 | |
| 12 | /** |
| 13 | * Custom WP_Ability subclass for REST API-based abilities. |
| 14 | * |
| 15 | * This class extends the base WP_Ability class but skips output validation |
| 16 | * to handle the discrepancies between WooCommerce REST API schemas and |
| 17 | * actual output. This is necessary because WooCommerce schemas are often |
| 18 | * incomplete or inaccurate regarding nullable fields and type variations. |
| 19 | */ |
| 20 | class RestAbility extends \WP_Ability { |
| 21 | |
| 22 | /** |
| 23 | * Skip output validation for REST abilities. |
| 24 | * |
| 25 | * WooCommerce REST API schemas often don't accurately reflect the actual |
| 26 | * output, particularly for nullable fields and type variations. Rather than |
| 27 | * trying to fix all schema inconsistencies, we skip output validation for |
| 28 | * REST-based abilities while maintaining input validation and permissions. |
| 29 | * |
| 30 | * @param mixed $output The output to validate. |
| 31 | * @return true Always returns true (no validation). |
| 32 | */ |
| 33 | protected function validate_output( $output ) { |
| 34 | // Skip validation - trust that REST controllers return valid data. |
| 35 | return true; |
| 36 | } |
| 37 | } |
| 38 |