Skip to content

Commit 49bb10e

Browse files
authored
Merge pull request #10 from imagewize/feature/rebuild-demo-script
Feature/rebuild Demo Script
2 parents e7e90b5 + 3c0073a commit 49bb10e

7 files changed

Lines changed: 419 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.4.0] - 2026-05-15
8+
9+
### Added
10+
11+
- **`scripts/rebuild-demo.php`** — WP-CLI script to rebuild demo pages from pattern PHP files. Renders each pattern file in the live WordPress context and overwrites the page's `post_content`, identical to a fresh block-editor insert. Supports:
12+
- Single-site and multisite configurations
13+
- Mapping page IDs to one or more pattern files (concatenated in order)
14+
- Optional push of custom `.html` templates to the WP database
15+
- Optional push of custom template parts (header, footer, etc.) to the WP database
16+
- Dry-run mode via `WP_REBUILD_DRY_RUN=1` environment variable
17+
- Works with any FSE block theme (not just Elayne)
18+
19+
### Changed
20+
21+
- Moved demo rebuild script documentation from `README.md` to `docs/demo-rebuild-script.md` for better organization
22+
- Added `docs/index.php` and `scripts/index.php` with "silence is golden" to prevent directory browsing
23+
724
## [2.3.1] - 2026-05-14
825

926
### Fixed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ Applied to `.html` files in `templates/` and `parts/` directories. These checks
333333

334334
The `check` command processes PHP pattern files. HTML template files use a different structure — raw block markup without PHP wrappers — and require different checks. In particular, WooCommerce 9.x+ changed the `save()` output for filter blocks to include empty `<div>` wrappers; templates written against older versions lack those wrappers and trigger client-side block validation errors that neither WP-CLI nor the PHP checker can catch.
335335

336+
## Demo Rebuild Script
337+
338+
For rebuilding demo pages from pattern PHP files, see the [Demo Rebuild Script guide](docs/demo-rebuild-script.md).
339+
336340
## Development
337341

338342
```bash

bin/pt-cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Imagewize\PtCli\Commands\Scaffold\StyleCreateCommand;
2222
use Imagewize\PtCli\Commands\TemplateCheckCommand;
2323
use Symfony\Component\Console\Application;
2424

25-
$application = new Application('pt-cli', '2.3.1');
25+
$application = new Application('pt-cli', '2.4.0');
2626
$application->add(new CheckCommand());
2727
$application->add(new TemplateCheckCommand());
2828
$application->add(new PatternCreateCommand());

docs/demo-rebuild-script.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Demo Rebuild Script
2+
3+
A WP-CLI script is included to rebuild demo pages from the latest pattern PHP files. It renders each pattern file in the live WordPress context and overwrites the page's `post_content` — identical to a fresh block-editor insert.
4+
5+
## Location
6+
7+
`scripts/rebuild-demo.php`
8+
9+
## Usage
10+
11+
Copy the script to your theme directory (e.g., `web/app/themes/your-theme/scripts/rebuild-demo.php`) and customize the `$page_map`, `$templates`, and `$template_parts` arrays.
12+
13+
```bash
14+
# Single-site usage (run from your WordPress root):
15+
wp --path=web/wp eval-file web/app/themes/your-theme/scripts/rebuild-demo.php
16+
17+
# Multisite usage — pass --url= to target the correct subsite AND pass the
18+
# subsite slug as a positional argument:
19+
wp --path=web/wp --url=example.com/store/ \
20+
eval-file web/app/themes/your-theme/scripts/rebuild-demo.php store
21+
22+
# Dry-run (shows what would be updated, no writes):
23+
WP_REBUILD_DRY_RUN=1 wp --path=web/wp \
24+
eval-file web/app/themes/your-theme/scripts/rebuild-demo.php
25+
```
26+
27+
## Configuration
28+
29+
Edit the script's arrays to map your page IDs to pattern files:
30+
31+
```php
32+
// Single-site
33+
$page_map = array(
34+
17 => array( 'patterns/hero-with-cta.php', 'patterns/features.php' ),
35+
20 => array( 'patterns/contact-with-form.php' ),
36+
);
37+
38+
// Multisite (nested by subsite slug)
39+
$page_map = array(
40+
'main' => array( 17 => array( 'patterns/hero-with-cta.php' ) ),
41+
'store' => array( 92 => array( 'patterns/woocommerce/woo-hero.php' ) ),
42+
);
43+
44+
// Optional: Push custom .html templates to WP database
45+
$templates = array(
46+
'archive-product' => 'templates/archive-product-custom.html',
47+
);
48+
49+
// Optional: Push custom template parts
50+
$template_parts = array(
51+
'header' => 'patterns/my-custom-header.php',
52+
'footer' => 'patterns/my-custom-footer.php',
53+
);
54+
```
55+
56+
## Important for multisite
57+
58+
Page IDs are per-subsite (not global). Always pass `--url=` so WP-CLI switches to the right blog context. Without it, `get_template_directory()` and page IDs may resolve against the wrong subsite.

docs/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Silence is golden.

scripts/index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Silence is golden.

0 commit comments

Comments
 (0)