wp_get_speculative_loading_override()
Returns the value of a speculative loading override, as supplied by a constant or an environment variable.
The constant takes precedence over the environment variable, consistent with wp_get_environment_type().
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
string|null. The override value, or null if neither is set.
Usage
wp_get_speculative_loading_override( $name ): ?string;
- $name(string) (required)
- Name of the constant and environment variable to look up.
Changelog
| Since 7.1.0 | Introduced. |
wp_get_speculative_loading_override() wp get speculative loading override code WP 7.1
function wp_get_speculative_loading_override( string $name ): ?string {
$value = null;
// Check if the environment variable has been set, if `getenv` is available on the system.
if ( function_exists( 'getenv' ) ) {
$has_env = getenv( $name );
if ( false !== $has_env ) {
$value = $has_env;
}
}
// Fetch the value from a constant, which overrides the environment variable.
if ( defined( $name ) ) {
$has_constant = constant( $name );
if ( is_string( $has_constant ) ) {
$value = $has_constant;
}
}
return $value;
}