Automattic\WooCommerce\Internal\Abilities\REST

RestAbility{} │ WC 1.0

Deprecated since 11.3.0 Removed along with the WooCommerce MCP endpoint's REST-derived abilities. Still works, but reports incorrect usage.. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Custom WP_Ability subclass for REST API-based abilities.

This class extends the base WP_Ability class but skips output validation to handle the discrepancies between WooCommerce REST API schemas and actual output. This is necessary because WooCommerce schemas are often incomplete or inaccurate regarding nullable fields and type variations.

No Hooks.

Usage

$RestAbility = new RestAbility();
// use class methods

Methods

  1. public __construct( string $name, array $args )
  2. protected validate_output( $output )

Changelog

Deprecated since 11.3.0 Removed along with the WooCommerce MCP endpoint's REST-derived abilities. Still works, but reports incorrect usage.

RestAbility{} code WC 11.3.0

class RestAbility extends \WP_Ability {

	/**
	 * Constructor.
	 *
	 * @param string $name The ability name.
	 * @param array  $args The ability arguments.
	 */
	public function __construct( string $name, array $args ) {
		McpEndpointRemoval::doing_it_wrong( __CLASS__ );
		parent::__construct( $name, $args );
	}

	/**
	 * Skip output validation for REST abilities.
	 *
	 * WooCommerce REST API schemas often don't accurately reflect the actual
	 * output, particularly for nullable fields and type variations. Rather than
	 * trying to fix all schema inconsistencies, we skip output validation for
	 * REST-based abilities while maintaining input validation and permissions.
	 *
	 * @param mixed $output The output to validate.
	 * @return true Always returns true (no validation).
	 */
	protected function validate_output( $output ) {
		// Skip validation - trust that REST controllers return valid data.
		return true;
	}
}