Skip to content

Define a PHP constant so PHP code can detect it is running in Playground #483

@eliot-akira

Description

@eliot-akira

Recently, there was an issue where the Create Block Theme plugin was throwing an error due to limited networking support in Playground.

Maybe we could disable Google fonts if the plugin is on a Playground instance for now.

If the Playground could define a PHP constant, like WORDPRESS_PLAYGROUND, then plugins/themes could detect it and modify their behavior accordingly.


Another possible use case: when running wp-now on the server, a locally installed wp-cli could detect and interact with it somehow.

we may just need to tell WP-CLI where to find the WordPress files, SQLite database, and project files. At the moment however, the knowledge of this only exists in the virtualized filesystem.

If wp-now could define a PHP constant, like WP_NOW, it could help wp-cli (and maybe other tools) to implement a deeper integration. How exactly the communication between them would work is a bigger question. 🙃


@adamziel's recommendation:

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 then check 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions