I’ve recently built into the must-use plugin that I run on all my live and local websites setting of the WP_ENVIRONMENT_TYPE appropriately (I check '127.0.0.1' == $_SERVER['SERVER_ADDR'] to sense being on Local, but as a side-note it would be better if Local sites all had something like $_SERVER['LOCAL_SITE'] to explicitly check, much like SpinupWP’s SPINUPWP_SITE and DreamHost’s DH_USER). This works for WP_ENVIRONMENT_TYPE just fine, to make my local sites all local environment. I then use this designation in other parts of my code to, for example, force the discouraging of search engines as needed, force payment gateways to test mode, and so on, so that I don’t have to risk forgetting changing those when in local or staging sites.
But on Locals I also want to set WP_DEVELOPMENT_MODE to all. I have to be defensive and check if these are defined already, and it appears that Local is explicitly defining WP_DEVELOPMENT_MODE to be disabled. Is that intentional? If so, why? Doing so makes it impossible to change this in custom code or the config file.
For both of these it may actually be a good idea to consider adding settings on the sites in the Local GUI to let us explicitly set both from there. But at minimum Local should run sites such that we can define these as we like ourselves.
Perhaps something else is defining WP_DEVELOPMENT_MODE in your environment? It might be worth searching your wp-content directory for that text just in case.
Interesting. It works if I put this in the wp-config.php file:
But it does not work in my custom mu-plugin. My plugin has the only cases of the constant in my wp-content directory. The plugin instantiates a class that incapsulates the plugin code (and then instantiates a copy of this class at the bottom of the file in global space), and it is right in the __construct() of that where I run my environment config code:
I am checking the constant in the admin under the Site Health screeen. Is this screen perhaps just not getting the correct value? Using the CLI as you did I get string(0) "", but that makes sense given my code as it currently is, no.
@alexclst I suspect your plugin code is trying to set those constants after they’ve been read by the Site Health Info code (in debug_data() here) and after WP-CLI when running eval logic. So this is less about Local and more about WordPress’ “boot process” and order of operations.
I don’t think it will be enough to move your class instantiation to an earlier hook or to the file root — it may still not be early enough because code that needs those env vars could run before hooks fire or plugins load.
To set site constants more dependably, you could move your definitions to wp-config.php (you can still apply the conditional logic there). The earlier you can configure environment variables, the better, and wp-config.php loads very early.
This is also consistent with the guidance on setting constants: