admin
1 year ago
emails
1 year ago
fields
1 year ago
functions
1 year ago
providers
1 year ago
templates
1 year ago
class-db.php
1 year ago
class-fields.php
1 year ago
class-form.php
1 year ago
class-install.php
1 year ago
class-process.php
1 year ago
class-providers.php
1 year ago
class-templates.php
1 year ago
class-widget.php
1 year ago
compat.php
1 year ago
deprecated.php
1 year ago
functions-list.php
1 year ago
functions.php
1 year ago
integrations.php
1 year ago
compat.php
75 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WordPress core function polyfill for WordPress 5.2 - 5.4. |
| 4 | * |
| 5 | * @since 1.7.6 |
| 6 | */ |
| 7 | if ( ! function_exists( 'wp_get_environment_type' ) ) { |
| 8 | /** |
| 9 | * Retrieves the current environment type. |
| 10 | * |
| 11 | * The type can be set via the `WP_ENVIRONMENT_TYPE` global system variable, |
| 12 | * or a constant of the same name. |
| 13 | * |
| 14 | * Possible values are 'local', 'development', 'staging', and 'production'. |
| 15 | * If not set, the type defaults to 'production'. |
| 16 | * |
| 17 | * @return string The current environment type. |
| 18 | */ |
| 19 | function wp_get_environment_type() { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh, WPForms.Comments.SinceTag.MissingSince |
| 20 | |
| 21 | static $current_env = ''; |
| 22 | |
| 23 | if ( ! defined( 'WP_RUN_CORE_TESTS' ) && $current_env ) { |
| 24 | return $current_env; |
| 25 | } |
| 26 | |
| 27 | $wp_environments = [ |
| 28 | 'local', |
| 29 | 'development', |
| 30 | 'staging', |
| 31 | 'production', |
| 32 | ]; |
| 33 | |
| 34 | // Add a note about the deprecated WP_ENVIRONMENT_TYPES constant. |
| 35 | if ( defined( 'WP_ENVIRONMENT_TYPES' ) && function_exists( '_deprecated_argument' ) ) { |
| 36 | // phpcs:disable WPForms.PHP.ValidateDomain.InvalidDomain |
| 37 | if ( function_exists( '__' ) ) { |
| 38 | /* translators: %s - WP_ENVIRONMENT_TYPES. */ |
| 39 | $message = sprintf( __( 'The %s constant is no longer supported.' ), 'WP_ENVIRONMENT_TYPES' ); |
| 40 | } else { |
| 41 | $message = sprintf( 'The %s constant is no longer supported.', 'WP_ENVIRONMENT_TYPES' ); |
| 42 | } |
| 43 | // phpcs:enable WPForms.PHP.ValidateDomain.InvalidDomain |
| 44 | |
| 45 | _deprecated_argument( |
| 46 | 'define()', |
| 47 | '5.5.1', |
| 48 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 49 | $message |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | // Check if the environment variable has been set, if `getenv` is available on the system. |
| 54 | if ( function_exists( 'getenv' ) ) { |
| 55 | $has_env = getenv( 'WP_ENVIRONMENT_TYPE' ); |
| 56 | |
| 57 | if ( $has_env !== false ) { |
| 58 | $current_env = $has_env; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // Fetch the environment from a constant, this overrides the global system variable. |
| 63 | if ( defined( 'WP_ENVIRONMENT_TYPE' ) ) { |
| 64 | $current_env = WP_ENVIRONMENT_TYPE; |
| 65 | } |
| 66 | |
| 67 | // Make sure the environment is an allowed one, and not accidentally set to an invalid value. |
| 68 | if ( ! in_array( $current_env, $wp_environments, true ) ) { |
| 69 | $current_env = 'production'; |
| 70 | } |
| 71 | |
| 72 | return $current_env; |
| 73 | } |
| 74 | } |
| 75 |