WordPress Playground
Tags: wordpress, php, webassembly
Published: 2023-06-27 19:14:08

One of the most exciting things at [WordCamp Europe 2023](https://europe.wordcamp.org/2023/) for me was discovering how far along the [WordPress Playground](https://developer.wordpress.org/playground/) project is. If you haven’t heard of the playground before, it’s a full version of WordPress, running directly in your browser!


## History

The project began [late last summer](https://make.wordpress.org/core/2022/09/23/client-side-webassembly-wordpress-with-no-server/), with version 0.1 being released in April. The readme indicates that it was inspired by the initial PHP WASM implementation,  a Drupal in the browser example, and a [WASM Labs WordPress demo](https://wasmlabs.dev/articles/wordpress-in-the-browser/). The WordPress Playground was introduced to the larger WordPress community during the [2022 State of the Word](https://www.hostinger.com/blog/state-of-the-word-2022#WordPress_Playground) presentation. 

The Playground was actively promoted during WCEU this year — used to quickly spin up sites for the [documentation team](https://dev.to/cgarofalo/contributor-day-at-wceu23-in-athens-15c1), and others,  on [contributor day](https://wordpress.github.io/wordpress-playground/wordcamp-contributor-day/), featured in a [connect track](https://europe.wordcamp.org/2023/wp-connect/) session, and a [demo during the keynote.](https://youtu.be/7Nmz3IjtPh0?t=374)


## How it works

The technology behind the Playground is called WASM, short for [Web Assembly](https://webassembly.org/).

> WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable compilation target for programming languages, enabling deployment on the web for client and server applications.

There are versions of PHP compiled into WASM binaries that allow you to run PHP code directly in the browser. The Playground then uses those binaries to [run the WordPress PHP application](https://wordpress.github.io/wordpress-playground/architecture/wordpress), as well as a plugin that allows MySQL calls to be intercepted and interpreted to SQLite


## Demos

<figure><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfknl4sn4a2y961nbbmf.png" alt="Screenshot of the Playground with Frost Theme" loading="lazy"><figcaption>WordPress Playground with Frost theme installed</figcaption></figure>

Unfortunately, you can’t embed playground iframes in dev.to, but we can link directly to a few examples of it in action. The [Playground default](https://playground.wordpress.net) uses the latest version of WordPress with the default theme and PHP 8.0. 

You can use query parameters, like `theme` and `plugins` to install a particular theme or plugin in the Playground. In [this example](https://playground.wordpress.net/?theme=frost&plugin=coblocks), we install the Frost theme and CoBlocks plugin. You can also pass `wp` and `php` to install different versions of WordPress and PHP.

If you’re embedding an iframe, the experience is also totally [scriptable](https://wordpress.github.io/wordpress-playground/javascript-api/index). One example of the iframes in action is the [tutorial](https://adamadam.blog/2023/02/16/how-to-modify-html-in-a-php-wordpress-plugin-using-the-new-tag-processor-api/) for using the new tag processor function.


## The future

The Playground opens up a lot of possibilities since it makes WordPress embeddable in so many areas: 

- We can easily test different versions of WordPress and PHP
- We can [embed live examples](https://jonathanbossenger.com/2023/06/19/testing-out-the-wp-playground-interactive-code-block/) in tutorials and lessons
- A [VS Code extension](https://marketplace.visualstudio.com/items?itemName=WordPressPlayground.wordpress-playground) allows you to open a theme or plugin up in a usable test environment
- It can be embedded directly in [mobile apps](https://twitter.com/adamzielin/status/1669478239771799552)
- We can include live demos in pull requests
- It can be integrated into a CI/CD pipeline

The [vision and philosophy](https://github.com/WordPress/wordpress-playground/issues/472) and [roadmap](https://github.com/WordPress/wordpress-playground/issues/525) are both available on GitHub, so you can see where things are headed. It’s still early on, version 0.2 was just released a few days ago on June 24th. We’re likely to see breaking changes at times until an official 1.0 release happens.

Now it’s time to go [play](https://wordpress.github.io/wordpress-playground/).