Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
31 changes: 31 additions & 0 deletions packages/docs/site/docs/blueprints/08-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,37 @@ blueprint={{
]
}} />

## How to work with WP-CLI on Playground

To run WP-CLI commands on a Playground instance, you need to set up two things: mount the `/wordpress/` directory to your local filesystem and ensure the SQLite database integration is correctly configured. These steps allow WP-CLI to recognize the site as a valid WordPress installation and connect to its database.

Playground uses an internal SQLite database integration that isn't persisted when the site is mounted. Therefore, you must explicitly install and configure this plugin in your Blueprint to ensure a database connection.

The following Blueprint snippet handles this setup:

<BlueprintExample blueprint={{
"steps": [
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "sqlite-database-integration"
}
},
{
"step": "cp",
"fromPath": "/wordpress/wp-content/plugins/sqlite-database-integration/db.copy",
"toPath": "/wordpress/wp-content/db.php"
},
{
"step": "activatePlugin",
"pluginPath": "/wordpress/wp-content/plugins/sqlite-database-integration"
}
]
}} />

For a detailed explanation of why this is needed, refer to the [Troubleshoot and Debug Blueprints](/blueprints/troubleshoot-and-debug#wp-cli-error-establishing-a-database-connection-on-mounted-sites) section.

## Showcase a product demo

<BlueprintExample noButton blueprint={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,36 @@ When you build Blueprints, you might run into issues. Here are tips and tools to
## Review Common gotchas

- Require `wp-load`: to run a WordPress PHP function using the `runPHP` step, you’d need to require [wp-load.php](https://github.com/WordPress/WordPress/blob/master/wp-load.php). So, the value of the `code` key should start with `"<?php require_once('wordpress/wp-load.php'); REST_OF_YOUR_CODE"`.
- Enable `networking`: to access wp.org assets (themes, plugins, blocks, or patterns), or load a stylesheet using [add_editor_style()](https://developer.wordpress.org/reference/functions/add_editor_style/) (say, when [creating a custom block style](https://developer.wordpress.org/news/2023/02/creating-custom-block-styles-in-wordpress-themes)), you’d need to enable the `networking` option: `"features": {"networking": true}`.

## Common Issues and Solutions

### WP-CLI: Error Establishing a Database Connection on Mounted Sites

When using `wp-cli` with a mounted Playground site (e.g., via `--mount-before-install`), you might encounter an "Error establishing a database connection." This happens because WordPress Playground loads the SQLite database integration plugin from its internal files by default, not from the mounted directory, meaning it's not persisted for external `wp-cli` calls.

To resolve this, you need to explicitly install and configure the SQLite database integration plugin within your Blueprint.

**Solution:** Add the following steps to your Blueprint:

```json
{
"plugins": [ "sqlite-database-integration" ]
}
```

**Example Usage:**

To test this locally, combine the Blueprint with your Playground CLI command:

```bash
mkdir wordpress
# Ensure your blueprint with the above steps is saved as, for example, './blueprint.json'
npx @wp-playground/cli server --mount-before-install=wordpress:/wordpress --blueprint=./blueprint.json
cd wordpress
wp post list
```

This will ensure the SQLite plugin is installed correctly and configured within your mounted WordPress site, allowing `wp-cli` commands to function correctly.

## Blueprints Builder

Expand Down Expand Up @@ -46,7 +75,7 @@ Full list of methods we can use is available [here](/api/client/interface/Playgr

## Check for errors in the browser console

If your Blueprint isn’t running as expected, open the browser developer tools to see if there are any errors.
If your Blueprint isn’t running as expected, open the browser developer tools to check for any errors.

To open the developer tools in Chrome, Firefox, Safari\*, and Edge: press `Ctrl + Shift + I` on Windows/Linux or `Cmd + Option + I` on macOS.

Expand Down