用途:快速创建一次性的 WordPress 环境,用于测试插件或主题、运行和迭代 Playground Blueprint(JSON)、制作可复现的共享快照、快速切换 WordPress/PHP 版本复现问题,以及在隔离环境中用 Xdebug 调试代码。需要 Node.js 20.18+(用 node -v 检查)、要挂载的项目路径,可选指定 WP/PHP 版本、Blueprint 位置和端口(默认 9400)。
主要用法:本地快速启动可进入插件或主题目录后执行 npx @wp-playground/cli@latest server --auto-mount,默认打开 http://localhost:9400 并自动识别安装插件/主题;可用 --wp=6.9、--php=8.2、--port=9500 指定版本和端口。复杂挂载使用 --mount=/path/to/plugin:/wordpress/wp-content/plugins/my-plugin 这类绝对路径参数。运行 Blueprint 用 npx @wp-playground/cli@latest run-blueprint --blueprint=./my-blueprint.json,也可传入 URL;Blueprint 可在 landingPage、preferredVersions、steps 中定义登录、安装插件、激活插件等步骤。构建快照用 build-snapshot --blueprint=./setup.json --outfile=./my-site.zip。调试用 --xdebug 并在 IDE 中连接输出端口。纯浏览器方式可用 https://playground.wordpress.net/ 或带 ?blueprint-url=YOUR_JSON_URL,站点内提供 Blueprint 编辑器。
限制与排错:Playground 基于 WebAssembly 和 SQLite,没有 MySQL,部分 PHP 扩展可能不可用,不适合生产数据;需要 PHP 扩展或原生数据库访问时应改用 wp-env、Docker 或 Local。Node 版本过低会报错需升级;挂载未生效应使用绝对路径并加 --verbosity=debug;Blueprint 读取本地资源需加 --blueprint-may-read-adjacent-files;端口占用可用 --port=9500 更换;界面缓慢或锁定时可尝试调整 --experimental-multi-worker。