Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ vendor/*
/fastlane/report.xml
/fastlane/README.md

# Include the vendored copy of wp-now in our repo
!vendor/wp-now

# CLI npm artifacts
cli/vendor/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Blueprint } from '@wp-playground/blueprints';
import { RunCLIArgs } from '@wp-playground/cli';
import type { RunCLIArgs } from '@wp-playground/cli';
import type { Blueprint } from 'common/types/blueprint';

/**
* Sanitizes a Blueprint step to remove sensitive data while keeping useful debugging info.
Expand Down
2 changes: 1 addition & 1 deletion cli/wordpress-server-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {
OverlayFilesystem,
InMemoryFilesystem,
} from '@wp-playground/storage';
import { sanitizeRunCLIArgs } from 'common/lib/cli-args-sanitizer';
import { isWordPressDirectory } from 'common/lib/fs-utils';
import { getMuPlugins } from 'common/lib/mu-plugins';
import { formatPlaygroundCliMessage } from 'common/lib/playground-cli-messages';
import { isWordPressDevVersion } from 'common/lib/wordpress-version-utils';
import { z } from 'zod';
import { sanitizeRunCLIArgs } from 'cli/lib/cli-args-sanitizer';
import { getSqliteCommandPath, getWpCliPharPath } from 'cli/lib/server-files';
import {
ServerConfig,
Expand Down
5 changes: 3 additions & 2 deletions common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RecommendedPHPVersion } from '@wp-playground/common';
import { RecommendedPHPVersion } from './types/php-versions';

// Time constants
export const HOUR_MS = 1000 * 60 * 60;
Expand Down Expand Up @@ -27,7 +27,8 @@ export const PLAYGROUND_CLI_ACTIVITY_CHECK_INTERVAL = 5 * 1000; // Check for ina
// Custom domains
export const DEFAULT_CUSTOM_DOMAIN_SUFFIX = '.wp.local';

// WordPress Playground constants
// WordPress constants
export const MINIMUM_WORDPRESS_VERSION = '6.2.1' as const; // https://wordpress.github.io/wordpress-playground/blueprints/examples/#load-an-older-wordpress-version
export const DEFAULT_WORDPRESS_VERSION = 'latest' as const;
export const DEFAULT_PHP_VERSION: typeof RecommendedPHPVersion = RecommendedPHPVersion;
export const SQLITE_FILENAME = 'sqlite-database-integration' as const;
1 change: 1 addition & 0 deletions common/types/blueprint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { Blueprint, BlueprintV1Declaration, StepDefinition } from '@wp-playground/blueprints';
29 changes: 29 additions & 0 deletions common/types/php-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Local type definitions for PHP versions.
* These replace imports from @php-wasm/universal to avoid bundling PHP-WASM in the desktop app.
*
* Note: Keep these values in sync with @php-wasm/universal if the upstream package changes.
*/

export const SupportedPHPVersions = [
'8.4',
'8.3',
'8.2',
'8.1',
'8.0',
'7.4',
'7.3',
'7.2',
] as const;

export const LatestSupportedPHPVersion = '8.4' as const;

export const SupportedPHPVersionsList: string[] = [ ...SupportedPHPVersions ];

export type SupportedPHPVersion = ( typeof SupportedPHPVersions )[ number ];

/**
* The recommended PHP version for new sites.
* This replaces RecommendedPHPVersion from @wp-playground/common.
*/
export const RecommendedPHPVersion: SupportedPHPVersion = '8.3';
57 changes: 22 additions & 35 deletions docs/ai-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ See the site management commands (create, list, start, etc) in `cli/commands/sit

## WordPress Studio - Architecture Overview

WordPress Studio is a desktop application for creating, managing, and testing WordPress sites locally. It's built as an Electron desktop application with a React renderer, powered by WordPress Playground and PHP WASM.
WordPress Studio is a desktop application for creating, managing, and testing WordPress sites locally. It's built as an Electron desktop application with a React renderer. The CLI component uses WordPress Playground (PHP WASM) to run WordPress sites.

## High-Level Architecture

Expand All @@ -162,7 +162,6 @@ WordPress Studio is a desktop application for creating, managing, and testing Wo
├─────────────────────────────────────────────────────┤
│ • IPC Handler Layer (ipc-handlers.ts) │
│ • Site Server Management (site-server.ts) │
│ • WordPress Provider Abstraction │
│ • Storage & User Data Management │
│ • OAuth / Authentication │
│ • Sync Operations (WordPress.com / Pressable) │
Expand All @@ -175,11 +174,11 @@ WordPress Studio is a desktop application for creating, managing, and testing Wo
└────────────────┬─┘ └───────────────┘
┌──────────────────────▼──────────────────────┐
WORDPRESS PROVIDERS
STUDIO CLI
├──────────────────────────────────────────────┤
│ • Playground-CLI Provider (with Blueprints) │
│ • WP-Now Provider (fallback)
│ • PHP WASM Runtime
│ • WordPress Playground (@wp-playground/cli) │
│ • PHP WASM Runtime (@php-wasm/*)
│ • Blueprint Support
│ • Server Process Management │
└─────────────────────────────────────────────┘
```
Expand All @@ -198,12 +197,10 @@ WordPress Studio is a desktop application for creating, managing, and testing Wo
- **`storage/`** - User data persistence and app state storage
- **`stores/`** - Redux RTK stores (centralized state management)
- **`lib/`** - Utility libraries and business logic
- `wordpress-provider/` - Abstraction layer for WordPress runtime (Playground vs WP-Now)
- `import-export/` - Site backup/restore functionality
- `sync/` - WordPress.com sync operations
- `certificate-manager.ts` - HTTPS certificate generation for custom domains
- `proxy-server.ts` - Local HTTP proxy for custom domain routing
- `wp-cli-process.ts` - WP-CLI command execution wrapper
- **`components/`** - React UI components
- `root.tsx` - Root component with all context providers
- `app.tsx` - Main app layout
Expand Down Expand Up @@ -266,15 +263,11 @@ window.ipcApi.installStudioCli() // Install the CLI
window.ipcApi.uninstallStudioCli() // Uninstall the CLI
```

### 3. WordPress Provider Pattern (Strategy Pattern)
Two implementations for running WordPress:
- **PlaygroundCliProvider**: Uses `@wp-playground/cli` with Blueprint support (feature-gated)
- **WpNowProvider**: Fallback provider with core functionality

Both implement the `WordPressProvider` interface with methods:
- `startServer()` - Start a WordPress site
- `setupWordPressSite()` - Initialize WordPress installation
- `createServerProcess()` - Create server child process
### 3. CLI Server Process
The desktop app delegates WordPress operations to the CLI:
- **CliServerProcess** (`src/modules/cli/lib/cli-server-process.ts`): Spawns CLI as child process
- **Site operations**: Start/stop servers, run WP-CLI commands
- **Blueprint support**: Passed to CLI for site initialization

### 4. Redux Store Architecture (RTK)
```typescript
Expand All @@ -284,7 +277,6 @@ Both implement the `WordPressProvider` interface with methods:
- connectedSites: Connected WordPress.com sites
- snapshot: Site snapshots/backups
- onboarding: First-run experience state
- provider constants: WordPress/PHP versions
- RTK Query APIs for data fetching:
- wpcomApi: WordPress.com API calls
- installedAppsApi: System apps detection, CLI installation status
Expand Down Expand Up @@ -338,11 +330,12 @@ Redux State Update / Re-render

### Main Process
- **Electron 38** - Desktop framework
- **express** - Lightweight HTTP server for sites

### CLI (runs WordPress sites)
- **@wp-playground/cli** - WordPress Playground CLI
- **@php-wasm/node** - PHP runtime in Node.js
- **@php-wasm/universal** - Universal PHP WASM
- **@wp-playground/blueprints** - Blueprint compilation
- **@wp-playground/cli** - Playground CLI integration
- **express** - Lightweight HTTP server for sites

### Development
- **electron-vite** - Electron build orchestration
Expand Down Expand Up @@ -410,19 +403,13 @@ Storage is protected by file locking (`lockAppdata()` / `unlockAppdata()`).
- Renderer uses `<I18nProvider>` context
- CLI translates via `loadTranslations()` in CLI bootstrap

## WordPress Playground Integration

### Blueprints
- Complex site configurations declaratively defined
- Compiled to runtime executable by `@wp-playground/blueprints`
- Feature detection/filtering: `filterUnsupportedBlueprintFeatures()` in `src/lib/blueprint-features.ts`
- Passed to server startup for automatic setup
## WordPress Playground Integration (CLI)

### PHP WASM Runtime
- `@php-wasm/node` provides PHP runtime in Node.js
- Runs in child processes via `WorkerThreads`
- WP-CLI integration: `WpCliProcess` class wraps CLI commands
- Server process: Handles PHP execution and WordPress HTTP requests
The CLI component uses WordPress Playground to run WordPress sites:
- **@wp-playground/cli**: Runs WordPress in Node.js using PHP WASM
- **Blueprints**: Declarative site configurations passed to CLI for setup
- **Feature filtering**: `filterUnsupportedBlueprintFeatures()` removes unsupported steps
- The desktop app spawns the CLI as a child process via `CliServerProcess`

## Sync & WordPress.com Integration

Expand Down Expand Up @@ -474,12 +461,12 @@ Local component state used for temporary UI interactions.

- **Code Splitting**: Vendor and Sentry chunks extracted separately
- **CSS Code Split**: Separate CSS files for better caching
- **WASM Bundling**: WASM files included as external assets
- **CLI Separation**: PHP WASM (~1GB) only in CLI, not in desktop app bundle
- **Port Finder**: Efficient port availability checking with caching
- **Snapshot System**: Browser-like snapshots for fast site restoration

---

Last Updated: 2025-11-10
Last Updated: 2025-12-18
Repository: https://github.com/Automattic/studio
License: GPLv2 or later
Loading
Loading