Skip to content

Add SCRIPT_DEBUG and WP_ENVIRONMENT_TYPE toggles to site debug settings - #4344

Open
ryanwelcher wants to merge 2 commits into
trunkfrom
add-script-debug-and-environment-type-settings
Open

Add SCRIPT_DEBUG and WP_ENVIRONMENT_TYPE toggles to site debug settings#4344
ryanwelcher wants to merge 2 commits into
trunkfrom
add-script-debug-and-environment-type-settings

Conversation

@ryanwelcher

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Code mapped the existing WP_DEBUG_LOG / WP_DEBUG_DISPLAY chain across the shared schema, CLI, both renderers, and the local REST server, then mirrored it for the two new settings. I reviewed the design decisions before implementation — in particular the WP_ENVIRONMENT_TYPE default and the choice to keep both controls in the Debugging tab.

Reviewers should pay closest attention to the SCRIPT_DEBUG / WP_DEBUG relationship (see below) and to the visual result of the new select in the legacy settings modal.

Proposed Changes

Studio already lets you toggle the debug log and browser error display from a site's Debugging settings, but SCRIPT_DEBUG and WP_ENVIRONMENT_TYPE required editing wp-config.php by hand. Since Studio manages that file, hand edits aren't reliably preserved. This adds both as first-class settings.

SCRIPT_DEBUG is the one that matters day to day: with it on, WordPress loads the development builds of core scripts, so the block editor surfaces readable React errors and component stack traces instead of minified production noise. Anyone working on blocks or in the editor wants this on regularly.

WP_ENVIRONMENT_TYPE lets you set a site to local, development, staging, or production, which changes what wp_get_environment_type() returns and how plugins and themes that branch on it behave.

Two behavior notes:

  • SCRIPT_DEBUG does not imply WP_DEBUG. They're independent constants in WordPress, so enabling script debug deliberately leaves WP_DEBUG alone. There's a regression test for this specifically, since it's the easy thing to get wrong later.
  • No change for existing sites. Studio's loader mu-plugin already defines WP_ENVIRONMENT_TYPE as local when nothing else has, so local is the effective default today and stays the default here. That mu-plugin fallback remains for imported sites whose wp-config.php Studio hasn't rewritten.

Both settings are wired through the whole stack — the CLI gains --script-debug and --environment-type on studio site set, and both appear in studio config get. Changing either restarts a running site, matching the existing debug toggles.

⚠️ Visual change: needs human review in light + dark mode.

Testing Instructions

Script debug

  1. Open a site's settings → Debugging tab. Enable Enable script debug and save; the site restarts.
  2. Confirm define( 'SCRIPT_DEBUG', true ); is in the site's wp-config.php.
  3. Open the block editor and confirm core scripts load un-minified (e.g. wp-includes/js/dist/blocks.js rather than blocks.min.js), and that React dev warnings appear in the console.
  4. Confirm WP_DEBUG was not flipped on as a side effect.

Environment type

  1. In the same tab, change Environment type to Staging and save.
  2. Confirm define( 'WP_ENVIRONMENT_TYPE', 'staging' ); lands in wp-config.php and that wp eval 'echo wp_get_environment_type();' reports staging.
  3. Confirm an untouched site still reports local.

CLI

npm run cli:build
node apps/cli/dist/cli/main.mjs site set --path <site> --script-debug --environment-type staging
node apps/cli/dist/cli/main.mjs config get --path <site>

Both UIs — repeat the first two sections in the agentic UI (studio ui) as well as the desktop settings modal, and check the read-only summary on the desktop Settings tab shows the new rows.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
SCRIPT_DEBUG lets developers load un-minified core scripts to get readable
React errors in the block editor, and WP_ENVIRONMENT_TYPE controls what
wp_get_environment_type() reports. Both previously required hand-editing
wp-config.php, which Studio manages and can overwrite.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ryanwelcher
ryanwelcher requested review from bcotrim and fredrikekelund and removed request for bcotrim July 24, 2026 20:03
@wpmobilebot

wpmobilebot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 7880fee vs trunk

app-size

Metric trunk 7880fee Diff Change
App Size (Mac) 1375.36 MB 1375.38 MB +0.02 MB ⚪ 0.0%

site-editor

Metric trunk 7880fee Diff Change
load 744 ms 1041 ms +297 ms 🔴 39.9%

site-startup

Metric trunk 7880fee Diff Change
siteCreation 6494 ms 6998 ms +504 ms 🔴 7.8%
siteStartup 2386 ms 2373 ms 13 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants