|
| 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. |
0 commit comments