Skip to content

Commit 3653a5a

Browse files
committed
fix: expose dotenv variables via getenv() for WordPress library compatibility
Use createUnsafeImmutable instead of createImmutable to ensure environment variables loaded by dotenv are available via getenv() in addition to $_ENV and $_SERVER. Many WordPress plugins and libraries (e.g. Wonolog) rely on getenv() and silently fall back to defaults when the variable is missing, causing hard-to-diagnose configuration bugs. Thread-safety is not a concern for standard WordPress deployments using PHP-FPM or CLI (single-threaded per request). Only affected on Apache mod_php with MPM worker/event, which is not a typical WordPress SAPI.
1 parent 7a956bb commit 3653a5a

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

.env.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
# ---------------------------
2+
# WP Boot
3+
# ---------------------------
4+
15
# Enable/disable WordPress sync to public directory
26
# Set to 'true' to enable automatic sync via post-cmd.sh
37
WP_BOOT_SYNC_ENABLED=false
48

9+
# ---------------------------
10+
# WordPress
11+
# ---------------------------
12+
513
DB_HOST=
614
DB_NAME=
715
DB_USER=
@@ -34,6 +42,10 @@ NONCE_SALT=''
3442
DISALLOW_FILE_MODS=false
3543
DISALLOW_FILE_EDIT=true
3644

45+
# Disable WordPress pseudo-cron (triggered on every page request) in favor of a
46+
# real system cron job. Improves performance by removing per-request cron overhead.
47+
# Requires a cron job to be set up manually (see crontab).
48+
# https://roots.io/bedrock/docs/wp-cron/
3749
DISABLE_WP_CRON=false
3850

3951
# false, true, minor

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ updates:
1111
assignees:
1212
- "frugan-dev"
1313
commit-message:
14-
prefix: "chore"
14+
prefix: "deps"
1515
include: "scope"
1616
labels:
1717
- "dependencies"
@@ -27,7 +27,7 @@ updates:
2727
assignees:
2828
- "frugan-dev"
2929
commit-message:
30-
prefix: "chore"
30+
prefix: "ci"
3131
include: "scope"
3232
labels:
3333
- "dependencies"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# Composer
77
/vendor
8-
composer*.lock
8+
*.lock
99
auth.json
1010

1111
# Claude

bootstrap.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,19 @@ function fixMissingEnvVars(
112112
$envs = array_unique(array_filter($envs));
113113

114114
try {
115-
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__, $envs, false);
115+
// NOTE: We use createUnsafeImmutable (not createImmutable) so that
116+
// dotenv-loaded variables are also exposed via getenv() in addition
117+
// to $_ENV / $_SERVER. Many WordPress plugins and libraries read
118+
// configuration via getenv() and silently fall back to defaults when
119+
// the variable is missing — causing hard-to-diagnose bugs.
120+
//
121+
// Thread-safety caveat: getenv()/putenv() are documented as not
122+
// thread-safe in phpdotenv. This only matters on PHP ZTS builds with a
123+
// multi-threaded SAPI (e.g. Apache mod_php with MPM worker/event).
124+
// Standard PHP-FPM and CLI deployments — the expected targets for
125+
// WordPress installations using wp-boot — are single-threaded per
126+
// request and unaffected.
127+
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__, $envs, false);
116128
$dotenv->load();
117129
$dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASSWORD']);
118130
} catch (Exception $e) {

0 commit comments

Comments
 (0)