/* ─── CONFIG — un target per gestionale ──────────────────────────────────────
 * Ogni riga = { endpoint REST , segreto } di QUEL gestionale.
 * Endpoint e segreto li trovi in wp-admin → Operatività di ciascun sito.
 * --------------------------------------------------------------------------- */
if ( ! defined( 'OC_SYNC_TARGETS_JSON' ) ) {
	define( 'OC_SYNC_TARGETS_JSON', wp_json_encode( array(
		// PRODUZIONE
		array(
			'endpoint' => 'https://gestionale.kinsta.cloud/wp-json/oc/v1/sync',
			'secret'   => 'ONZsDaYUa78QvOLlQ9IAeKhPsYraLcO9d70s1m9b',
		),
		// STAGING (togli questa voce quando dismetti lo staging)
		array(
			'endpoint' => 'https://stg-gestionale-staging.kinsta.cloud/wp-json/oc/v1/sync',
			'secret'   => 'jtPzpw8jH5rfoQghydFS7K4VtwlVjZF9LSabNj9m',
		),
	) ) );
}

/* Stessi hook di cronos.php: registrati UNA volta, valgono per tutte le sedi. */
add_action( 'AmeliaAppointmentBookingAdded',         'oc_sync_ping_operativita', 20 );
add_action( 'AmeliaAppointmentBookingStatusUpdated', 'oc_sync_ping_operativita', 20 );
add_action( 'AmeliaAppointmentBookingCanceled',      'oc_sync_ping_operativita', 20 );

/**
 * Notifica NON bloccante a OGNI gestionale: "questa sede è cambiata, risincronizza".
 * Manda solo lo slug = path del blog corrente. Ogni gestionale farà il pull da Amelia.
 */
function oc_sync_ping_operativita() {
	if ( ! function_exists( 'get_blog_details' ) ) {
		return; // atteso multisite a sottocartella ({rete}/{slug}/)
	}
	$blog = get_blog_details();
	if ( ! is_object( $blog ) || empty( $blog->path ) ) {
		return;
	}
	$slug = trim( (string) $blog->path, '/' ); // es. 'base', 'treviso'
	if ( '' === $slug ) {
		return;
	}

	$targets = json_decode( OC_SYNC_TARGETS_JSON, true );
	if ( ! is_array( $targets ) ) {
		return;
	}

	foreach ( $targets as $t ) {
		if ( empty( $t['endpoint'] ) || empty( $t['secret'] )
			|| false !== strpos( $t['secret'], 'INCOLLA' ) ) {
			continue; // salta i target non ancora compilati
		}
		wp_remote_post( $t['endpoint'], array(
			'blocking' => false, // fire-and-forget: non rallenta Amelia
			'timeout'  => 1,
			'headers'  => array( 'X-OC-Secret' => $t['secret'] ),
			'body'     => array( 'sede' => $slug ),
		) );
	}
}
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//www.cronos.house/genova/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://www.cronos.house/genova/post-sitemap.xml</loc>
		<lastmod>2025-10-15T09:51:49+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://www.cronos.house/genova/page-sitemap.xml</loc>
		<lastmod>2026-03-16T14:40:08+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->