brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set WP_ENVIRONMENT_TYPE so plugins know a site is staging

WordPress
~/tips/tip-wordpress-environment-type

define( 'WP_ENVIRONMENT_TYPE', 'staging' );

Marks a WordPress site as local, staging or production so plugins and code can behave differently.

A staging copy of a site and the live one look the same to most plugins. WordPress has a way to tell them apart.

Since WordPress 5.5 there is a constant for it. The allowed values are local, development, staging and production. Anything else falls back to production, which is also the default.

define( 'WP_ENVIRONMENT_TYPE', 'staging' );

Code can then ask with wp_get_environment_type(). A plugin can use it to skip sending real emails or to disable analytics on a copy. WP-CLI can read the constant too: wp eval 'echo wp_get_environment_type();' prints the current value.

The docs add that the constant can also come from a PHP environment variable with the same name, and the constant wins if both are set. When the type is development and you did not define WP_DEBUG yourself, WordPress turns debugging on.

The caveat: it is only a label. WordPress core does very little with it, and your plugins have to read it. So setting it will not block outgoing mail on its own. It is still the cleanest way to mark a copy, and I would put it in every staging site’s config.

Further reading: Editing wp-config.php (WordPress developer docs), On this site: WP_AUTO_UPDATE_CORE decides which WordPress updates install themselves, On this site: cap post revisions with WP_POST_REVISIONS, On this site: Guide: let git bisect find the commit that broke your code

Going deeper: Guide: let git bisect find the commit that broke your code

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link