https://github.com/maximeculea/gutenberg-patterns-sync
Export and import block patterns (wp_block) as JSON via WP-CLI. Dev‑oriented to sync local patterns with other environments (staging, production).
https://github.com/maximeculea/gutenberg-patterns-sync
gutenberg gutenberg-patterns wordpress wordpress-development wp-cli wpcli
Last synced: 7 months ago
JSON representation
Export and import block patterns (wp_block) as JSON via WP-CLI. Dev‑oriented to sync local patterns with other environments (staging, production).
- Host: GitHub
- URL: https://github.com/maximeculea/gutenberg-patterns-sync
- Owner: MaximeCulea
- License: gpl-3.0
- Created: 2025-08-27T14:59:04.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-08-27T15:18:46.000Z (7 months ago)
- Last Synced: 2025-08-28T00:19:39.010Z (7 months ago)
- Topics: gutenberg, gutenberg-patterns, wordpress, wordpress-development, wp-cli, wpcli
- Language: PHP
- Homepage: https://maximeculea.fr
- Size: 25.4 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gutenberg Patterns Sync (Export/Import)
Dev‑oriented plugin to sync patterns from local with other environments (staging, production) by exporting and importing block patterns (wp_block) as JSON via WP‑CLI.
By default, stores these JSON files in the current theme's patterns/blocks-sync directory. It checks existing patterns to handle create/updates instead of hard‑deleting each time, which helps keep references in the DB and code stable.
Also, for each pattern, it keeps synced (or not) status, block categories.
## Requirements
- WordPress 6.0+
- PHP 7.4+
- WP-CLI available in the environment
## Installation
### As a regular plugin
This package is a regular WordPress plugin. You can install and activate it like any other plugin.
- Copy this folder into `wp-content/plugins/gutenberg-patterns-sync` on your site.
- In WP Admin → Plugins, activate “Gutenberg Patterns Sync”.
### Via Composer (as MU‑plugin)
You can install by Composer, it is designed to be installed as a MU plugin under `wp-content/mu-plugins/` (developer‑oriented).
#### From Packagist
Do `composer require maximeculea/gutenberg-patterns-sync`
#### From Github
- Add into your composer.json `{ "type": "vcs", "url": "https://github.com/MaximeCulea/gutenberg-patterns-sync" }`
- Include `"maximeculea/gutenberg-patterns-sync": "dev-master"` in your composer file as require
- Before use, launch `composer update`
## Commands
- `wp patterns export` — Export all published patterns (`wp_block` posts) to JSON files.
- `wp patterns import` — Import patterns (`wp_block` posts) from JSON files and optionally delete missing ones.
### Export
```
wp patterns export [--dir=] [--no-pretty] [--prefix=]
```
Options:
- `--dir=`: Destination directory. Default is current theme: `/patterns/blocks-sync`.
- `--no-pretty`: Disable pretty-printed JSON (pretty-print is enabled by default).
- `--prefix=`: Prefix for the `slug` field inside JSON (e.g. `mytheme`). Defaults to the active theme textdomain.
Output files are named `.json` and contain:
```
{
"title": "...",
"slug": "/",
"content": "...",
"categories": ["..."],
"syncStatus": "synced" | "unsynced"
}
```
### Import
```
wp patterns import [--dir=] [--dry-run] [--no-verbose]
```
Options:
- `--dir=`: Source directory. Default is current theme: `/patterns/blocks-sync`.
- `--dry-run`: Show actions without applying changes.
- `--no-verbose`: Reduce log noise.
Behavior:
- Creates or updates by slug.
- Assigns `wp_pattern_category` terms (creates them if missing).
- Preserves sync status (`wp_pattern_sync_status` post meta).
- Deletes existing `wp_block` posts not present in the source directory (unless `--dry-run` is used).
## License
© Maxime Culea. Gutenberg Patterns Sync is licensed under GPL-3.0+.