-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
env variables are strings #229
Conversation
@@ -63,7 +63,7 @@ | |||
* Custom Settings | |||
*/ | |||
define('AUTOMATIC_UPDATER_DISABLED', true); | |||
define('DISABLE_WP_CRON', getenv('DISABLE_WP_CRON') ?: false); | |||
define('DISABLE_WP_CRON', getenv('DISABLE_WP_CRON') == "true" ? true : false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simplify this to:
define('DISABLE_WP_CRON', getenv('DISABLE_WP_CRON') == 'true');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, I just thought that the longer version is easier to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swalk's version is easier to understand for me
@dvorakluk just had one more minor comment. Would you be able to squash the commits into 1 if possible? |
…this constant is checked in WP ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ), DISABLE_WP_CRON=false would resolve to true.
@swalkinshaw Here you are :) |
Thanks! |
Noticed something similar recently... but should it be "True" (capital T)? That's how booleans render for me in the .env file.
|
@swalkinshaw - Shouldn't boolean environment variables should be set as an integer for this reason? The It's true that defining The way it is now, if I would define I suggest reverting this change because I think it is more in line with the conventions followed in other configuration files to use 1 or 0 for boolean values. 1 and 0 are also going to be interpreted correctly by both WP and bash. Also, as @andrewfrankel pointed out, 1 and 0 will not be misinterpreted simply because of a case-sensitive difference. I think it would be better to document the best practice for setting boolean values in the In summary: false === (bool) "0"
true === (bool) "1"
true === (bool) "false"
true === (bool) "true" |
Case-sensitivity is another story, good point. |
Think we're just going to use https://github.com/oscarotero/env and let it take care of this. |
In Bash, environment variable is always a string (which is what getenv() returns).
Because of the way this constant is checked in WP:
if ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON )
,setting
DISABLE_WP_CRON=false
would resolve to true.This approach should be more predictable