API の概要
WordPress Playground API の概要
WordPress Playground は、Playground と通信するために使用できるいくつかの API を公開しています。
クエリ API
基本的な操作は URL を調整することで実行できます。たとえば、coblocks プラグインを事前にインストールする方法は次のとおりです。
https://playground.wordpress.net/?plugin=coblocks
またはテーマ:
https://playground.wordpress.net/?theme=pendant
これは クエリ API と呼ばれ、詳細は こちら で確認できます。気に入った URL ができたら、iframe を使用して Web サイトに埋め込むことができます。
<iframe style="width: 800px; height: 500px;" src="https://playground.wordpress.net/?plugin=coblocks"></iframe>
詳細については、クエリ API セクションを確認してください。
ブループリント
Playground をより細かく制御したい場合は、JSON ブループリントを使用できます。例えば、投稿を作成してプラグインをインストールする方法は次のとおりです。
{
"steps": [
{
"step": "login"
},
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "friends"
}
},
{
"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)); ?>"
}
]
}
WordPress Playground ではブループリントが重要な役割を果たすため、専用のドキュメントハブが用意されています。JSON ブループリントの詳細については、ブループリント ドキュメント ハブ をご覧ください。
JavaScript API
@wp-playground/client パッケージは、Playground インスタンスを完全に制御できる JavaScript API を提供します。以下に、実際にできることの簡単な例を示します。
<iframe id="wp" style="width: 100%; height: 300px; border: 1px solid #000;"></iframe>
<script type="module">
// Use unpkg for convenience
import { startPlaygroundWeb } from 'https://playground.wordpress.net/client/index.js';
const client = await startPlaygroundWeb({
iframe: document.getElementById('wp'),
remoteUrl: `https://playground.wordpress.net/remote.html`,
});
// Let's wait until Playground is fully loaded
await client.isReady();
</script>
詳細については、JavaScript API セクションをご覧ください。
プレイグラウンド API の概念
ブラウザ上の WordPress Playground は、リンクと iframe が中心です。どの API を選択しても、以下のいずれかの方法で使用します。