'',
'id' => '',
'limit' => '',
], $atts, 'yogasoul_eventi');
wp_enqueue_style('yse-eventi');
wp_enqueue_script('yse-eventi');
// Costruisce l'URL dell'endpoint lista
$query = [];
if ($atts['id'] !== '') {
$query['id'] = (int) $atts['id'];
}
if ($atts['ids'] !== '') {
$clean = preg_replace('/[^0-9,]/', '', $atts['ids']);
if ($clean !== '') {
$query['ids'] = $clean;
}
}
if ($atts['limit'] !== '') {
$query['limit'] = (int) $atts['limit'];
}
$url = YSE_API_BASE . '/events.php' . (!empty($query) ? '?' . http_build_query($query) : '');
// Lettura server-side (niente CORS) + anti-cache
$resp = wp_remote_get($url . (strpos($url, '?') !== false ? '&' : '?') . '_=' . time(), [
'timeout' => 8,
'headers' => ['Cache-Control' => 'no-cache'],
]);
if (is_wp_error($resp) || (int) wp_remote_retrieve_response_code($resp) !== 200) {
return '
';
}
$data = json_decode(wp_remote_retrieve_body($resp), true);
if (!is_array($data) || empty($data['ok'])) {
return '';
}
if (empty($data['events'])) {
return '';
}
$out = '';
foreach ($data['events'] as $ev) {
$out .= yse_render_card($ev);
}
$out .= '
';
return $out;
}
/* Icona SVG inline (stroke = currentColor) */
function yse_icon($name)
{
$p = [
'user' => '',
'pin' => '',
'clock' => '',
'heart' => '',
'bag' => '',
'info' => '',
'img' => '',
'chev' => '',
];
$inner = $p[$name] ?? '';
return '';
}
/* Rende una singola card evento */
function yse_render_card($ev)
{
$mesiAbbr = [1 => 'GEN', 2 => 'FEB', 3 => 'MAR', 4 => 'APR', 5 => 'MAG', 6 => 'GIU', 7 => 'LUG', 8 => 'AGO', 9 => 'SET', 10 => 'OTT', 11 => 'NOV', 12 => 'DIC'];
$mesi = [1 => 'gennaio', 2 => 'febbraio', 3 => 'marzo', 4 => 'aprile', 5 => 'maggio', 6 => 'giugno', 7 => 'luglio', 8 => 'agosto', 9 => 'settembre', 10 => 'ottobre', 11 => 'novembre', 12 => 'dicembre'];
$id = (int) $ev['id'];
$cost = (float) $ev['cost'];
$sym = (string) $ev['currency_symbol'];
$price = $cost > 0 ? $sym . number_format($cost, 2, ',', '.') : 'Gratuito';
$color = (isset($ev['color']) && preg_match('/^#[0-9a-fA-F]{6}$/', $ev['color'])) ? $ev['color'] : '#4CAF50';
$soldOut = !empty($ev['sold_out']);
$waitOn = !empty($ev['waitlist_enabled']);
$waitMode = $soldOut && $waitOn;
$hardFull = $soldOut && !$waitOn;
$maxPer = max(1, (int) $ev['max_per_booking']);
$remaining = (int) $ev['remaining'];
$maxQty = $soldOut ? ($waitMode ? $maxPer : 0) : max(1, min($maxPer, $remaining));
$startTs = strtotime($ev['starts_at']);
$dayNum = (int) date('j', $startTs);
$monAbbr = $mesiAbbr[(int) date('n', $startTs)];
$dateLong = $dayNum . ' ' . $mesi[(int) date('n', $startTs)] . ' ' . date('Y', $startTs);
$timeLabel = date('H:i', $startTs) . (!empty($ev['ends_at']) ? '–' . date('H:i', strtotime($ev['ends_at'])) : '');
$address = trim((string) ($ev['address'] ?? ''));
$organizer = trim((string) ($ev['organizer'] ?? ''));
$mapQuery = $address !== '' ? $address : ((isset($ev['lat'], $ev['lng']) && $ev['lat'] && $ev['lng']) ? ($ev['lat'] . ',' . $ev['lng']) : '');
$gallery = is_array($ev['gallery'] ?? null) ? $ev['gallery'] : [];
$hasDetails = trim((string) ($ev['description'] ?? '')) !== ''
|| trim((string) ($ev['suitable_for'] ?? '')) !== ''
|| trim((string) ($ev['what_to_bring'] ?? '')) !== ''
|| trim((string) ($ev['instructions'] ?? '')) !== ''
|| !empty($ev['cover_image']) || !empty($gallery) || $mapQuery !== '';
ob_start();
?>
Prenotazioni aperte dal
Evento esaurito — non ci sono più posti disponibili.
0
? ' Al momento ' . ($waitingCount === 1 ? "c'è 1 persona" : "ci sono {$waitingCount} persone") . ' in coda.'
: '';
?>
Posti esauriti — puoi iscriverti alla lista d'attesa: ti avviseremo se si libera un posto.