ブループリント 例
Blueprints ギャラリー をチェックして、WordPress Playground を使用してさまざまな設定で WordPress サイトを起動する実際のコード例を確認してください。
ブループリントで実現できるクールな機能をいくつか見てみましょう。
テーマと プラグインをインストールする
{
"steps": [
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "coblocks"
}
},
{
"step": "installTheme",
"themeData": {
"resource": "wordpress.org/themes",
"slug": "pendant"
}
}
]
}
カスタム PHP コードを実行する
{
"steps": [
{
"step": "runPHP",
"code": "<?php require_once '/wordpress/wp-load.php'; wp_insert_post(array( 'post_title' => 'Post title', 'post_content' => 'Post content', 'post_status' => 'publish', 'post_author' => 1 )); "
}
]
}
Gutenberg 実験ページでオプションを有効にする
ここで、「新しい管理者ビュー」機能をオンにします。
{
"steps": [
{
"step": "runPHP",
"code": "<?php require '/wordpress/wp-load.php'; update_option( 'gutenberg-experiments', array( 'gutenberg-dataviews' => true ) );"
}
]
}
製品デモを紹介
{
"steps": [
{
"step": "installPlugin",
"pluginData": {
"resource": "url",
"url": "https://your-site.com/your-plugin.zip"
}
},
{
"step": "installTheme",
"themeData": {
"resource": "url",
"url": "https://your-site.com/your-theme.zip"
}
},
{
"step": "importWxr",
"file": {
"resource": "url",
"url": "https://your-site.com/starter-content.wxr"
}
},
{
"step": "setSiteOptions",
"options": {
"some_required_option_1": "your_favorite_values",
"some_required_option_2": "your_favorite_values"
}
}
]
}
ネットワーキングを有効
{
"landingPage": "/wp-admin/plugin-install.php",
"features": {
"networking": true
},
"steps": [
{
"step": "login"
}
]
}
リクエストごとに PHP コードをロードする (mu-plugin)
writeFile ステップを使用して、リクエストごとに実行される mu-plugin にコードを追加します。
{
"landingPage": "/category/uncategorized/",
"features": {
"networking": true
},
"steps": [
{
"step": "login"
},
{
"step": "writeFile",
"path": "/wordpress/wp-content/mu-plugins/rewrite.php",
"data": "<?php add_action( 'after_setup_theme', function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );"
}
]
}
コードエディター( Gutenberg ブロックとして)
{
"landingPage": "/wp-admin/post.php?post=4&action=edit",
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "interactive-code-block"
}
},
{
"step": "runPHP",
"code": "<?php require '/wordpress/wp-load.php'; wp_insert_post(['post_title' => 'WordPress Playground block demo!','post_content' => '<!-- wp:wordpress-playground/playground /-->', 'post_status' => 'publish', 'post_type' => 'post',]);"
}
]
}
この専用 wiki で独自のブループリントの例を共有できます。
古いバージョンの WordPress を読み込む
Playground には最近の WordPress リリースがいくつかしか含まれていません。古いバージョンを使用する必要がある場合は、こちらのブループリントが役立ちます。"url": "https://playground.wordpress.net/plugin-proxy.php?url=https://wordpress.org/wordpress-5.9.9.zip" のバージョン番号を 5.9.9 から、読み込みたいリリースに変更してください。
注: サポートされている最も古い WordPress バージョンは、SQLite 統合プラグインに従った 5.9.9 です。
{
"landingPage": "/wp-admin",
"steps": [
{
"step": "writeFile",
"path": "/tmp/wordpress.zip",
"data": {
"resource": "url",
"url": "https://playground.wordpress.net/plugin-proxy.php?url=https://wordpress.org/wordpress-5.9.9.zip",
"caption": "Downloading the WordPress Release"
}
},
{
"step": "importWordPressFiles",
"wordPressFilesZip": {
"resource": "vfs",
"path": "/tmp/wordpress.zip"
},
"pathInZip": "/wordpress",
"progress": {
"weight": 20,
"caption": "Importing the WordPress release"
}
},
{
"step": "runPHP",
"code": "<?php $_GET['step'] = 'upgrade_db'; require '/wordpress/wp-admin/upgrade.php'; "
},
{
"step": "login",
"username": "admin",
"password": "password"
}
]
}
トランクまたは特定のコミットから WordPress を実行します。
WordPress Playground は、trunk (最新のコミット)、特定のブランチの HEAD、または WordPress/WordPress GitHub リポジトリからの特定のコミットを実行できます。
"url": "https://playground.wordpress.net/plugin-proxy.php?build-ref=trunk" で参照を指定できます。
特定のブランチの最新コミットを指定するには、ブランチのバージョン番号への参照を変更します(例:6.6)。特定のコミットを実行するには、WordPress/WordPress のコミットハッシュを使用します(例:7d7a52367dee9925337e7d901886c2e9b21f70b6)。
注: サポートされている最も古い WordPress バージョンは、SQLite 統合プラグインに従った 5.9.9 です。
{
"landingPage": "/wp-admin",
"login": true,
"preferredVersions": {
"php": "8.0",
"wp": "https://playground.wordpress.net/plugin-proxy.php?build-ref=trunk"
}
}
ブループリントバンドルの使用
以下は、ブループリント バンドルからバンドルされたリソースを使用するブループリントの例です。
{
"landingPage": "/",
"preferredVersions": {
"php": "8.0",
"wp": "latest"
},
"steps": [
{
"step": "installTheme",
"themeData": {
"resource": "bundled",
"path": "/my-theme.zip"
},
"activate": true
},
{
"step": "installPlugin",
"pluginData": {
"resource": "bundled",
"path": "/my-plugin.zip"
},
"activate": true
},
{
"step": "writeFile",
"path": "/wordpress/custom-page.html",
"data": {
"resource": "bundled",
"path": "/assets/custom-page.html"
}
}
]
}
このブループリント バンドルは、次のファイルを含む zip ファイルになります。
/blueprint.json- 上記で説明したブループリントの宣言/my-theme.zip- テーマパッケージ/my-plugin.zip- プラグインパッケージ/assets/custom-page.html- カスタム HTML ファイル
このブループリント バンドルは次の方法で使用できます。
- これらのファイルと blueprint.json を含む ZIP ファイルを作成する
- ZIP ファイルをサーバーにホストする
?blueprint-url=https://example.com/my-blueprint-bundle.zipで読み込む
ブループリント バンドルの詳細については、ブループリント バンドル ドキュメントを参照してください。