{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "landingPage": "/agenda/",
  "preferredVersions": {
    "php": "8.3",
    "wp": "latest"
  },
  "phpExtensionBundles": [
    "kitchen-sink"
  ],
  "features": {
    "networking": true
  },
  "steps": [
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "wordpress.org/plugins",
        "slug": "acs-agenda-manager"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "login"
    },
    {
      "step": "runPHP",
      "code": "<?php require_once '/wordpress/wp-load.php'; global $wpdb; $table = $wpdb->prefix . 'acs_agenda_manager'; $charset = $wpdb->get_charset_collate(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta(\"CREATE TABLE IF NOT EXISTS {$table} (id INT(11) NOT NULL AUTO_INCREMENT, categorie VARCHAR(120) NOT NULL, title VARCHAR(120) NOT NULL, emplacement VARCHAR(120) NOT NULL, image VARCHAR(255) NOT NULL, intro TEXT NOT NULL, link VARCHAR(255) NOT NULL, date VARCHAR(255) NOT NULL, price VARCHAR(60) DEFAULT NULL, account TINYINT(1) DEFAULT 1, candopartial TINYINT(1) DEFAULT 0, redirect VARCHAR(255) DEFAULT NULL, last_date_ts INT DEFAULT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), INDEX idx_date (date), INDEX idx_categorie (categorie), INDEX idx_last_date_ts (last_date_ts)) {$charset};\"); $count = (int) $wpdb->get_var(\"SELECT COUNT(*) FROM {$table}\"); $yoga_page = get_page_by_path('yoga-basics', OBJECT, 'page'); if (!$yoga_page) { $yoga_page_id = wp_insert_post(['post_title' => 'Yoga Basics', 'post_name' => 'yoga-basics', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => 'Yoga Basics is an introductory workshop focused on posture, breathing, and flexibility. Bring comfortable clothes and a yoga mat.']); $yoga_link = get_permalink($yoga_page_id); } else { $yoga_link = get_permalink($yoga_page); } $mind_page = get_page_by_path('mindfulness-practice', OBJECT, 'page'); if (!$mind_page) { $mind_page_id = wp_insert_post(['post_title' => 'Mindfulness Practice', 'post_name' => 'mindfulness-practice', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => 'Mindfulness Practice is a guided session to reduce stress and improve focus through breathing and gentle awareness exercises.']); $mind_link = get_permalink($mind_page_id); } else { $mind_link = get_permalink($mind_page); } $wpdb->update($table, ['link' => $yoga_link], ['title' => 'Yoga Basics', 'link' => ''], ['%s'], ['%s','%s']); $wpdb->update($table, ['link' => $mind_link], ['title' => 'Mindfulness Practice', 'link' => ''], ['%s'], ['%s','%s']); if ($count === 0) { $d1 = gmdate('d/m/y', strtotime('+5 days')); $d2 = gmdate('d/m/y', strtotime('+12 days')); $wpdb->insert($table, ['categorie' => 'Workshop', 'title' => 'Yoga Basics', 'emplacement' => 'Community Center', 'image' => '', 'intro' => 'Introduction class for all levels.', 'link' => $yoga_link, 'date' => $d1, 'price' => 'CHF 20.-', 'account' => 1, 'candopartial' => 0], ['%s','%s','%s','%s','%s','%s','%s','%s','%d','%d']); $wpdb->insert($table, ['categorie' => 'Course', 'title' => 'Mindfulness Practice', 'emplacement' => 'Studio Room B', 'image' => '', 'intro' => 'Weekly guided session focused on breathing and relaxation.', 'link' => $mind_link, 'date' => $d2, 'price' => 'CHF 35.-', 'account' => 1, 'candopartial' => 1], ['%s','%s','%s','%s','%s','%s','%s','%s','%d','%d']); } $agenda = get_page_by_path('agenda', OBJECT, 'page'); if (!$agenda) { wp_insert_post(['post_title' => 'Agenda', 'post_name' => 'agenda', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '[acsagma_agenda]', 'comment_status' => 'closed', 'ping_status' => 'closed']); } update_option('acsagma_page', 'Agenda');"
    },
    {
      "step": "runPHP",
      "code": "<?php require_once '/wordpress/wp-load.php'; $mu_dir = WPMU_PLUGIN_DIR; if (!is_dir($mu_dir)) { wp_mkdir_p($mu_dir); } $shim = <<<'SHIM'\n<?php\ndefined('ABSPATH') || exit;\nadd_action('init', function () {\n    if (!class_exists('ACSAGMA_Template')) {\n        return;\n    }\n    if (shortcode_exists('acsagma_agenda')) {\n        remove_shortcode('acsagma_agenda');\n    }\n    add_shortcode('acsagma_agenda', function () {\n        global $wpdb;\n        $table = $wpdb->prefix . 'acs_agenda_manager';\n        $rows = $wpdb->get_results('SELECT * FROM ' . $table . ' ORDER BY id ASC', ARRAY_A);\n        $events = [];\n        foreach ($rows as $row) {\n            $dates = array_values(array_filter(array_map('trim', explode(',', (string) ($row['date'] ?? '')))));\n            if (empty($dates)) {\n                continue;\n            }\n            $dates_info = [];\n            foreach ($dates as $date) {\n                $dates_info[] = ['date' => $date];\n            }\n            $events[] = [\n                'id' => (int) ($row['id'] ?? 0),\n                'categorie' => (string) ($row['categorie'] ?? ''),\n                'title' => (string) ($row['title'] ?? ''),\n                'emplacement' => (string) ($row['emplacement'] ?? ''),\n                'image' => (string) ($row['image'] ?? ''),\n                'intro' => (string) ($row['intro'] ?? ''),\n                'link' => (string) ($row['link'] ?? ''),\n                'dates' => $dates,\n                'dates_info' => $dates_info,\n                'price' => (string) ($row['price'] ?? ''),\n                'account' => (int) ($row['account'] ?? 1),\n                'candopartial' => (int) ($row['candopartial'] ?? 0),\n                'redirect' => (string) ($row['redirect'] ?? ''),\n                'status' => null,\n            ];\n        }\n        if (empty($events)) {\n            return '<p>No upcoming events.</p>';\n        }\n        return ACSAGMA_Template::render_agenda($events);\n    });\n}, 1000);\nSHIM; file_put_contents($mu_dir . '/acsagma-playground-preview-shim.php', $shim);"
    }
  ]
}
