Skip to main content

PlaygroundClient

The Playground Client interface.

Hierarchy

  • RemoteAPI<PlaygroundWorkerEndpoint & WebClientMixin>
    • PlaygroundClient

Index

Properties

absoluteUrl

absoluteUrl: Promise<string>
@inheritDoc

addEventListener

addEventListener: Remote<(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener) => void>

documentRoot

documentRoot: Promise<string>
@inheritDoc

isConnected

isConnected: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Resolves to true when the remote API is ready for Comlink communication, but not necessarily fully initialized yet.


      Returns Promise<void>

isReady

isReady: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Resolves to true when the remote API is declares it’s fully loaded and ready to be used.


      Returns Promise<void>

journalFSEvents

journalFSEvents: Remote<(root: string, callback: (op: FilesystemOperation) => void) => Promise<() => any> & (root: string, callback: (op: FilesystemOperation) => void) => Promise<() => any>>

onDownloadProgress

onDownloadProgress: Remote<(callback: (progress: CustomEvent<ProgressEvent<EventTarget>>) => void) => Promise<void>>

The onDownloadProgress event listener.

onMessage

onMessage: Remote<(listener: MessageListener) => void>
@inheritDoc

removeEventListener

removeEventListener: Remote<(eventType: request.end | request.error | runtime.initialized | runtime.beforedestroy, listener: PHPEventListener) => void>

replayFSJournal

replayFSJournal: Remote<(events: FilesystemOperation[]) => Promise<void> & (events: FilesystemOperation[]) => Promise<void>>

scope

scope: Promise<string>

A string representing the scope of the Playground instance.

wordPressVersion

wordPressVersion: Promise<string>

A string representing the version of WordPress being used.

Methods

bindOpfs

  • bindOpfs(...args: [opfs: FileSystemDirectoryHandle, onProgress?: SyncProgressCallback]): Promise<void>
  • Parameters

    • rest...args: [opfs: FileSystemDirectoryHandle, onProgress?: SyncProgressCallback]

    Returns Promise<void>

chdir

  • chdir(...args: [path: string]): Promise<void>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<void>

defineConstant

  • defineConstant(...args: [key: string, value: null | string | number | boolean]): Promise<void>
  • @inheritDoc

    Parameters

    • rest...args: [key: string, value: null | string | number | boolean]

    Returns Promise<void>

fileExists

  • fileExists(...args: [path: string]): Promise<false> | Promise<true>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<false> | Promise<true>

getCurrentURL

  • getCurrentURL(...args: []): Promise<string>
  • Gets the current URL.


    Parameters

    • rest...args: []

    Returns Promise<string>

getSupportedWordPressVersions

  • getSupportedWordPressVersions(...args: []): Promise<{ all: { 6.1: string; 6.2: string; 6.3: string; 6.4: string; 6.5: string; beta: string; nightly: string }; latest: string }>
  • Parameters

    • rest...args: []

    Returns Promise<{ all: { 6.1: string; 6.2: string; 6.3: string; 6.4: string; 6.5: string; beta: string; nightly: string }; latest: string }>

getWordPressModuleDetails

  • getWordPressModuleDetails(...args: []): Promise<{ majorVersion: string; staticAssetsDirectory: string }>

  • Parameters

    • rest...args: []

    Returns Promise<{ majorVersion: string; staticAssetsDirectory: string }>

    WordPress module details, including the static assets directory and default theme.

goTo

  • goTo(...args: [requestedPath: string]): Promise<void>
  • Navigates to the requested path.


    Parameters

    • rest...args: [requestedPath: string]

    Returns Promise<void>

internalUrlToPath

  • internalUrlToPath(...args: [internalUrl: string]): Promise<string>
  • Converts an absolute URL based at the PHPRequestHandler to a relative path without the server pathname and scope.


    Parameters

    • rest...args: [internalUrl: string]

      An absolute URL based at the PHPRequestHandler root.

    Returns Promise<string>

    The relative path.

isDir

  • isDir(...args: [path: string]): Promise<false> | Promise<true>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<false> | Promise<true>

listFiles

  • listFiles(...args: [path: string, options?: ListFilesOptions]): Promise<string[]>
  • Parameters

    • rest...args: [path: string, options?: ListFilesOptions]

    Returns Promise<string[]>

mkdir

  • mkdir(...args: [path: string]): Promise<void>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<void>

mkdirTree

  • mkdirTree(...args: [path: string]): Promise<void>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<void>

mv

  • mv(...args: [fromPath: string, toPath: string]): Promise<void>
  • Moves a file or directory in the PHP filesystem to a new location.


    Parameters

    • rest...args: [fromPath: string, toPath: string]

      The path to rename.

    Returns Promise<void>

onNavigation

  • onNavigation(...args: [fn: (url: string) => void]): Promise<void>
  • Sets the navigation event listener.


    Parameters

    • rest...args: [fn: (url: string) => void]

    Returns Promise<void>

pathToInternalUrl

  • pathToInternalUrl(...args: [path: string]): Promise<string>
  • Converts a path to an absolute URL based at the PHPRequestHandler root.


    Parameters

    • rest...args: [path: string]

      The server path to convert to an absolute URL.

    Returns Promise<string>

    The absolute URL.

readFileAsBuffer

  • readFileAsBuffer(...args: [path: string]): Promise<Uint8Array>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<Uint8Array>

readFileAsText

  • readFileAsText(...args: [path: string]): Promise<string>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<string>

reloadFilesFromOpfs

  • reloadFilesFromOpfs(...args: []): Promise<void>
  • Parameters

    • rest...args: []

    Returns Promise<void>

request

  • Serves the request – either by serving a static file, or by dispatching it to the PHP runtime.

    The request() method mode behaves like a web server and only works if the PHP was initialized with a requestHandler option (which the online version of WordPress Playground does by default).

    In the request mode, you pass an object containing the request information (method, headers, body, etc.) and the path to the PHP file to run:

    const php = PHP.load('7.4', {
    requestHandler: {
    documentRoot: "/www"
    }
    })
    php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
    const result = await php.request({
    method: "GET",
    headers: {
    "Content-Type": "text/plain"
    },
    body: "Hello world!",
    path: "/www/index.php"
    });
    // result.text === "Hello world!"

    The request() method cannot be used in conjunction with cli().


    Parameters

    • rest...args: [request: PHPRequest]

      PHP Request data.

    Returns Promise<PHPResponse>

resetVirtualOpfs

  • resetVirtualOpfs(...args: []): Promise<void>
  • Parameters

    • rest...args: []

    Returns Promise<void>

rmdir

  • rmdir(...args: [path: string, options?: RmDirOptions]): Promise<void>
  • Removes a directory from the PHP filesystem.


    Parameters

    • rest...args: [path: string, options?: RmDirOptions]

      The directory path to remove.

    Returns Promise<void>

run

setIframeSandboxFlags

  • setIframeSandboxFlags(...args: [flags: string[]]): Promise<void>
  • Sets the iframe sandbox flags.


    Parameters

    • rest...args: [flags: string[]]

    Returns Promise<void>

setLoaded

  • setLoaded(...args: []): Promise<void>
  • Sets the loaded state.


    Parameters

    • rest...args: []

    Returns Promise<void>

setPhpIniEntry

  • setPhpIniEntry(...args: [key: string, value: string]): Promise<void>
  • Parameters

    • rest...args: [key: string, value: string]

    Returns Promise<void>

setPhpIniPath

  • setPhpIniPath(...args: [path: string]): Promise<void>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<void>

setPrimaryPHP

  • setPrimaryPHP(...args: [php: WebPHP]): Promise<void>
  • Parameters

    • rest...args: [php: WebPHP]

    Returns Promise<void>

setProgress

  • setProgress(...args: [options: ProgressBarOptions]): Promise<void>
  • Sets the progress bar options.


    Parameters

    • rest...args: [options: ProgressBarOptions]

    Returns Promise<void>

setSapiName

  • setSapiName(...args: [newName: string]): Promise<void>
  • Parameters

    • rest...args: [newName: string]

    Returns Promise<void>

unlink

  • unlink(...args: [path: string]): Promise<void>
  • Parameters

    • rest...args: [path: string]

    Returns Promise<void>

writeFile

  • writeFile(...args: [path: string, data: string | Uint8Array]): Promise<void>
  • Parameters

    • rest...args: [path: string, data: string | Uint8Array]

    Returns Promise<void>