[wp-trac] [WordPress Trac] #50896: Add filters to wp_get_environment_type()
WordPress Trac
noreply at wordpress.org
Wed Aug 12 14:41:27 UTC 2020
#50896: Add filters to wp_get_environment_type()
----------------------------+------------------------------
Reporter: crstauf | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bootstrap/Load | Version: 5.5
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
----------------------------+------------------------------
Comment (by crstauf):
FWIW, I did think of another approach last night: check if
`WP_DEVELOPMENT_TYPE` constant is defined or the environment variable is
set, and if not, `wp_die()` with a message asking for the value to be
explicitly set. This is not ideal, but if adding filters into the function
is significantly problematic, there is that option.
Here's the mu-plugin if anyone ends up here looking for something similar:
{{{#!php
<?php
if ( ! function_exists( 'require_set_environment_type' ) ) {
/**
* Prevent site load if environment type not explicitly set.
*
* @uses wp_get_environment_type()
* @uses wp_die()
*/
function require_set_environment_type() {
if ( ! function_exists( 'wp_get_environment_type' ) ) {
return;
}
$current_env = '';
if ( function_exists( 'getenv' ) ) {
$has_env = getenv( 'WP_ENVIRONMENT_TYPE' );
if ( false !== $has_env ) {
$current_env = $has_env;
}
}
if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) {
$current_env = WP_ENVIRONMENT_TYPE;
}
if ( wp_get_environment_type() === $current_env ) {
return;
}
wp_die( 'Explicitly define a valid environment type to
activate the site.<br />See <code>wp_get_environment_type()</code> for
more info.' );
exit;
}
require_set_environment_type();
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50896#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list