diff --git a/apps/cli/commands/site/set.ts b/apps/cli/commands/site/set.ts index f466f683e1..9cdd21adbb 100644 --- a/apps/cli/commands/site/set.ts +++ b/apps/cli/commands/site/set.ts @@ -44,10 +44,12 @@ export interface SetCommandOptions { php?: string; wp?: string; xdebug?: boolean; + debugLog?: boolean; + debugDisplay?: boolean; } export async function runCommand( sitePath: string, options: SetCommandOptions ): Promise< void > { - const { name, domain, https, php, wp, xdebug } = options; + const { name, domain, https, php, wp, xdebug, debugLog, debugDisplay } = options; if ( name === undefined && @@ -55,10 +57,14 @@ export async function runCommand( sitePath: string, options: SetCommandOptions ) https === undefined && php === undefined && wp === undefined && - xdebug === undefined + xdebug === undefined && + debugLog === undefined && + debugDisplay === undefined ) { throw new LoggerError( - __( 'At least one option (--name, --domain, --https, --php, --wp, --xdebug) is required.' ) + __( + 'At least one option (--name, --domain, --https, --php, --wp, --xdebug, --debug-log, --debug-display) is required.' + ) ); } @@ -112,9 +118,19 @@ export async function runCommand( sitePath: string, options: SetCommandOptions ) const phpChanged = php !== undefined && php !== site.phpVersion; const wpChanged = wp !== undefined; const xdebugChanged = xdebug !== undefined && xdebug !== site.enableXdebug; + const debugLogChanged = debugLog !== undefined && debugLog !== site.enableDebugLog; + const debugDisplayChanged = + debugDisplay !== undefined && debugDisplay !== site.enableDebugDisplay; const hasChanges = - nameChanged || domainChanged || httpsChanged || phpChanged || wpChanged || xdebugChanged; + nameChanged || + domainChanged || + httpsChanged || + phpChanged || + wpChanged || + xdebugChanged || + debugLogChanged || + debugDisplayChanged; if ( ! hasChanges ) { throw new LoggerError( __( 'No changes to apply. The site already has the specified settings.' ) @@ -127,6 +143,8 @@ export async function runCommand( sitePath: string, options: SetCommandOptions ) phpChanged, wpChanged, xdebugChanged, + debugLogChanged, + debugDisplayChanged, } ); const oldDomain = site.customDomain; @@ -153,6 +171,12 @@ export async function runCommand( sitePath: string, options: SetCommandOptions ) if ( xdebugChanged ) { foundSite.enableXdebug = xdebug; } + if ( debugLogChanged ) { + foundSite.enableDebugLog = debugLog; + } + if ( debugDisplayChanged ) { + foundSite.enableDebugDisplay = debugDisplay; + } await saveAppdata( appdata ); site = foundSite; @@ -287,6 +311,14 @@ export const registerCommand = ( yargs: StudioArgv ) => { .option( 'xdebug', { type: 'boolean', description: __( 'Enable Xdebug' ), + } ) + .option( 'debug-log', { + type: 'boolean', + description: __( 'Enable WP_DEBUG_LOG' ), + } ) + .option( 'debug-display', { + type: 'boolean', + description: __( 'Enable WP_DEBUG_DISPLAY' ), } ); }, handler: async ( argv ) => { @@ -298,6 +330,8 @@ export const registerCommand = ( yargs: StudioArgv ) => { php: argv.php, wp: argv.wp, xdebug: argv.xdebug, + debugLog: argv.debugLog, + debugDisplay: argv.debugDisplay, } ); } catch ( error ) { if ( error instanceof LoggerError ) { diff --git a/apps/cli/commands/site/tests/set.test.ts b/apps/cli/commands/site/tests/set.test.ts index 7cabcf1701..6516e05820 100644 --- a/apps/cli/commands/site/tests/set.test.ts +++ b/apps/cli/commands/site/tests/set.test.ts @@ -98,7 +98,7 @@ describe( 'CLI: studio site set', () => { describe( 'Validation', () => { it( 'should throw when no options provided', async () => { await expect( runCommand( testSitePath, {} ) ).rejects.toThrow( - 'At least one option (--name, --domain, --https, --php, --wp, --xdebug) is required.' + 'At least one option (--name, --domain, --https, --php, --wp, --xdebug, --debug-log, --debug-display) is required.' ); } ); diff --git a/apps/cli/lib/types/wordpress-server-ipc.ts b/apps/cli/lib/types/wordpress-server-ipc.ts index 9550c899bc..7f4506db54 100644 --- a/apps/cli/lib/types/wordpress-server-ipc.ts +++ b/apps/cli/lib/types/wordpress-server-ipc.ts @@ -13,6 +13,8 @@ const serverConfig = z.object( { siteLanguage: z.string().optional(), isWpAutoUpdating: z.boolean().optional(), enableXdebug: z.boolean().optional(), + enableDebugLog: z.boolean().optional(), + enableDebugDisplay: z.boolean().optional(), blueprint: z .object( { contents: z.any(), // Blueprint type is complex, allow any for now diff --git a/apps/cli/lib/wordpress-server-manager.ts b/apps/cli/lib/wordpress-server-manager.ts index 3609082a22..d289cbc05b 100644 --- a/apps/cli/lib/wordpress-server-manager.ts +++ b/apps/cli/lib/wordpress-server-manager.ts @@ -105,6 +105,14 @@ export async function startWordPressServer( serverConfig.enableXdebug = true; } + if ( site.enableDebugLog ) { + serverConfig.enableDebugLog = true; + } + + if ( site.enableDebugDisplay ) { + serverConfig.enableDebugDisplay = true; + } + const env = { ELECTRON_RUN_AS_NODE: '1', STUDIO_WORDPRESS_SERVER_CONFIG: JSON.stringify( serverConfig ), @@ -371,6 +379,14 @@ export async function runBlueprint( serverConfig.enableXdebug = true; } + if ( site.enableDebugLog ) { + serverConfig.enableDebugLog = true; + } + + if ( site.enableDebugDisplay ) { + serverConfig.enableDebugDisplay = true; + } + const env = { ELECTRON_RUN_AS_NODE: '1', STUDIO_WORDPRESS_SERVER_CONFIG: JSON.stringify( serverConfig ), diff --git a/apps/cli/patches/@wp-playground+wordpress+3.1.1.patch b/apps/cli/patches/@wp-playground+wordpress+3.1.1.patch index 172f90bc5b..279c1e6f80 100644 --- a/apps/cli/patches/@wp-playground+wordpress+3.1.1.patch +++ b/apps/cli/patches/@wp-playground+wordpress+3.1.1.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/@wp-playground/wordpress/index.cjs b/node_modules/@wp-playground/wordpress/index.cjs -index 9c468e3..3e5ab08 100644 +index 9c468e3..324e27d 100644 --- a/node_modules/@wp-playground/wordpress/index.cjs +++ b/node_modules/@wp-playground/wordpress/index.cjs @@ -352,7 +352,7 @@ function skip_whitespace($tokens) { @@ -11,8 +11,21 @@ index 9c468e3..3e5ab08 100644 ob_start(); $wp_load = getenv('DOCUMENT_ROOT') . '/wp-load.php'; if (!file_exists($wp_load)) { +@@ -619,7 +619,11 @@ function skip_whitespace($tokens) { + + $log_file = WP_CONTENT_DIR . '/debug.log'; + define('ERROR_LOG_FILE', $log_file); +- ini_set('error_log', $log_file); ++ if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) { ++ ini_set('error_log', $log_file); ++ } else { ++ ini_set('log_errors', '0'); ++ } + ?>`),await e.writeFile("/internal/shared/mu-plugins/sitemap-redirect.php",`` + ), await e.writeFile( + "/internal/shared/mu-plugins/sitemap-redirect.php", diff --git a/apps/cli/wordpress-server-child.ts b/apps/cli/wordpress-server-child.ts index ad303df87f..afcb500064 100644 --- a/apps/cli/wordpress-server-child.ts +++ b/apps/cli/wordpress-server-child.ts @@ -166,8 +166,14 @@ async function getBaseRunCLIArgs( }, ]; - const defaultConstants = { + const enableDebugLog = config.enableDebugLog ?? false; + const enableDebugDisplay = config.enableDebugDisplay ?? false; + + const defaultConstants: Record< string, boolean > = { WP_SQLITE_AST_DRIVER: true, + WP_DEBUG: enableDebugLog || enableDebugDisplay, + WP_DEBUG_LOG: enableDebugLog, + WP_DEBUG_DISPLAY: enableDebugDisplay, }; let blueprintBundle: BlueprintBundle | undefined; diff --git a/apps/studio/src/components/content-tab-settings.tsx b/apps/studio/src/components/content-tab-settings.tsx index d9f799281f..8d8dd86d2a 100644 --- a/apps/studio/src/components/content-tab-settings.tsx +++ b/apps/studio/src/components/content-tab-settings.tsx @@ -143,9 +143,20 @@ export function ContentTabSettings( { selectedSite }: ContentTabSettingsProps ) { selectedSite.phpVersion } +