Adattatori CMS

Guide all'integrazione: WordPress, qualsiasi sito, Next.js, Strapi

Inizia dalle opzioni senza codice. Il codice qui sotto è per i team che vogliono il pieno controllo.

Opzioni senza codice

  • WordPress: apri Integrazioni, inserisci l'indirizzo del sito e approva la connessione in WordPress. Gli articoli che pubblichi compaiono sul tuo sito con copertina, categorie e descrizione SEO.
  • Qualsiasi altro sito (HTML statico, Webflow, Wix e simili): attiva “Qualsiasi altro sito” in Integrazioni e incolla il frammento nella pagina del blog. Nessun server né spazio di archiviazione.

Tutti gli adattatori seguono lo stesso schema: verifica HMAC su article.ready, recupera l'articolo completo da Tenant API v1, poi upsert nel CMS. Le bozze sono disponibili subito. Decidi tu quando pubblicare.

Per sviluppatori: webhook e API

  1. Crea chiave API e URL webhook in Integrazioni GrowthDailySeo
  2. Esporre un endpoint POST e verificare X-GrowthDaily-Signature
  3. Su article.ready, GET /api/v1/sites/{siteId}/posts/{slug}
  4. Upsert di contentHtml, seo e faqJsonLd. Pubblica secondo il tuo calendario

Vedi anche: Webhook · Riferimento API

I webhook partono solo per nuove bozze. Pagina GET /posts una volta, poi updatedAfter. Come nella sezione backfill della reference API.

Adattatori per stack

Copia, adatta variabili d'ambiente e nomi tabelle, deploy.

La via più semplice: collega WordPress da Integrazioni, senza codice. Usa il codice del plugin qui sotto solo se vuoi gestire tu la sincronizzazione.

Variabili d'ambiente
# wp-config.php or server env
define('GROWTHDAILY_API_BASE', 'https://app.growthdailyseo.com');
define('GROWTHDAILY_API_KEY', 'fig_live_...');
define('GROWTHDAILY_WEBHOOK_SECRET', 'whsec_...');
define('GROWTHDAILY_SITE_ID', 'your-site-uuid');
// Tenant IndexNow — key file lives on YOUR WordPress domain (not GrowthDailySeo)
define('INDEXNOW_KEY', 'your-random-indexnow-key'); // also set in GrowthDailySeo niche_json.seo.indexnowKey
Endpoint webhook
<?php
// wp-content/mu-plugins/growthdaily-webhook.php
add_action('rest_api_init', function () {
  register_rest_route('growthdaily/v1', '/webhook', [
    'methods' => 'POST',
    'callback' => 'growthdaily_handle_webhook',
    'permission_callback' => '__return_true',
  ]);
});

function growthdaily_handle_webhook(WP_REST_Request $request) {
  $raw = $request->get_body();
  $ts = $request->get_header('x-growthdaily-timestamp') ?: $request->get_header('x-figrush-timestamp') ?: '';
  $sig = $request->get_header('x-growthdaily-signature') ?: $request->get_header('x-figrush-signature') ?: '';
  $expected = hash_hmac('sha256', $ts . '.' . $raw, GROWTHDAILY_WEBHOOK_SECRET);
  if (!hash_equals($expected, $sig)) {
    return new WP_Error('invalid_signature', 'Invalid signature', ['status' => 401]);
  }

  $event = json_decode($raw, true);
  if (($event['event'] ?? '') === 'article.ready') {
    growthdaily_sync_post($event['siteId'], $event['slug']);
    wp_remote_post(GROWTHDAILY_API_BASE . '/api/v1/sites/' . $event['siteId'] . '/posts/' . rawurlencode($event['slug']) . '/publish', [
      'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
      'timeout' => 15,
    ]);
  }
  return ['ok' => true];
}
Funzione di sync (fetch + upsert)
function growthdaily_sync_post(string $site_id, string $slug): void {
  $url = GROWTHDAILY_API_BASE . "/api/v1/sites/{$site_id}/posts/{$slug}";
  $response = wp_remote_get($url, [
    'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
    'timeout' => 30,
  ]);
  if (is_wp_error($response)) return;

  $post = json_decode(wp_remote_retrieve_body($response), true);
  if (empty($post['slug'])) return;

  $existing = get_page_by_path($post['slug'], OBJECT, 'post');
  $post_id = wp_insert_post([
    'ID' => $existing ? $existing->ID : 0,
    'post_title' => $post['title'],
    'post_excerpt' => $post['excerpt'] ?? '',
    'post_content' => $post['contentHtml'],
    'post_status' => ($post['status'] ?? 'draft') === 'published' ? 'publish' : 'draft',
    'post_name' => $post['slug'],
  ]);

  if (!empty($post['seo']['ogTitle'])) {
    update_post_meta($post_id, '_yoast_wpseo_title', $post['seo']['ogTitle']);
  }
  if (!empty($post['seo']['metaDescription'])) {
    update_post_meta($post_id, '_yoast_wpseo_metadesc', $post['seo']['metaDescription']);
  }
  if (!empty($post['faqJsonLd'])) {
    update_post_meta($post_id, '_growthdaily_faq_jsonld', wp_json_encode($post['faqJsonLd']));
  }
  if (!empty($post['schemaBundle'])) {
    update_post_meta($post_id, '_growthdaily_schema_bundle', wp_json_encode($post['schemaBundle']));
  }
}
Rendering / recupero dati
// Point webhook URL in GrowthDailySeo Integrations to:
// https://your-site.com/wp-json/growthdaily/v1/webhook

// Theme template — output Article + Breadcrumb + FAQ JSON-LD
function growthdaily_render_schema_bundle(int $post_id): void {
  $raw = get_post_meta($post_id, '_growthdaily_schema_bundle', true);
  if (!$raw) return;
  $bundle = json_decode($raw, true);
  if (!is_array($bundle)) return;
  foreach (['article', 'breadcrumb', 'faq'] as $key) {
    if (empty($bundle[$key])) continue;
    echo '<script type="application/ld+json">' . wp_json_encode($bundle[$key]) . '</script>';
  }
}
add_action('wp_head', function () {
  if (is_singular('post')) growthdaily_render_schema_bundle(get_the_ID());
});

// Optional: nightly backfill for missed webhooks
add_action('growthdaily_daily_sync', function () {
  $url = GROWTHDAILY_API_BASE . '/api/v1/sites/' . GROWTHDAILY_SITE_ID . '/posts?pageSize=50';
  $response = wp_remote_get($url, [
    'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
  ]);
  $items = json_decode(wp_remote_retrieve_body($response), true)['items'] ?? [];
  foreach ($items as $item) {
    growthdaily_sync_post(GROWTHDAILY_SITE_ID, $item['slug']);
  }
});
  if (!wp_next_scheduled('growthdaily_daily_sync')) {
  wp_schedule_event(time(), 'daily', 'growthdaily_daily_sync');
}
Pagine generate e llms.txt
// Fetch a generated page spec (path without leading slash)
function growthdaily_fetch_page($path) {
  $encoded = rawurlencode(ltrim($path, '/'));
  $url = GROWTHDAILY_API_BASE . '/api/v1/sites/' . GROWTHDAILY_SITE_ID . '/pages/' . $encoded;
  $response = wp_remote_get($url, [
    'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
  ]);
  return json_decode(wp_remote_retrieve_body($response), true);
}

// Proxy llms.txt onto your domain
function growthdaily_llms_txt(): string {
  $url = GROWTHDAILY_API_BASE . '/api/v1/sites/' . GROWTHDAILY_SITE_ID . '/llms.txt';
  $response = wp_remote_get($url, [
    'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
    'timeout' => 20,
  ]);
  return is_wp_error($response) ? '' : wp_remote_retrieve_body($response);
}
Feed della sitemap
// Dynamic sitemap feed
function growthdaily_fetch_sitemap(): string {
  $url = GROWTHDAILY_API_BASE . '/api/v1/sites/' . GROWTHDAILY_SITE_ID . '/sitemap.xml';
  $response = wp_remote_get($url, [
    'headers' => ['Authorization' => 'Bearer ' . GROWTHDAILY_API_KEY],
    'timeout' => 30,
  ]);
  return is_wp_error($response) ? '' : wp_remote_retrieve_body($response);
}

// Rewrite rule or template_redirect to serve XML at /sitemap-growthdaily.xml
Ping IndexNow
// Upload {INDEXNOW_KEY}.txt to WordPress web root (ABSPATH) — content = key string
// e.g. https://www.your-domain.com/a1b2c3.txt contains "a1b2c3"
function growthdaily_indexnow_ping(string $url): void {
  if (!defined('INDEXNOW_KEY')) return;
  wp_remote_post('https://api.indexnow.org/indexnow', [
    'headers' => ['Content-Type' => 'application/json'],
    'body' => wp_json_encode([
      'host' => wp_parse_url(home_url(), PHP_URL_HOST),
      'key' => INDEXNOW_KEY,
      'keyLocation' => home_url('/' . INDEXNOW_KEY . '.txt'),
      'urlList' => [$url],
    ]),
  ]);
}