• Resolved room34

    (@room34)


    I’m trying to make one of my plugins compatible with WordPress Playground, and as I’m troubleshooting some of the issues, I’m finding it would be helpful within the plugin to have a way to detect that it’s running in a WordPress Playground instance, rather than a traditional server.

    I imagine there is a way to detect this (a function like is_playground() is probably too much to ask for), but I’ve been skimming the documentation and haven’t found anything.

    Any suggestions?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    I don’t know for sure, but since the playground renders within an iframe, I should think that window.parent !== window.self. See if that does anything for you. It’s how JavaScript can determine if it’s running in any iframe, it’s not unique to WP Playground.

    Could return a false playground positive if your script is running in a normal non-playground WP page that someone just happens to include within an iframe, unrelated to WP Playground. Depending on your need, this may or may not be an issue.

    Thread Starter room34

    (@room34)

    Sorry I didn’t clarify, it really needs to be a PHP-based method.

    Moderator bcworkz

    (@bcworkz)

    Sorry, I’m not sure about PHP methods. Maybe try dumping out $_SERVER and see if anything useful is there? Maybe $_SERVER['SERVER_SIGNATURE'] might be meaningful?

    There’s likely something unique about Playground PHP someone can check for to verify it’s running in Playground. For example, there’s cross process communication available that’s not possible in server based PHP. If such communication is possible, it’s likely Playground or at least it’s WebAssembly PHP. But I’m only speculating, I don’t really know.

    Thread Starter room34

    (@room34)

    Yeah, good point. I was dumping $_GET but I didn’t think to check $_SERVER.

    Thread Starter room34

    (@room34)

    Follow-up for anyone who may be in the same boat, this looks like a workable solution. Just check for:

    $_SERVER['SERVER_SOFTWARE'] == 'PHP.wasm'

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Is there a way from “inside” WordPress to detect it’s running in Playground?’ is closed to new replies.