$path * @return mixed[] */ private static function sanitizeValues(array $data, bool $rich_text, array $path): array { $sanitized = []; foreach ($data as $key => $value) { if (is_array($value)) { $sanitized[$key] = self::sanitizeValues($value, $rich_text || $key === 'collections', array_merge($path, [$key])); } else if (is_string($value)) { // Passwords and encoded JSON must retain their original syntax. // Their consumers validate and sanitize the decoded/typed values. if ($key === 'password' || $key === 'json') { $sanitized[$key] = wp_check_invalid_utf8($value); } else if ($rich_text || in_array($key, ['content', 'description', 'body'], true) || (count($path) === 2 && $path[0] === 'gateways' && in_array($key, ['comment', 'appreciation'], true))) { $sanitized[$key] = wp_kses_post($value); } else { $sanitized[$key] = wp_strip_all_tags(wp_check_invalid_utf8($value)); } } else if (is_int($value) || is_float($value) || is_bool($value) || $value === null) { $sanitized[$key] = $value; } } return $sanitized; } }