Skip to content

Docs – loose notes to turn into proper documentation pages later on

Adam Zielinski edited this page Mar 29, 2024 · 4 revisions

Various questions and discussions

How to debug wasm?


How do I detect if my code is running in Playground?

From https://github.com/WordPress/wordpress-playground/issues/483:

I recommend not detecting Playground because it will break your plugin in many contexts.

You could, however, explicitly create a constant via a Blueprint and test for that:

https://playground.wordpress.net/#{%22constants%22:{%20%22MYPLUGIN_SETUP_DEMO_CONTENT%22:%22true%22}}

This way your plugin will only load the demo data when that's expected.

I understand why blanket Playground detection is tempting for setting up demo content. Playground, however, is more than just the app on https://playground.wordpress.net/. Here's a few contexts where loading the demo content would be harmful instead of useful:

If installing the plugin does something unexpected to the site content in either of these tools, the user will likely be surprised and assume the plugin is broken.

Any Playground-specific variable or constant is a private API and may get renamed or disappear without a warning. A long-term goal for Playground is to have 1:1 feature parity with native PHP and be indistinguishable from it.

More content: