ACF_Rest_Api::validate_rest_arg()publicACF 1.0

fires off a filter, so we can add some custom validation for specific fields.

This will likely no longer be needed once WordPress implements something like validate_callback and sanitize_callback for nested schema properties, see: https://core.trac.wordpress.org/ticket/49960

{} Это метод класса: ACF_Rest_Api{}

Хуки из метода

Возвращает

true|false|WP_Error.

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

$ACF_Rest_Api = new ACF_Rest_Api();
$ACF_Rest_Api->validate_rest_arg( $value, $request, $param );
$value(разное) (обязательный)
-
$request(\WP_REST_Request) (обязательный)
-
$param(строка) (обязательный)
-

Код ACF_Rest_Api::validate_rest_arg() ACF 6.0.4

public function validate_rest_arg( $value, $request, $param ) {
	// Validate all fields with default WordPress validation first.
	$valid = rest_validate_request_arg( $value, $request, $param );

	if ( true !== $valid ) {
		return $valid;
	}

	foreach ( $value as $field_name => $field_value ) {
		$field = acf_get_field( $field_name );

		if ( ! $field ) {
			continue;
		}

		/**
		 * Filters whether a value passed via REST is valid.
		 *
		 * @since   5.11
		 *
		 * @param bool  $valid True if the value is valid, false or WP_Error if not.
		 * @param mixed $value The value to check.
		 * @param array $field An array of information about the field.
		 */
		$valid = apply_filters( 'acf/validate_rest_value/type=' . $field['type'], true, $field_value, $field );

		if ( true !== $valid ) {
			return $valid;
		}
	}

	return true;
}