blueprint
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWordPress Playground Blueprints
WordPress Playground Blueprint 指南
Overview
概述
A Blueprint is a JSON file that declaratively configures a WordPress Playground instance — installing plugins/themes, setting options, running PHP/SQL, manipulating files, and more.
Core principle: Blueprints are trusted JSON-only declarations. No arbitrary JavaScript. They work on web, Node.js, and CLI.
Blueprint是一种JSON文件,用于声明式配置WordPress Playground实例——包括安装插件/主题、设置选项、运行PHP/SQL、操作文件等。
核心原则:Blueprint是仅受信任的JSON声明,不支持任意JavaScript。可在Web、Node.js和CLI环境中使用。
Quick Start Template
快速入门模板
json
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/",
"preferredVersions": { "php": "8.3", "wp": "latest" },
"steps": [{ "step": "login" }]
}json
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/",
"preferredVersions": { "php": "8.3", "wp": "latest" },
"steps": [{ "step": "login" }]
}Top-Level Properties
顶层属性
All optional. Only documented keys are allowed — the schema rejects unknown properties.
| Property | Type | Notes |
|---|---|---|
| string | Always |
| string | Relative path, e.g. |
| object | |
| object | |
| object | |
| array | |
| object | Shorthand for |
| array | Shorthand for |
| object | Shorthand for |
| boolean or object | |
| array | Main execution pipeline. Runs after shorthands |
所有属性均为可选。仅允许使用文档中记录的键——Schema会拒绝未知属性。
| 属性 | 类型 | 说明 |
|---|---|---|
| 字符串 | 固定为 |
| 字符串 | 相对路径,例如 |
| 对象 | |
| 对象 | |
| 对象 | |
| 数组 | |
| 对象 | |
| 数组 | |
| 对象 | |
| 布尔值或对象 | |
| 数组 | 主执行流程。在简写配置之后运行 |
preferredVersions Values
preferredVersions 取值说明
- php: Major.minor only (e.g. ,
"8.3"), or"7.4". Patch versions like"latest"are invalid. Check the schema for currently supported versions."7.4.1" - wp: Recent major versions (e.g. ,
"6.7"),"6.8","latest","nightly", or a URL to a custom zip. Check the schema for the full list."beta"
- php:仅支持主版本.次版本格式(例如,
"8.3"),或"7.4"。类似"latest"的补丁版本无效。请查看Schema获取当前支持的版本列表。"7.4.1" - wp:支持近期主版本(例如,
"6.7")、"6.8"、"latest"、"nightly",或自定义压缩包的URL。请查看Schema获取完整列表。"beta"
Shorthands vs Steps
简写配置 vs 步骤
Shorthands (, , , ) are expanded and prepended to in an unspecified order. Use explicit steps when execution order matters.
loginpluginssiteOptionsconstantssteps简写配置(, , , )会被展开并前置到中,顺序不固定。当执行顺序重要时,请使用显式步骤。
loginpluginssiteOptionsconstantsstepsResource References
资源引用
Resources tell Playground where to find files. Used by , , , , , etc.
installPlugininstallThemewriteFilewriteFilesimportWxr| Resource Type | Required Fields | Example |
|---|---|---|
| | |
| | |
| | |
| | See below |
| | |
| | See below |
| | References a file within a blueprint bundle (e.g. |
| | Wraps another resource in a ZIP — use when a step expects a zip but your source isn't one (e.g. wrapping a |
资源用于告知Playground文件的位置。适用于、、、、等步骤。
installPlugininstallThemewriteFilewriteFilesimportWxr| 资源类型 | 必填字段 | 示例 |
|---|---|---|
| | |
| | |
| | |
| | 见下文 |
| | |
| | 见下文 |
| | 引用Blueprint包内的文件(例如 |
| | 将其他资源包装为ZIP格式——当步骤需要ZIP文件但源资源不是ZIP时使用(例如包装指向原始目录的 |
git:directory — Installing from GitHub
git:directory —— 从GitHub安装
json
{
"resource": "git:directory",
"url": "https://github.com/WordPress/gutenberg",
"ref": "trunk",
"refType": "branch",
"path": "/"
}- When using a branch or tag name for , you must set
ref(refType|"branch"|"tag"|"commit"). Without it, only"refname"resolves reliably."HEAD" - selects a subdirectory (defaults to repo root).
path
json
{
"resource": "git:directory",
"url": "https://github.com/WordPress/gutenberg",
"ref": "trunk",
"refType": "branch",
"path": "/"
}- 当使用分支或标签名称作为时,必须设置
ref(refType|"branch"|"tag"|"commit")。如果不设置,仅"refname"能可靠解析。"HEAD" - 用于选择子目录(默认为仓库根目录)。
path
literal:directory — Inline File Trees
literal:directory —— 内联文件树
json
{
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"plugin.php": "<?php /* Plugin Name: My Plugin */ ?>",
"includes": {
"helper.php": "<?php // helper code ?>"
}
}
}- uses nested objects for subdirectories — keys are filenames or directory names, values are plain strings (file content) or objects (subdirectories). Never use resource references as values.
files - Do NOT use path separators in keys (e.g. is wrong — use a nested
"includes/helper.php"object)."includes": { "helper.php": "..." }
json
{
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"plugin.php": "<?php /* Plugin Name: My Plugin */ ?>",
"includes": {
"helper.php": "<?php // helper code ?>"
}
}
}- 使用嵌套对象表示子目录——键为文件名或目录名,值为纯字符串(文件内容)或对象(子目录)。请勿将资源引用作为值。
files - 请勿在键中使用路径分隔符(例如是错误的——应使用嵌套的
"includes/helper.php"对象)。"includes": { "helper.php": "..." }
Steps Reference
步骤参考
Every step requires . Any step can optionally include for UI feedback.
"step": "<name>""progress": { "weight": 1, "caption": "Installing..." }每个步骤都需要。任意步骤都可选择性包含以提供UI反馈。
"step": "<name>""progress": { "weight": 1, "caption": "Installing..." }Plugin & Theme Installation
插件与主题安装
json
{
"step": "installPlugin",
"pluginData": { "resource": "wordpress.org/plugins", "slug": "gutenberg" },
"options": { "activate": true, "targetFolderName": "gutenberg" },
"ifAlreadyInstalled": "overwrite"
}json
{
"step": "installTheme",
"themeData": { "resource": "wordpress.org/themes", "slug": "twentytwentyfour" },
"options": { "activate": true, "importStarterContent": true },
"ifAlreadyInstalled": "overwrite"
}- Use /
pluginData— NOT the deprecatedthemeData/pluginZipFile.themeZipFile - /
pluginDataaccept any FileReference or DirectoryReference — a zip URL, athemeDataslug, awordpress.org/plugins, or agit:directory(noliteral:directorywrapper needed).zip - controls activation. No need for a separate
options.activate/activatePluginstep when usingactivateTheme/installPlugin.installTheme - :
ifAlreadyInstalled|"overwrite"|"skip""error"
json
{
"step": "installPlugin",
"pluginData": { "resource": "wordpress.org/plugins", "slug": "gutenberg" },
"options": { "activate": true, "targetFolderName": "gutenberg" },
"ifAlreadyInstalled": "overwrite"
}json
{
"step": "installTheme",
"themeData": { "resource": "wordpress.org/themes", "slug": "twentytwentyfour" },
"options": { "activate": true, "importStarterContent": true },
"ifAlreadyInstalled": "overwrite"
}- 使用/
pluginData——不要使用已弃用的themeData/pluginZipFile。themeZipFile - /
pluginData支持任意FileReference或DirectoryReference——包括ZIP URL、themeData别名、wordpress.org/plugins或git:directory(无需literal:directory包装)。zip - 控制激活状态。使用
options.activate/installPlugin时,无需单独的installTheme/activatePlugin步骤。activateTheme - 可选值:
ifAlreadyInstalled|"overwrite"|"skip""error"
Activation (standalone)
单独激活
Only needed for plugins/themes already on disk (e.g. after /):
writeFilewriteFilesjson
{ "step": "activatePlugin", "pluginPath": "my-plugin/my-plugin.php" }json
{ "step": "activateTheme", "themeFolderName": "twentytwentyfour" }仅适用于已存在于磁盘中的插件/主题(例如/之后):
writeFilewriteFilesjson
{ "step": "activatePlugin", "pluginPath": "my-plugin/my-plugin.php" }json
{ "step": "activateTheme", "themeFolderName": "twentytwentyfour" }File Operations
文件操作
json
{ "step": "writeFile", "path": "/wordpress/wp-content/mu-plugins/custom.php", "data": "<?php // code" }data{ "resource": "url", "url": "https://..." }json
{
"step": "writeFiles",
"writeToPath": "/wordpress/wp-content/plugins/",
"filesTree": {
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"plugin.php": "<?php\n/*\nPlugin Name: My Plugin\n*/",
"includes": {
"helpers.php": "<?php // helpers"
}
}
}
}writeFilesliteral:directorygit:directoryfilesTreeOther file operations: , , , , , .
mkdircpmvrmrmdirunzipjson
{ "step": "writeFile", "path": "/wordpress/wp-content/mu-plugins/custom.php", "data": "<?php // code" }data{ "resource": "url", "url": "https://..." }json
{
"step": "writeFiles",
"writeToPath": "/wordpress/wp-content/plugins/",
"filesTree": {
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"plugin.php": "<?php\n/*\nPlugin Name: My Plugin\n*/",
"includes": {
"helpers.php": "<?php // helpers"
}
}
}
}writeFilesfilesTreeliteral:directorygit:directory其他文件操作步骤:, , , , , 。
mkdircpmvrmrmdirunzipRunning Code
运行代码
runPHP:
json
{ "step": "runPHP", "code": "<?php require '/wordpress/wp-load.php'; update_option('key', 'value');" }GOTCHA: You must to use any WordPress functions.
require '/wordpress/wp-load.php';wp-cli:
json
{ "step": "wp-cli", "command": "wp post create --post_type=page --post_title='Hello' --post_status=publish" }The step name is (with hyphen), NOT or .
wp-clicliwpclirunSql:
json
{ "step": "runSql", "sql": { "resource": "literal", "name": "q.sql", "contents": "UPDATE wp_options SET option_value='val' WHERE option_name='key';" } }runPHP:
json
{ "step": "runPHP", "code": "<?php require '/wordpress/wp-load.php'; update_option('key', 'value');" }注意: 若要使用WordPress函数,必须。
require '/wordpress/wp-load.php';wp-cli:
json
{ "step": "wp-cli", "command": "wp post create --post_type=page --post_title='Hello' --post_status=publish" }步骤名称为(含连字符),而非或。
wp-clicliwpclirunSql:
json
{ "step": "runSql", "sql": { "resource": "literal", "name": "q.sql", "contents": "UPDATE wp_options SET option_value='val' WHERE option_name='key';" } }Site Configuration
站点配置
json
{ "step": "setSiteOptions", "options": { "blogname": "My Site", "blogdescription": "A tagline" } }json
{ "step": "defineWpConfigConsts", "consts": { "WP_DEBUG": true } }json
{ "step": "setSiteLanguage", "language": "en_US" }json
{ "step": "defineSiteUrl", "siteUrl": "https://example.com" }json
{ "step": "setSiteOptions", "options": { "blogname": "My Site", "blogdescription": "A tagline" } }json
{ "step": "defineWpConfigConsts", "consts": { "WP_DEBUG": true } }json
{ "step": "setSiteLanguage", "language": "en_US" }json
{ "step": "defineSiteUrl", "siteUrl": "https://example.com" }Other Steps
其他步骤
| Step | Key Properties |
|---|---|
| |
| (no required props) |
| |
| |
| |
| |
| |
| |
| (no props) |
| 步骤 | 关键属性 |
|---|---|
| |
| 无必填属性 |
| |
| |
| |
| |
| |
| |
| 无属性 |
Common Patterns
常见模式
Inline mu-plugin (quick custom code)
内联mu-plugin(快速自定义代码)
json
{
"step": "writeFile",
"path": "/wordpress/wp-content/mu-plugins/custom.php",
"data": "<?php\n// mu-plugins load automatically — no activation needed, no require wp-load.php\nadd_filter('show_admin_bar', '__return_false');"
}json
{
"step": "writeFile",
"path": "/wordpress/wp-content/mu-plugins/custom.php",
"data": "<?php\n// mu-plugins会自动加载——无需激活,无需引入wp-load.php\nadd_filter('show_admin_bar', '__return_false');"
}Inline plugin with multiple files
包含多文件的内联插件
json
{
"step": "writeFiles",
"writeToPath": "/wordpress/wp-content/plugins/",
"filesTree": {
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"my-plugin.php": "<?php\n/*\nPlugin Name: My Plugin\n*/\nrequire __DIR__ . '/includes/main.php';",
"includes": {
"main.php": "<?php // main logic"
}
}
}
}Then activate it with a separate step:
json
{ "step": "activatePlugin", "pluginPath": "my-plugin/my-plugin.php" }json
{
"step": "writeFiles",
"writeToPath": "/wordpress/wp-content/plugins/",
"filesTree": {
"resource": "literal:directory",
"name": "my-plugin",
"files": {
"my-plugin.php": "<?php\n/*\nPlugin Name: My Plugin\n*/\nrequire __DIR__ . '/includes/main.php';",
"includes": {
"main.php": "<?php // main logic"
}
}
}
}随后通过单独步骤激活:
json
{ "step": "activatePlugin", "pluginPath": "my-plugin/my-plugin.php" }Plugin from a GitHub branch
从GitHub分支安装插件
json
{
"step": "installPlugin",
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/user/repo",
"ref": "feature-branch",
"refType": "branch",
"path": "/"
}
}json
{
"step": "installPlugin",
"pluginData": {
"resource": "git:directory",
"url": "https://github.com/user/repo",
"ref": "feature-branch",
"refType": "branch",
"path": "/"
}
}Common Mistakes
常见错误
| Mistake | Correct |
|---|---|
| |
| |
Flat object as | Must be a |
Path separators in | Use nested objects for subdirectories |
| Always |
| Invented top-level keys | Only documented keys work — schema rejects unknown properties |
| Inventing proxy URLs for GitHub | Use |
Omitting | Required — only |
Resource references in | Values must be plain strings (content) or objects (subdirectories) — never resource refs |
| |
| Only needed in |
Schema URL with | Must be |
| 错误用法 | 正确用法 |
|---|---|
| |
| |
将纯对象作为 | 必须使用 |
在 | 使用嵌套对象表示子目录 |
| 使用WordPress函数时必须 |
| 自定义顶层键 | 仅支持文档中记录的键——Schema会拒绝未知属性 |
| 为GitHub自定义代理URL | 使用 |
使用分支/标签 | 必须设置——仅 |
在 | 值必须为纯字符串(内容)或对象(子目录)——不能是资源引用 |
| |
在mu-plugin代码中引入 | 仅在 |
使用 | 必须使用 |
Full Reference
完整参考
This skill covers the most common steps and patterns. For the complete API, see:
- Blueprint docs: https://wordpress.github.io/wordpress-playground/blueprints
- JSON schema: https://playground.wordpress.net/blueprint-schema.json
Additional steps not covered above: (run PHP with custom settings), , and resource types and (for advanced embedding scenarios).
runPHPWithOptionsinirunWpInstallationWizardvfsbundled本指南涵盖了最常用的步骤和模式。如需完整API,请查看:
- Blueprint文档:https://wordpress.github.io/wordpress-playground/blueprints
- JSON Schema:https://playground.wordpress.net/blueprint-schema.json
本指南未涵盖的其他步骤:(使用自定义设置运行PHP)、,以及资源类型和(用于高级嵌入场景)。
runPHPWithOptionsinirunWpInstallationWizardvfsbundledBlueprint Bundles
Blueprint 包
Bundles are self-contained packages that include a along with all the resources it references (plugins, themes, WXR files, etc.). Instead of hosting assets externally, bundle them alongside the blueprint.
blueprint.json包是自包含的套件,包含及其引用的所有资源(插件、主题、WXR文件等)。无需在外部托管资源,可将它们与Blueprint打包在一起。
blueprint.jsonBundle Structure
包结构
my-bundle/
├── blueprint.json ← must be at the root
├── my-plugin.zip ← zipped plugin directory
├── theme.zip
└── content/
└── sample-content.wxrPlugins and themes must be zipped before bundling — expects a zip, not a raw directory. To create the zip from a plugin directory:
installPluginbash
cd my-bundle
zip -r my-plugin.zip my-plugin/my-bundle/
├── blueprint.json ← 必须位于根目录
├── my-plugin.zip ← 插件目录的压缩包
├── theme.zip
└── content/
└── sample-content.wxr插件和主题在打包前必须压缩——要求ZIP格式,而非原始目录。从插件目录创建ZIP的命令:
installPluginbash
cd my-bundle
zip -r my-plugin.zip my-plugin/Referencing Bundled Resources
引用包内资源
Use the resource type to reference files within the bundle:
bundledjson
{
"step": "installPlugin",
"pluginData": {
"resource": "bundled",
"path": "/my-plugin.zip"
},
"options": { "activate": true }
}json
{
"step": "importWxr",
"file": {
"resource": "bundled",
"path": "/content/sample-content.wxr"
}
}使用资源类型引用包内的文件:
bundledjson
{
"step": "installPlugin",
"pluginData": {
"resource": "bundled",
"path": "/my-plugin.zip"
},
"options": { "activate": true }
}json
{
"step": "importWxr",
"file": {
"resource": "bundled",
"path": "/content/sample-content.wxr"
}
}Creating a Bundle Step by Step
逐步创建包
- Create the bundle directory and add at its root.
blueprint.json - Write your plugin/theme source files in a subdirectory (e.g. ).
my-plugin/my-plugin.php - Zip the plugin directory:
zip -r my-plugin.zip my-plugin/ - Reference it in using
blueprint.json.{ "resource": "bundled", "path": "/my-plugin.zip" }
Full example — a bundle that installs a custom plugin:
dashboard-widget-bundle/
├── blueprint.json
├── dashboard-widget.zip ← zip of dashboard-widget/
└── dashboard-widget/ ← plugin source (kept for editing)
└── dashboard-widget.phpjson
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/",
"preferredVersions": { "php": "8.3", "wp": "latest" },
"steps": [
{ "step": "login" },
{
"step": "installPlugin",
"pluginData": { "resource": "bundled", "path": "/dashboard-widget.zip" },
"options": { "activate": true }
}
]
}- 创建包目录,并在根目录添加。
blueprint.json - 在子目录中编写插件/主题源文件(例如)。
my-plugin/my-plugin.php - 压缩插件目录:
zip -r my-plugin.zip my-plugin/ - 在中使用
blueprint.json引用该压缩包。{ "resource": "bundled", "path": "/my-plugin.zip" }
完整示例——安装自定义插件的包:
dashboard-widget-bundle/
├── blueprint.json
├── dashboard-widget.zip ← dashboard-widget/目录的压缩包
└── dashboard-widget/ ← 插件源文件(用于编辑)
└── dashboard-widget.phpjson
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/",
"preferredVersions": { "php": "8.3", "wp": "latest" },
"steps": [
{ "step": "login" },
{
"step": "installPlugin",
"pluginData": { "resource": "bundled", "path": "/dashboard-widget.zip" },
"options": { "activate": true }
}
]
}Distribution Formats
分发格式
| Format | How to use |
|---|---|
| ZIP file (remote) | Website: |
| ZIP file (local) | CLI: |
| Local directory | CLI: |
| Git repository directory | Point |
GOTCHA: Local directory bundles always need for the CLI to read bundled resources. Without it, any reference will fail with a "File not found" error. ZIP bundles don't need this flag — all files are self-contained inside the archive.
--blueprint-may-read-adjacent-files"resource": "bundled"| 格式 | 使用方式 |
|---|---|
| ZIP文件(远程) | 网页端: |
| ZIP文件(本地) | CLI: |
| 本地目录 | CLI: |
| Git仓库目录 | 将 |
注意: 本地目录包在CLI中必须添加参数才能读取包内资源。如果不添加,所有引用都会因“文件未找到”错误而失败。ZIP包无需此参数——所有文件都已包含在归档文件中。
--blueprint-may-read-adjacent-files"resource": "bundled"Testing Blueprints
测试Blueprint
Inline Blueprints (quick test, no bundles)
内联Blueprint(快速测试,无需打包)
Minify the blueprint JSON (no extra whitespace), prepend , and open the URL in a browser:
https://playground.wordpress.net/#https://playground.wordpress.net/#{"$schema":"https://playground.wordpress.net/blueprint-schema.json","preferredVersions":{"php":"8.3","wp":"latest"},"steps":[{"step":"login"}]}Very large blueprints may exceed browser URL length limits; use the CLI instead.
压缩Blueprint JSON(无多余空格),在前面添加,然后在浏览器中打开该URL:
https://playground.wordpress.net/#https://playground.wordpress.net/#{"$schema":"https://playground.wordpress.net/blueprint-schema.json","preferredVersions":{"php":"8.3","wp":"latest"},"steps":[{"step":"login"}]}过大的Blueprint可能会超出浏览器URL长度限制;此时请使用CLI。
Local CLI Testing
本地CLI测试
Interactive server (keeps running, opens in browser):
bash
undefined交互式服务器(持续运行,在浏览器中打开):
bash
undefinedDirectory bundle — requires --blueprint-may-read-adjacent-files
目录包——需要添加--blueprint-may-read-adjacent-files参数
npx @wp-playground/cli server --blueprint=./my-bundle/ --blueprint-may-read-adjacent-files
npx @wp-playground/cli server --blueprint=./my-bundle/ --blueprint-may-read-adjacent-files
ZIP bundle — self-contained, no extra flags needed
ZIP包——自包含,无需额外参数
npx @wp-playground/cli server --blueprint=./bundle.zip
**Headless validation** (runs blueprint and exits):
```bash
npx @wp-playground/cli run-blueprint --blueprint=./my-bundle/ --blueprint-may-read-adjacent-filesnpx @wp-playground/cli server --blueprint=./bundle.zip
**无头验证**(运行Blueprint后退出):
```bash
npx @wp-playground/cli run-blueprint --blueprint=./my-bundle/ --blueprint-may-read-adjacent-filesTesting with the wordpress-playground-server Skill
使用wordpress-playground-server技能测试
Use the skill to start a local Playground instance with , then verify the expected state with Playwright MCP. For directory bundles, pass as an extra argument.
wordpress-playground-server--blueprint /path/to/blueprint.json--blueprint-may-read-adjacent-files使用技能启动本地Playground实例,参数为,然后使用Playwright MCP验证预期状态。对于目录包,需额外传递参数。
wordpress-playground-server--blueprint /path/to/blueprint.json--blueprint-may-read-adjacent-files