'string', 'default' => 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'sanitize_callback' => static function (mixed $value): string { if ($value === null) { return (string) get_option('pcwp_map_tile_url', 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'); } $value = sanitize_text_field((string) $value); return str_starts_with($value, 'https://') && str_contains($value, '{z}') && str_contains($value, '{x}') && str_contains($value, '{y}') ? $value : 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; }, ]); register_setting('pcwp_maps', 'pcwp_map_attribution', [ 'type' => 'string', 'default' => '© OpenStreetMap contributors', 'sanitize_callback' => static fn (mixed $value): string => $value === null ? (string) get_option('pcwp_map_attribution', '© OpenStreetMap contributors') : sanitize_text_field((string) $value), ]); register_setting('pcwp_maps', 'pcwp_geocoding_provider', ['sanitize_callback' => static fn (mixed $value): string => $value === 'geoapify' ? 'geoapify' : '']); register_setting('pcwp_maps', 'pcwp_geocoding_country', ['sanitize_callback' => static fn (mixed $value): string => preg_match('/^[a-z]{2}$/i', (string) $value) ? strtolower((string) $value) : '']); register_setting('pcwp_maps', 'pcwp_geocoding_key_input', ['sanitize_callback' => static function (mixed $value): string { if (! defined('PCWP_GEOCODING_API_KEY') && is_string($value) && trim($value) !== '') { GeocodingKey::set($value === '__remove__' ? '' : $value); } return ''; }]); register_setting('pcwp_maps', 'pcwp_map_styles', ['sanitize_callback' => [self::class, 'sanitizeStyles']]); } /** @return list */ public static function sanitizeStyles(mixed $value): array { $value = is_string($value) ? json_decode($value, true) : $value; $result = []; foreach (is_array($value) ? array_slice($value, 0, 20) : [] as $style) { if (! is_array($style)) { continue; } $url = (string) ($style['url'] ?? ''); $parts = wp_parse_url($url); $id = sanitize_key((string) ($style['id'] ?? '')); $attribution = sanitize_text_field((string) ($style['attribution'] ?? '')); $type = ($style['type'] ?? '') === 'vector' ? 'vector' : 'raster'; if ($id === '' || $id === 'default' || ! is_array($parts) || ($parts['scheme'] ?? '') !== 'https' || empty($parts['host']) || isset($parts['user']) || $attribution === '') { continue; } if ($type === 'raster' && (! str_contains($url, '{z}') || ! str_contains($url, '{x}') || ! str_contains($url, '{y}'))) { continue; } $result[$id] = ['id' => $id, 'label' => sanitize_text_field((string) ($style['label'] ?? $id)), 'type' => $type, 'url' => sanitize_text_field($url), 'attribution' => $attribution]; } return array_values($result); } /** @return list */ public static function styles(): array { return array_merge([[ 'id' => 'default', 'label' => __('Site default', 'proeventswp'), 'type' => 'raster', 'url' => (string) get_option('pcwp_map_tile_url', 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'), 'attribution' => (string) get_option('pcwp_map_attribution', '© OpenStreetMap contributors'), ]], self::sanitizeStyles(get_option('pcwp_map_styles', []))); } public static function render(): void { if (! current_user_can('manage_pcwp_events')) { return; } ?>

aria-describedby="pcwp-geocoding-help">