{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "landingPage": "/wp-admin/admin.php?page=wp-google-maps-menu&action=welcome_page",
  "preferredVersions": {
    "php": "8.2",
    "wp": "latest"
  },
  "phpExtensionBundles": [
    "kitchen-sink"
  ],
  "steps": [
    {
      "step": "login",
      "username": "admin",
      "password": "password"
    },
    {
      "step": "mkdir",
      "path": "/wordpress/wp-content/mu-plugins"
    },
    {
      "step": "writeFile",
      "path": "/wordpress/wp-content/mu-plugins/wpgmza-sqlite-spatial-shim.php",
      "data": "<?php\n/**\n * Plugin Name: WP Go Maps - SQLite Spatial Shim (Playground)\n *\n * Registers PHP-backed shims for the MySQL spatial functions WP Go Maps\n * uses, on the SQLite PDO connection. Active ONLY when the SQLite\n * Database Integration is detected. No-ops on real MySQL installs.\n *\n * DIAGNOSTIC version — writes to error_log at every step so we can see\n * in the WordPress error log exactly where the registration succeeds\n * or fails. Once the shim is confirmed working, the WPGMZA_SHIM_LOG\n * calls can be removed.\n */\n\nif (!defined('ABSPATH')) exit;\n\n// Confirm the file is being included at all. If this line never appears\n// in the error log, the mu-plugin file isn't being loaded by WordPress.\nerror_log('[WPGMZA-SHIM] mu-plugin file included');\n\n// Hook on multiple actions so we catch the connection regardless of\n// when it becomes available.\nadd_action('muplugins_loaded', 'wpgmza_sqlite_spatial_shim_try', 5);\nadd_action('plugins_loaded',   'wpgmza_sqlite_spatial_shim_try', 0);\nadd_action('init',             'wpgmza_sqlite_spatial_shim_try', 0);\n\nfunction wpgmza_sqlite_spatial_shim_try() {\n    static $done = false;\n    if ($done) return;\n\n    global $wpdb;\n    $hook = current_action();\n\n    error_log('[WPGMZA-SHIM] try() fired on hook: ' . $hook);\n    error_log('[WPGMZA-SHIM] wpdb class: ' . (is_object($wpdb) ? get_class($wpdb) : 'NOT-OBJECT'));\n    error_log('[WPGMZA-SHIM] WP_SQLite_DB class_exists: ' . (class_exists('WP_SQLite_DB') ? 'yes' : 'no'));\n    error_log('[WPGMZA-SHIM] $GLOBALS[@pdo] type: ' . (isset($GLOBALS['@pdo']) ? (is_object($GLOBALS['@pdo']) ? get_class($GLOBALS['@pdo']) : gettype($GLOBALS['@pdo'])) : 'NOT-SET'));\n\n    if (!class_exists('WP_SQLite_DB')) {\n        error_log('[WPGMZA-SHIM] bail: WP_SQLite_DB does not exist');\n        return;\n    }\n    if (!($wpdb instanceof WP_SQLite_DB)) {\n        error_log('[WPGMZA-SHIM] bail: wpdb is not WP_SQLite_DB');\n        return;\n    }\n\n    $pdo = wpgmza_sqlite_spatial_get_pdo();\n    if (!($pdo instanceof PDO)) {\n        error_log('[WPGMZA-SHIM] PDO probe returned null on ' . $hook . ' — will retry on later hook');\n        return;\n    }\n\n    error_log('[WPGMZA-SHIM] got PDO instance: ' . get_class($pdo) . ' — registering functions');\n\n    $identity = function ($value) { return $value; };\n    $extractX = function ($wkt) { return wpgmza_sqlite_spatial_point_xy($wkt, 0); };\n    $extractY = function ($wkt) { return wpgmza_sqlite_spatial_point_xy($wkt, 1); };\n\n    $registered = 0;\n    $failed = 0;\n\n    $identityFunctions = array(\n        'AsText', 'ST_AsText',\n        'GeomFromText', 'ST_GeomFromText',\n        'PointFromText', 'ST_PointFromText',\n    );\n\n    foreach ($identityFunctions as $fn) {\n        try {\n            $pdo->sqliteCreateFunction($fn, $identity, 1);\n            $registered++;\n        } catch (\\Throwable $e) {\n            $failed++;\n            error_log('[WPGMZA-SHIM] sqliteCreateFunction ' . $fn . ' failed: ' . $e->getMessage());\n        }\n    }\n    foreach (array('X', 'ST_X') as $fn) {\n        try {\n            $pdo->sqliteCreateFunction($fn, $extractX, 1);\n            $registered++;\n        } catch (\\Throwable $e) {\n            $failed++;\n            error_log('[WPGMZA-SHIM] sqliteCreateFunction ' . $fn . ' failed: ' . $e->getMessage());\n        }\n    }\n    foreach (array('Y', 'ST_Y') as $fn) {\n        try {\n            $pdo->sqliteCreateFunction($fn, $extractY, 1);\n            $registered++;\n        } catch (\\Throwable $e) {\n            $failed++;\n            error_log('[WPGMZA-SHIM] sqliteCreateFunction ' . $fn . ' failed: ' . $e->getMessage());\n        }\n    }\n\n    error_log('[WPGMZA-SHIM] registration complete: ' . $registered . ' functions registered, ' . $failed . ' failed');\n    $done = true;\n}\n\nfunction wpgmza_sqlite_spatial_get_pdo() {\n    global $wpdb;\n\n    // Path A: global set by WP_SQLite_DB::db_connect()\n    if (isset($GLOBALS['@pdo']) && $GLOBALS['@pdo'] instanceof PDO) {\n        error_log('[WPGMZA-SHIM] PDO found via $GLOBALS[@pdo]');\n        return $GLOBALS['@pdo'];\n    }\n\n    // Path B: public method chain on the SQLite driver\n    if (isset($wpdb->dbh) && is_object($wpdb->dbh)) {\n        error_log('[WPGMZA-SHIM] $wpdb->dbh class: ' . get_class($wpdb->dbh));\n        error_log('[WPGMZA-SHIM] $wpdb->dbh methods: ' . implode(',', get_class_methods($wpdb->dbh)));\n\n        if (method_exists($wpdb->dbh, 'get_connection')) {\n            $connection = $wpdb->dbh->get_connection();\n            if (is_object($connection)) {\n                error_log('[WPGMZA-SHIM] connection class: ' . get_class($connection));\n                error_log('[WPGMZA-SHIM] connection methods: ' . implode(',', get_class_methods($connection)));\n\n                if (method_exists($connection, 'get_pdo')) {\n                    $pdo = $connection->get_pdo();\n                    if ($pdo instanceof PDO) {\n                        error_log('[WPGMZA-SHIM] PDO found via get_connection()->get_pdo()');\n                        return $pdo;\n                    }\n                }\n            }\n        }\n    }\n\n    return null;\n}\n\nfunction wpgmza_sqlite_spatial_point_xy($wkt, $index) {\n    if (!is_string($wkt)) return 0.0;\n    if (preg_match('/POINT\\s*\\(\\s*([\\-\\d\\.eE+]+)\\s+([\\-\\d\\.eE+]+)\\s*\\)/i', $wkt, $m)) {\n        return (float) $m[$index + 1];\n    }\n    return 0.0;\n}\n"
    },
    {
      "step": "installPlugin",
      "pluginZipFile": {
        "resource": "wordpress.org/plugins",
        "slug": "wp-google-maps"
      },
      "options": {
        "activate": true
      }
    }
  ]
}
