Sites API
The Sites API is a JavaScript API exposed by playground.wordpress.net. It manages the WordPress sites shown in the Dock's Playgrounds pane: recent autosaves, permanently stored browser Playgrounds, local-directory Playgrounds, and temporary Playgrounds.
The API is reached through the window.playgroundSites global. window.playgroundSites is not assigned during the first moments of page load. Wait for it to appear, then call isReady() before making API calls that need the active Playground client.
The Sites API ships with the Playground website application, not with the @wp-playground/client library. It is exposed on the top-level page (/), not on /remote.html. If you embed Playground via startPlaygroundWeb into your own page, your iframe won't expose window.playgroundSites to the parent — use the JavaScript API for direct control instead.
Quick start
Open playground.wordpress.net, wait for WordPress to load, then run this in DevTools:
await playgroundSites.isReady();
playgroundSites.list();
// → [{ slug: 'calm-sunny-park', name: 'Calm Sunny Park', storage: 'opfs', persistence: 'autosave', isActive: true }]
await playgroundSites.keep(undefined, 'My demo site');
// The active autosave is now a permanently saved browser Playground.
const client = playgroundSites.getClient();
await client.listFiles('/wordpress');
A fresh visit normally creates an autosaved browser Playground when browser storage and saving are available. Use ?storage=temp or createNewTemporarySite() when you need a Playground that is discarded on page refresh or tab close.
Storage and persistence
Every site has a storage backend. Stored sites also have a persistence lifecycle.
| Field | Value | Meaning |
|---|---|---|
storage | temporary | In-memory only. It is discarded on browser refresh or tab close. |
storage | opfs | Stored in the browser's Origin Private File System. |
storage | local-fs | Stored in a local directory through the File System Access API. |
persistence | autosave | A stored recovery point. Playground keeps the five most recent autosaves. |
persistence | explicit | A stored Playground kept permanently until the user or API deletes it. |
Temporary Playgrounds do not report persistence because there is no stored lifecycle to preserve.
Creating and switching sites
createNewTemporarySite(slug?, settings?)
Creates a new temporary site and switches to it. Resolves with the new site's slug once it has booted.
createNewTemporarySite(
slug?: string,
settings?: {
phpVersion?: string; // e.g. '8.4'
wpVersion?: string; // e.g. '6.8', 'latest', 'nightly', 'beta'
networking?: boolean;
language?: string; // e.g. 'pl_PL'
multisite?: boolean;
}
): Promise<string>;
Each setting corresponds to an equivalent Query API parameter of the same name, with phpVersion mapped to php and wpVersion mapped to wp. Other Query API options like plugin, theme, or blueprint-url are not accepted here.