Automattic\WooCommerce\Abilities

ExtensibleAbilities::matches_schema │ private static │ WC 1.0

Whether a value matches its field schema. A value other than null that does not match is logged and reported one time for each field.

Метод класса: ExtensibleAbilities{}

Хуков нет.

Возвращает

bool.

Использование

$result = ExtensibleAbilities::matches_schema( $args, $value ): bool;
$args(array<string, mixed>) (обязательный)
Field arguments.
$value(разное) (обязательный)
Value that the get_callback returned.

Код ExtensibleAbilities::matches_schema() WC 11.3.0

private static function matches_schema( array $args, $value ): bool {
	$valid = rest_validate_value_from_schema( $value, $args['schema'], $args['field'] );
	if ( true === $valid ) {
		return true;
	}

	$key = $args['resource'] . '.' . $args['namespace'] . '.' . $args['field'];
	if ( null === $value || isset( self::$reported[ $key ] ) ) {
		return false;
	}

	self::$reported[ $key ] = true;
	wc_get_logger()->error(
		sprintf( 'Ability field "%s.%s" of "%s" was left out because its value does not match its schema: %s', $args['namespace'], $args['field'], $args['resource'], $valid->get_error_message() ),
		array( 'source' => 'extensible-abilities' )
	);
	wc_doing_it_wrong(
		__CLASS__ . '::register_field',
		sprintf(
			/* translators: 1: extension namespace, 2: field name, 3: resource name, 4: validation error. */
			__( 'Ability field "%1$s.%2$s" of "%3$s" was left out because its value does not match its schema: %4$s', 'woocommerce' ),
			$args['namespace'],
			$args['field'],
			$args['resource'],
			$valid->get_error_message()
		),
		'11.3.0'
	);
	return false;
}