Skip to main content
All CollectionsDevelop your WordPress sitesUsing advanced Platform features
How to detect that my code is running on Pressidium
How to detect that my code is running on Pressidium

Ways to identify if your code is running on the Pressidium platform

T
Written by Team Pressidium
Updated over 2 years ago

TL;DR Check if the PRESSIDIUM_PLATFORM environment variable exists, like this:

if ( isset( $_SERVER['PRESSIDIUM_PLATFORM'] ) || getenv( 'PRESSIDIUM_PLATFORM' ) !== false ) {
// We are running on Pressidium
} else {
// We are running on a non-Pressidium environment
}

Or, keep reading for a more detailed explanation.

Detecting in a web request context

If you’re developing a WordPress theme and/or plugin, you might want to check whether you’re running on the Pressidium platform. You just have to check if the PRESSIDIUM_PLATFORM entry exists in the $_SERVER superglobal.

if ( isset( $_SERVER['PRESSIDIUM_PLATFORM'] ) ) {
// We are running on Pressidium
} else {
// We are running on a non-Pressidium environment
}

If your plugin adds a custom WP-CLI command, refer to the Detecting on CLI section below.

Detecting on CLI

If you’re writing your own custom WP-CLI commands and you need to detect whether your code is running on the Pressidium platform, you just have to check if the PRESSIDIUM_PLATFORM environment variable exists.

if ( getenv( 'PRESSIDIUM_PLATFORM' ) !== false ) {
// We are running on Pressidium
} else {
// We are running on a non-Pressidium environment
}

Please note that you need to use the getenv() function on a CLI context, because $_SERVER might not be populated.

You could combine both conditions in a single if statement, like this:

if ( isset( $_SERVER['PRESSIDIUM_PLATFORM'] ) || getenv( 'PRESSIDIUM_PLATFORM' ) !== false ) {
// We are running on Pressidium
} else {
// We are running on a non-Pressidium environment
}

Detecting via HTTP headers

You can tell if a response originates from Pressidium by inspecting its HTTP Server header.

Server: Pressidium

~ curl -sLD - https://pressidium.com -o /dev/null | grep -i "server:"
server: Pressidium

Is the Pressidium must-use plugin loaded?

Our MU (must-use) plugin provides several WordPress actions and filters, and methods that can be used to interact with the Pressidium platform. For example, purging additional paths when a clear cache operation is performed.

It may be a good idea to check whether the Pressidium MU plugin has been loaded before using any of the methods it provides:

if ( class_exists( 'Ninukis_Plugin' ) ) {
// Pressidium must-use plugin has been loaded
} else {
// Pressidium must-use plugin might not be available
}

We recommend to check each method provided by our MU plugin before invoking it:

if ( method_exists( 'Some_MU_Provided_Class', 'some_mu_provided_method' ) ) {
Some_MU_Provided_Class::some_mu_provided_method();
}

Is your use case not covered here? Let us know and we’ll be happy to include it.

Did this answer your question?