Using the is_wpe() function
If your workflow includes writing code outside of WP Engine’s environment, and you want an easy way to differentiate between a WP Engine environment and another environment in your code, we have just the thing for you!
is_wpe()
is a function that we have integrated into our platform to help you determine if you are running on our production environment. This function returns true (“1”) if and only if you are on a production WP Engine environment.
Please note: the output of this function is not boolean (e.g. is_wpe()===true will always return false) but instead is a numeric string (1 == true and 0 == false).
is_wpe_snapshot()
is a similar function that returns true if you are running on our 1-click staging environment.
When to use the is_wpe() function
So, when is this useful?
If you are developing on a local environment and you want to test whether the site you’re seeing is on WP Engine or not, you can use something like the following within a test file in the root directory of your website:
<?php # Use WordPress functions outside of WordPress files define('WP_USE_THEMES', false); global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header; require('wp-load.php'); # Ensure the function exists before running it and printing out the return value. if (function_exists('is_wpe')) { echo is_wpe(); } else { echo "The function does not exist"; }
Visiting yourdomain.com/testfile.php will print “1” if the site is running on a WP Engine production environment, “0” if it is not running on a WP Engine production environment, or “The function does not exist” if the is_wpe() function has not been defined in your environment (this should never be the case on a WP Engine server as long as our mu-plugin is installed).