Skip to content

Commit d21027b

Browse files
authored
Merge pull request #1 from lightspeedwp/copilot/scaffold-multi-block-plugin
WordPress multi-block plugin scaffold with CPT, taxonomies, SCF fields, and block bindings
2 parents 4801bb6 + fa46b4f commit d21027b

File tree

111 files changed

+7456
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+7456
-43
lines changed

.gitignore

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,40 @@
1-
# Wordpress - ignore core, configuration, examples, uploads and logs.
2-
# https://github.com/github/gitignore/blob/main/WordPress.gitignore
3-
4-
# Core
5-
#
6-
# Note: if you want to stage/commit WP core files
7-
# you can delete this whole section/until Configuration.
8-
/wp-admin/
9-
/wp-content/index.php
10-
/wp-content/languages
11-
/wp-content/plugins/index.php
12-
/wp-content/themes/index.php
13-
/wp-includes/
14-
/index.php
15-
/license.txt
16-
/readme.html
17-
/wp-*.php
18-
/xmlrpc.php
19-
20-
# Configuration
21-
wp-config.php
22-
23-
# Example themes
24-
/wp-content/themes/twenty*/
25-
26-
# Example plugin
27-
/wp-content/plugins/hello.php
28-
29-
# Uploads
30-
/wp-content/uploads/
1+
# Dependencies
2+
node_modules/
3+
vendor/
4+
5+
# Build output
6+
build/
317

328
# Log files
339
*.log
3410

35-
# htaccess
36-
/.htaccess
11+
# OS files
12+
.DS_Store
13+
Thumbs.db
14+
15+
# IDE files
16+
.idea/
17+
.vscode/
18+
*.swp
19+
*.swo
20+
21+
# WordPress environment
22+
.wp-env/
23+
24+
# Composer lock (optional for scaffold)
25+
composer.lock
26+
27+
# NPM package lock (optional for scaffold)
28+
package-lock.json
29+
30+
# Local development
31+
.env
32+
.env.local
3733

38-
# All plugins
39-
#
40-
# Note: If you wish to whitelist plugins,
41-
# uncomment the next line
42-
#/wp-content/plugins
34+
# Test coverage
35+
coverage/
36+
.phpunit.result.cache
4337

44-
# All themes
45-
#
46-
# Note: If you wish to whitelist themes,
47-
# uncomment the next line
48-
#/wp-content/themes
38+
# Temporary files
39+
*.tmp
40+
*.temp

.wp-env.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"core": "WordPress/WordPress#6.5",
3+
"phpVersion": "8.0",
4+
"plugins": [
5+
"."
6+
],
7+
"themes": [
8+
"WordPress/theme-developer-resources#trunk"
9+
],
10+
"mappings": {
11+
"wp-content/plugins/{{slug}}": "."
12+
},
13+
"config": {
14+
"WP_DEBUG": true,
15+
"WP_DEBUG_LOG": true,
16+
"SCRIPT_DEBUG": true
17+
},
18+
"lifecycleScripts": {
19+
"afterStart": "wp plugin activate {{slug}}"
20+
}
21+
}

README.md

Lines changed: 179 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,179 @@
1-
# multi-block-plugin-scaffold
1+
# {{name}}
2+
3+
{{description}}
4+
5+
## Description
6+
7+
A multi-block WordPress plugin scaffold with support for:
8+
9+
- **Multiple Gutenberg blocks** (Card, Collection, Slider, Featured)
10+
- **Custom Post Types** with block templates
11+
- **Custom Taxonomies**
12+
- **Custom Fields** via Secure Custom Fields (SCF) with repeater support
13+
- **Block Patterns** and Template Parts
14+
- **Block Bindings** for dynamic content
15+
- **Shared React components** (Slider, PostSelector, Gallery, etc.)
16+
17+
## Requirements
18+
19+
- WordPress 6.5+
20+
- PHP 8.0+
21+
- Node.js 18+
22+
- [Secure Custom Fields](https://wordpress.org/plugins/secure-custom-fields/) plugin
23+
24+
## Installation
25+
26+
1. Clone this repository to your WordPress plugins directory:
27+
```bash
28+
cd wp-content/plugins/
29+
git clone https://github.com/{{author}}/{{slug}}.git
30+
```
31+
32+
2. Install dependencies:
33+
```bash
34+
cd {{slug}}
35+
npm install
36+
composer install
37+
```
38+
39+
3. Build the plugin:
40+
```bash
41+
npm run build
42+
```
43+
44+
4. Activate the plugin in WordPress admin.
45+
46+
## Development
47+
48+
### Start development server
49+
50+
```bash
51+
npm start
52+
```
53+
54+
### Build for production
55+
56+
```bash
57+
npm run build
58+
```
59+
60+
### Linting
61+
62+
```bash
63+
npm run lint:js
64+
npm run lint:css
65+
composer phpcs
66+
```
67+
68+
### Testing
69+
70+
```bash
71+
# JavaScript tests
72+
npm run test:unit
73+
74+
# PHP tests
75+
composer test
76+
77+
# E2E tests (requires wp-env)
78+
npm run test:e2e
79+
```
80+
81+
### Local development with wp-env
82+
83+
```bash
84+
npx @wordpress/env start
85+
```
86+
87+
## Structure
88+
89+
```
90+
{{slug}}/
91+
├── {{slug}}.php # Main plugin file
92+
├── uninstall.php # Cleanup on uninstall
93+
├── inc/ # PHP classes
94+
│ ├── class-post-types.php
95+
│ ├── class-taxonomies.php
96+
│ ├── class-fields.php
97+
│ ├── class-repeater-fields.php
98+
│ ├── class-block-bindings.php
99+
│ ├── class-block-templates.php
100+
│ └── class-patterns.php
101+
├── src/ # Source files
102+
│ ├── blocks/ # Block source
103+
│ │ ├── {{slug}}-card/
104+
│ │ ├── {{slug}}-collection/
105+
│ │ ├── {{slug}}-slider/
106+
│ │ └── {{slug}}-featured/
107+
│ ├── components/ # Shared components
108+
│ ├── hooks/ # Custom hooks
109+
│ └── utils/ # Utilities
110+
├── patterns/ # Block patterns
111+
├── templates/ # Block templates
112+
├── parts/ # Template parts
113+
└── tests/ # Test files
114+
```
115+
116+
## Blocks
117+
118+
### {{name}} Card
119+
120+
Display a single post in a card layout.
121+
122+
### {{name}} Collection
123+
124+
Display a collection of posts with:
125+
- Grid, list, or slider layout
126+
- Taxonomy filtering
127+
- Featured posts filter
128+
- Pagination support
129+
130+
### {{name}} Slider
131+
132+
Display posts or custom slides in a carousel with:
133+
- Autoplay
134+
- Navigation dots and arrows
135+
- Touch/swipe support
136+
- Keyboard navigation
137+
138+
### Featured {{name_plural}}
139+
140+
Highlight featured posts with:
141+
- Grid layout
142+
- Featured-first layout
143+
- Hero layout
144+
145+
## Custom Fields (SCF)
146+
147+
The plugin registers the following custom fields:
148+
149+
- **Subtitle** - Text field
150+
- **Featured** - True/False toggle
151+
- **Gallery** - Image gallery
152+
- **Related Posts** - Post relationship
153+
- **Slides** - Repeater field for slider content
154+
- **Sections** - Flexible content for page sections
155+
156+
## Block Bindings
157+
158+
Use the `{{namespace}}/fields` binding source to display field values:
159+
160+
```html
161+
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"{{namespace}}/fields","args":{"key":"{{slug}}_subtitle"}}}}} -->
162+
<p></p>
163+
<!-- /wp:paragraph -->
164+
```
165+
166+
## Mustache Variables
167+
168+
This scaffold uses Mustache-style variables for customization:
169+
170+
| Variable | Description |
171+
|----------|-------------|
172+
| `{{slug}}` | Plugin slug (kebab-case) |
173+
| `{{name}}` | Plugin display name |
174+
| `{{namespace}}` | Plugin namespace |
175+
| `{{textdomain}}` | Text domain |
176+
177+
## License
178+
179+
{{license}}

bin/build.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Build script for {{name}}.
5+
*
6+
* @package {{namespace}}
7+
*/
8+
9+
const { execSync } = require( 'child_process' );
10+
const path = require( 'path' );
11+
const fs = require( 'fs' );
12+
13+
const rootDir = path.resolve( __dirname, '..' );
14+
15+
console.log( '🚀 Building {{name}}...\n' );
16+
17+
// Clean build directory.
18+
const buildDir = path.join( rootDir, 'build' );
19+
if ( fs.existsSync( buildDir ) ) {
20+
fs.rmSync( buildDir, { recursive: true } );
21+
}
22+
23+
// Run webpack build.
24+
try {
25+
execSync( 'npm run build', {
26+
cwd: rootDir,
27+
stdio: 'inherit',
28+
} );
29+
} catch ( error ) {
30+
console.error( '❌ Build failed:', error.message );
31+
process.exit( 1 );
32+
}
33+
34+
console.log( '\n✅ Build complete!' );

0 commit comments

Comments
 (0)