Skip to content

Bug: WP_ENVIRONMENT_TYPE set doesn't check if constant is already defined #672

Open
@ethanclevenger91

Description

Terms

Description

What's wrong?

Some environments (like Local) set the WP_ENVIRONMENT_TYPE constant. Bedrock's implementation should probably check for that to avoid a fatal error.

What have you tried?

Local's prepended PHP file can be updated, but a more bulletproof implementation here is likely preferred.

Possible solutions

if (!defined('WP_ENVIRONMENT_TYPE') && !env('WP_ENVIRONMENT_TYPE') && in_array(WP_ENV, ['production', 'staging', 'development'])) {
    Config::define('WP_ENVIRONMENT_TYPE', WP_ENV);
}

I'm also not sure what the !env('WP_ENVIRONMENT_TYPE') check does in that line, since there's no code to convert that exact env value to the constant value, unless WordPress is doing it under the hood (it might be).

Temporary workarounds

Update Local's config

Steps To Reproduce

  1. Install a Bedrock site in Local
  2. See fatal error

Expected Behavior

No fatal error

Actual Behavior

Fatal error

Relevant Log Output

No response

Versions

Since PR #668

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions