ブループリント 例
ヒント
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 include '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"
}
]
}