$attributes * @return array */ public static function options(array $attributes): array { $color = sanitize_hex_color((string) ($attributes['markerColor'] ?? '#2457d6')) ?: '#2457d6'; $styles = array_column(MapSettings::styles(), 'id'); return [ 'zoom' => max(1, min(20, (float) ($attributes['zoom'] ?? 14))), 'height' => max(120, min(1200, (int) ($attributes['height'] ?? 320))), 'showMarker' => (bool) ($attributes['showMarker'] ?? true), 'markerColor' => $color, 'markerStyle' => ($attributes['markerStyle'] ?? '') === 'dot' ? 'dot' : 'pin', 'mapStyle' => in_array($attributes['mapStyle'] ?? '', $styles, true) ? $attributes['mapStyle'] : 'default', 'navigation' => (bool) ($attributes['navigation'] ?? true), 'scrollZoom' => (bool) ($attributes['scrollZoom'] ?? false), 'showAddress' => (bool) ($attributes['showAddress'] ?? true), 'showLink' => (bool) ($attributes['showLink'] ?? true), ]; } /** @param array $attributes */ public static function render(array $attributes, string $content, \WP_Block $block): string { unset($content); $id = absint($block->context['postId'] ?? $attributes['eventId'] ?? get_the_ID()); if (\ProCalendarWP\Events\EventVisibility::passwordRequired($id)) { return ''; } $parent = absint(get_post_meta($id, '_pcwp_series_id', true)); if ($parent > 0 && get_post($parent) !== null && get_post_status($parent) !== 'publish' && ! current_user_can('read_post', $parent)) { return ''; } if (get_post_type($id) !== 'pcwp_event' || ! (bool) get_post_meta($id, '_pcwp_show_map', true)) { return ''; } $location = Location::publicData($id); $options = self::options($attributes); $address = $location['formatted'] ?: implode(', ', array_filter([$location['line'], $location['city'], $location['region'], $location['postal_code'], $location['country']])); $valid = $location['latitude'] !== null && $location['longitude'] !== null; if (! $valid && $address === '') { return ''; } $html = '
'pcwp-event-map', 'style' => '--pcwp-map-height:' . $options['height'] . 'px', 'data-pcwp-map' => (string) wp_json_encode(['location' => $location, 'options' => $options])]) . '>'; if ($valid) { $html .= '
'; } if ($address !== '' && $options['showAddress']) { $html .= '

' . esc_html($address) . '

'; } if ($valid && $options['showLink']) { $url = 'https://www.openstreetmap.org/?mlat=' . $location['latitude'] . '&mlon=' . $location['longitude'] . '#map=' . $options['zoom'] . '/' . $location['latitude'] . '/' . $location['longitude']; $html .= '' . esc_html__('View map', 'proeventswp') . ''; } return $html . '
'; } }