From 99dc3224cb14de2f8ecb703ae338233c8491902a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 1 Oct 2025 16:46:45 +0200 Subject: [PATCH 1/2] [PHP Playground] Attach client to http://playground.wordpress.net/remote.html --- .../php-playground/components/PlaygroundManager.tsx | 10 ++++------ .../website-extras/src/php-playground/constants.ts | 6 ------ .../website-extras/src/php-playground/store.ts | 5 +++-- packages/playground/wordpress/src/index.ts | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx b/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx index 8afcfff62d..1dc5799b58 100644 --- a/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx +++ b/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx @@ -1,10 +1,6 @@ import { useEffect, useRef } from 'react'; import { startPlaygroundWeb } from '@wp-playground/client'; -import { - DEFAULT_URL_PREFIX, - DEFAULT_WORKSPACE_DIR, - DEFAULT_WP_REMOTE, -} from '../constants'; +import { DEFAULT_URL_PREFIX, DEFAULT_WORKSPACE_DIR } from '../constants'; import { useAppDispatch, useAppSelector } from '../hooks'; import { applyUrlState, @@ -19,6 +15,8 @@ import { setCurrentPath } from '../store'; import { loadStateFromURL, saveStateToURL } from '../url-state'; import { playgroundRuntime } from '../runtime'; import { logger } from '@php-wasm/logger'; +// @ts-expect-error +import { getRemoteUrl } from 'virtual:website-config'; export const PlaygroundManager = () => { const dispatch = useAppDispatch(); @@ -120,7 +118,7 @@ export const PlaygroundManager = () => { try { const clientInstance = await startPlaygroundWeb({ iframe: previewIframe, - remoteUrl: DEFAULT_WP_REMOTE, + remoteUrl: getRemoteUrl(), // blueprint: { // preferredVersions: { // wp: wpVersionRef.current, diff --git a/packages/playground/website-extras/src/php-playground/constants.ts b/packages/playground/website-extras/src/php-playground/constants.ts index d3800462c4..060357b0b5 100644 --- a/packages/playground/website-extras/src/php-playground/constants.ts +++ b/packages/playground/website-extras/src/php-playground/constants.ts @@ -1,9 +1,3 @@ -export const DEFAULT_PHP_VERSION = '8.4'; -export const DEFAULT_WP_VERSION = '6.8'; -// @TODO: Use URL imported from vite build-time config -export const DEFAULT_WP_REMOTE = 'http://127.0.0.1:5400/remote.html'; -// export const DEFAULT_WP_REMOTE = 'https://playground.wordpress.net/remote.html'; - // @TODO: Get rid of the hardcoded initial path, always source cwd from the client. export const DEFAULT_WORKSPACE_DIR = '/wordpress/workspace'; export const DEFAULT_URL_PREFIX = '/workspace'; diff --git a/packages/playground/website-extras/src/php-playground/store.ts b/packages/playground/website-extras/src/php-playground/store.ts index 44617ca98c..3194789b9b 100644 --- a/packages/playground/website-extras/src/php-playground/store.ts +++ b/packages/playground/website-extras/src/php-playground/store.ts @@ -6,7 +6,8 @@ import { import type { PlaygroundClient } from '@wp-playground/client'; import { SupportedPHPVersionsList } from '@wp-playground/client'; -import { DEFAULT_CODE, DEFAULT_PHP_VERSION } from './constants'; +import { DEFAULT_CODE } from './constants'; +import { RecommendedPHPVersion } from '@wp-playground/common'; export type BootStatus = 'idle' | 'booting' | 'ready' | 'error'; @@ -28,7 +29,7 @@ export interface PlaygroundState { const initialState: PlaygroundState = { code: DEFAULT_CODE, currentPath: null, - phpVersion: DEFAULT_PHP_VERSION, + phpVersion: RecommendedPHPVersion, wpVersion: 'latest', phpVersions: SupportedPHPVersionsList, wpVersions: [], diff --git a/packages/playground/wordpress/src/index.ts b/packages/playground/wordpress/src/index.ts index ed8cdf717c..df0fbcfb4d 100644 --- a/packages/playground/wordpress/src/index.ts +++ b/packages/playground/wordpress/src/index.ts @@ -597,7 +597,7 @@ export async function unzipWordPress(php: PHP, wpZip: File) { '/' ); logger.warn( - `Skipping ${wpPath} because something exists at the target path.` + `Cannot unzip WordPress files at ${target}: ${wpPath} already exists.` ); return; } From 3171d303ebba6a527957a81c487f26ace89a0f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Wed, 1 Oct 2025 17:03:54 +0200 Subject: [PATCH 2/2] copypaste getRemoteUrl --- .../php-playground/components/PlaygroundManager.tsx | 10 ++++++---- .../website-extras/src/php-playground/constants.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx b/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx index 1dc5799b58..882f47f745 100644 --- a/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx +++ b/packages/playground/website-extras/src/php-playground/components/PlaygroundManager.tsx @@ -1,6 +1,10 @@ import { useEffect, useRef } from 'react'; import { startPlaygroundWeb } from '@wp-playground/client'; -import { DEFAULT_URL_PREFIX, DEFAULT_WORKSPACE_DIR } from '../constants'; +import { + DEFAULT_URL_PREFIX, + DEFAULT_WORKSPACE_DIR, + getRemoteUrl, +} from '../constants'; import { useAppDispatch, useAppSelector } from '../hooks'; import { applyUrlState, @@ -15,8 +19,6 @@ import { setCurrentPath } from '../store'; import { loadStateFromURL, saveStateToURL } from '../url-state'; import { playgroundRuntime } from '../runtime'; import { logger } from '@php-wasm/logger'; -// @ts-expect-error -import { getRemoteUrl } from 'virtual:website-config'; export const PlaygroundManager = () => { const dispatch = useAppDispatch(); @@ -118,7 +120,7 @@ export const PlaygroundManager = () => { try { const clientInstance = await startPlaygroundWeb({ iframe: previewIframe, - remoteUrl: getRemoteUrl(), + remoteUrl: getRemoteUrl().toString(), // blueprint: { // preferredVersions: { // wp: wpVersionRef.current, diff --git a/packages/playground/website-extras/src/php-playground/constants.ts b/packages/playground/website-extras/src/php-playground/constants.ts index 060357b0b5..b7517684e9 100644 --- a/packages/playground/website-extras/src/php-playground/constants.ts +++ b/packages/playground/website-extras/src/php-playground/constants.ts @@ -1,3 +1,6 @@ +// @ts-expect-error +import { buildVersion } from 'virtual:website-config'; + // @TODO: Get rid of the hardcoded initial path, always source cwd from the client. export const DEFAULT_WORKSPACE_DIR = '/wordpress/workspace'; export const DEFAULT_URL_PREFIX = '/workspace'; @@ -15,3 +18,10 @@ $html_processor = WP_HTML_Processor::create_fragment('

Hey!

') $html_processor->next_tag(); var_dump($html_processor->get_tag()); ?>`; + +export function getRemoteUrl() { + const remoteUrl = new URL(window.location.origin); + remoteUrl.pathname = '/remote.html'; + remoteUrl.searchParams.set('v', buildVersion); + return remoteUrl; +}