Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
"core": null,
"phpVersion": "8.3",
"themes": [ "." ],
"plugins": [ "https://downloads.wordpress.org/plugin/advanced-custom-fields.zip" ],
"config": {
"WP_DEBUG": true,
"WP_DEBUG_LOG": true,
"WP_DEBUG_DISPLAY": false,
"SCRIPT_DEBUG": true,
"WP_ENVIRONMENT_TYPE": "local",
"WP_DEVELOPMENT_MODE": "theme"
},
"lifecycleScripts": {
"afterStart": "wp-env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install --no-interaction"
Comment thread
firestar300 marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}
}
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,86 @@ Alternatively, you can use NPM.
npm install
```

## Local development with wp-env

BFF ships with a [wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/) configuration (`.wp-env.json`) to run a local WordPress instance with Docker.

### Requirements

- [Docker Desktop](https://www.docker.com/products/docker-desktop/) (or a compatible Docker runtime)
- Node.js (see [Requirements](#nodejs))

### Installing wp-env

You can run wp-env without a global install via `npx @wordpress/env`, or install the CLI once and use the `wp-env` command:

```bash
# Global install (npm or yarn)
npm install -g @wordpress/env
# or
yarn global add @wordpress/env
```

After installation, replace `npx @wordpress/env` with `wp-env` in the commands below.

### Getting started

From the theme root:

```bash
yarn
npx @wordpress/env start
# or, if wp-env is installed globally:
wp-env start
```

On first start, wp-env will:

- Spin up WordPress (PHP 8.3)
- Mount this theme from the current directory
- Install the [Advanced Custom Fields](https://wordpress.org/plugins/advanced-custom-fields/) plugin
- Run `composer install` in the theme via the `afterStart` lifecycle script

### URLs and credentials

| | |
|---|---|
| Site | http://localhost:8888 |
| Admin | http://localhost:8888/wp-admin |
| Username | `admin` |
| Password | `password` |

### Common commands

```bash
# Start the environment
npx @wordpress/env start # or: wp-env start

# Stop containers (data is preserved)
npx @wordpress/env stop # or: wp-env stop

# Remove containers and volumes
npx @wordpress/env destroy # or: wp-env destroy

# Run WP-CLI inside the environment
npx @wordpress/env run cli wp plugin list
# or: wp-env run cli wp plugin list

# Run a command in the theme directory
npx @wordpress/env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
# or: wp-env run cli --env-cwd=wp-content/themes/beapi-frontend-framework composer install
```

### Development workflow

With wp-env running, start the Webpack watcher in a second terminal:

```bash
yarn start
```

Changes to PHP, SCSS, and JavaScript assets are reflected after Webpack rebuilds. Theme PHP changes are picked up immediately thanks to the mounted volume.

## Configuration

The configurations files are in `config` directory.
Expand Down
16 changes: 16 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?php

/**
* Bootstrap the theme Composer autoloader when classes are not already available.
*
* Root projects (Bedrock, composer-scaffold-theme) usually register this namespace
* via their own autoload. Standalone setups (wp-env, theme-only) rely on vendor/.
*
* @since 5.4.0
*/
if ( ! class_exists( 'BEA\\Theme\\Framework\\Framework', false ) ) {
$autoloader = __DIR__ . '/vendor/autoload.php';

if ( file_exists( $autoloader ) ) {
require_once $autoloader;
}
}

/**
* Load all services
*/
Expand Down
Loading