WP_Ability::validate_output( mixed $output ): true|WP_Error

In this article

Validates output data against the output schema.

Parameters

$outputmixedrequired
The output data to validate.

Return

true|WP_Error Returns true if valid, or a WP_Error object if validation fails.

Source

protected function validate_output( $output ) {
	$output_schema = $this->get_output_schema();
	if ( empty( $output_schema ) ) {
		return true;
	}

	$valid_output = rest_validate_value_from_schema( $output, $output_schema, 'output' );
	if ( is_wp_error( $valid_output ) ) {
		return new WP_Error(
			'ability_invalid_output',
			sprintf(
				/* translators: %1$s ability name, %2$s error message. */
				__( 'Ability "%1$s" has invalid output. Reason: %2$s' ),
				esc_html( $this->name ),
				$valid_output->get_error_message()
			)
		);
	}

	return true;
}

Changelog

VersionDescription
6.9.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.