Skip to content

Commit dd2ec5c

Browse files
authored
Merge pull request #11 from lightspeedwp/feature/block-bindings
Fix dynamic block render callbacks and PHP function names
2 parents 08c577c + 5f845cb commit dd2ec5c

177 files changed

Lines changed: 5957 additions & 4881 deletions

File tree

Some content is hidden

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

.github/agents/generate-plugin.agent.md

Lines changed: 88 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
# SCF-Driven Content Model
2+
3+
All post types, taxonomies, and field groups are now output as individual JSON files in `scf-json/` and registered by Secure Custom Fields (SCF). No PHP registration code is generated for post types or taxonomies.
14
---
25
name: "Plugin Generator Agent"
36
description: Interactive agent that collects comprehensive requirements and generates a WordPress multi-block plugin with CPT, taxonomies, and SCF fields
4-
tools: ["semantic_search", "read_file", "grep_search", "file_search", "run_in_terminal", "create_file", "update_file", "delete_file", "move_file"]
7+
tools: ['vscode', 'execute', 'read', 'edit', 'search', 'web', 'github/delete_file', 'agent', 'ms-vscode.vscode-websearchforcopilot/websearch', 'todo']
58
permissions: ["read", "write", "execute", "shell", "filesystem"]
69
---
710

@@ -202,9 +205,35 @@ I will ask you about each taxonomy you want to create one by one.
202205

203206
### Stage 4: Custom Fields (SCF)
204207

205-
I'll help you design field groups. I can work from a simple list or an interactive process.
208+
I'll help you design field groups. The generator will create SCF JSON files that Secure Custom Fields automatically loads from the `scf-json/` directory.
209+
206210
For each field, please provide the **field label** (e.g., "Start Date") and the **field type** (e.g., `date_picker`). I will generate the field name automatically (e.g., `start_date`).
207211

212+
**How It Works:**
213+
- Fields from `plugin-config.json` are converted to SCF JSON format
214+
- Generated files are saved to `scf-json/group_{slug}_fields.json`
215+
- SCF automatically loads and registers these field groups from JSON files
216+
- No PHP code required - pure JSON configuration
217+
218+
**Configuration Options:**
219+
All fields support these common properties:
220+
- `name` — Field slug (lowercase with underscores)
221+
- `label` — Display label in admin
222+
- `type` — Field type (see below)
223+
- `instructions` — Help text shown below the field
224+
- `required` — Whether the field is required (true/false)
225+
- `default_value` — Default value for the field
226+
- `placeholder` — Placeholder text for text-based fields
227+
- `choices` — Options for select/radio/checkbox fields (object with key:value pairs)
228+
- `return_format` — Return format for certain field types (value, label, array, url, id, object)
229+
- `multiple` — Allow multiple selections (for select/post_object/user fields)
230+
- `allow_null` — Allow null/empty value
231+
232+
**Number Field Options:**
233+
- `min` — Minimum value
234+
- `max` — Maximum value
235+
- `step` — Step increment (default: 1)
236+
208237
**Example Field Request:**
209238
> "Add a 'Subtitle' text field, a 'Price' number field, and a 'Featured' true/false toggle."
210239
@@ -275,31 +304,15 @@ itinerary (repeater)
275304

276305
### Stage 6: Blocks Configuration
277306

278-
| Block | Purpose | Included |
279-
|-------|---------|----------|
280-
| `{{slug}}-card` | Single post card display | ✓ Default |
281-
| `{{slug}}-collection` | Query-based post grid | ✓ Default |
282-
| `{{slug}}-slider` | Carousel display | ✓ Default |
283-
| `{{slug}}-single` | Full post display | ✓ Default |
284-
| `{{slug}}-featured` | Featured posts section | ✓ Default |
285-
286-
**Block Configuration Options:**
287-
288-
For each block:
289-
- Category (common, text, media, design, widgets)
290-
- Icon (dashicon name)
291-
- Supports (align, anchor, className, color, spacing)
292-
- Variations (grid, list, slider layouts)
307+
**Note**: Block templates have been removed from the scaffold. Blocks should be implemented as patterns or custom code.
293308

294309
### Stage 7: Templates & Patterns
295310

296311
| Item | File | Include? |
297312
|------|------|----------|
298313
| Single template | `templates/single-{{slug}}.html` | ✓ Default |
299314
| Archive template | `templates/archive-{{slug}}.html` | ✓ Default |
300-
| Card pattern | `patterns/{{slug}}-card.php` | ✓ Default |
301315
| Grid pattern | `patterns/{{slug}}-grid.php` | ✓ Default |
302-
| Featured pattern | `patterns/{{slug}}-featured.php` | ✓ Default |
303316

304317
### Stage 8: Additional Features
305318

@@ -460,9 +473,9 @@ Which blocks do you want?
460473

461474
### Final Configuration
462475

463-
**User**: "All defaults plus the search block"
476+
**User**: "All defaults"
464477

465-
**Me**: "Adding search block.
478+
**Me**: "Using all defaults.
466479

467480
**Final Configuration Summary:**
468481

@@ -491,21 +504,14 @@ Fields:
491504
Repeater: features (feature_name, feature_icon)
492505

493506
Blocks:
494-
- real-estate-pro-card
495-
- real-estate-pro-collection
496-
- real-estate-pro-slider
497-
- real-estate-pro-single
498-
- real-estate-pro-featured
499-
- real-estate-pro-search
507+
- None (block templates removed - implement as patterns or custom code)
500508

501509
Templates:
502510
- single-real-estate-pro.html
503511
- archive-real-estate-pro.html
504512

505513
Patterns:
506-
- real-estate-pro-card.php
507514
- real-estate-pro-grid.php
508-
- real-estate-pro-featured.php
509515
```
510516
511517
**Ready to generate?** (yes/no/modify)"
@@ -517,25 +523,74 @@ Patterns:
517523
After generation, I can help with:
518524
519525
### 1. SCF Field Configuration
526+
527+
Field groups are automatically generated as JSON files:
528+
520529
```bash
521-
# Field groups will be in:
530+
# Field group JSON files:
522531
scf-json/group_{{slug}}_fields.json
532+
533+
# Schema for validation:
534+
.github/schemas/scf-field-group.schema.json
535+
```
536+
537+
**SCF Local JSON Benefits:**
538+
- Version control friendly
539+
- No database queries for field definitions
540+
- Easy to backup and sync across environments
541+
- Can be edited directly or via WordPress admin
542+
543+
The SCF_JSON class automatically configures the save/load paths so any field groups created in WordPress admin are saved to `scf-json/` and version controlled.
544+
545+
### 2. Post Types & Taxonomies via SCF Local JSON
546+
547+
Post types and taxonomies are defined using Secure Custom Fields' Local JSON format in the `scf-json/` directory:
548+
549+
```bash
550+
# Post type JSON configuration:
551+
scf-json/post-type-{{slug}}.json
552+
553+
# Taxonomy JSON configuration:
554+
scf-json/taxonomy-{{slug}}.json
555+
```
556+
557+
**SCF Post Type JSON Example:**
558+
```json
559+
{
560+
"key": "post_type_product",
561+
"title": "Product",
562+
"post_type": "product",
563+
"active": true,
564+
"labels": {
565+
"name": "Products",
566+
"singular_name": "Product"
567+
}
568+
}
523569
```
524570

525-
### 2. Block Customisation
571+
**SCF Local JSON Benefits:**
572+
- Native SCF format for post types, taxonomies, and fields
573+
- Automatic loading via SCF's Local JSON system
574+
- Version control friendly
575+
- No separate Content_Model_Manager needed
576+
- Edit in WordPress admin, saved automatically to JSON
577+
578+
The SCF_JSON class configures SCF to load post types, taxonomies, and field groups from `scf-json/` directory.
579+
580+
### 3. Block Customisation
526581
```bash
527582
# Edit block attributes and supports:
528583
src/blocks/{{slug}}-*/block.json
529584
```
530585

531-
### 3. Template Setup
586+
### 4. Template Setup
532587
```bash
533588
# Customise templates with block bindings:
534589
templates/single-{{slug}}.html
535590
templates/archive-{{slug}}.html
536591
```
537592

538-
### 4. Development Start
593+
### 5. Development Start
539594
```bash
540595
cd output-plugin
541596
composer install

.github/copilot-tasks.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ date: 2025-12-01
3232
**Status**: ✅ COMPLETED
3333

3434
- [x] **Custom Post Types**
35-
- Location: [inc/class-post-types.php](../inc/class-post-types.php)
35+
- Location: JSON files in [/scf-json/](../scf-json/) (post-type-{slug}.json)
3636
- Registers: {{slug}} post type with block editor support
3737

3838
- [x] **Custom Taxonomies**
39-
- Location: [inc/class-taxonomies.php](../inc/class-taxonomies.php)
39+
- Location: JSON files in [/scf-json/](../scf-json/) (taxonomy-{slug}.json)
4040
- Registers: {{slug}}_category taxonomy
4141

4242
---
@@ -46,7 +46,7 @@ date: 2025-12-01
4646
**Status**: ✅ COMPLETED
4747

4848
- [x] **SCF Field Registration**
49-
- Location: [inc/class-fields.php](../inc/class-fields.php)
49+
- Location: JSON files in [/scf-json/](../scf-json/) (group_{name}.json)
5050
- Features: Subtitle, featured flag, gallery, related posts
5151

5252
- [x] **Repeater Fields**
@@ -75,23 +75,11 @@ date: 2025-12-01
7575

7676
## 5. Block Development
7777

78-
**Status**: 📋 TODO
79-
80-
- [ ] **Card Block** - Single post card display
81-
- Location: `src/blocks/{{slug}}-card/`
82-
- Features: Post preview with featured image, title, excerpt
83-
84-
- [ ] **Collection Block** - Post query/collection
85-
- Location: `src/blocks/{{slug}}-collection/`
86-
- Features: Grid/list/slider layouts, taxonomy filtering
78+
**Status**: ❌ REMOVED
8779

88-
- [ ] **Slider Block** - Carousel/slider display
89-
- Location: `src/blocks/{{slug}}-slider/`
90-
- Features: ACF repeater integration, navigation, autoplay
80+
**Note**: Block templates have been removed from the scaffold. Implement blocks as patterns or custom code as needed.
9181

92-
- [ ] **Featured Block** - Featured posts display
93-
- Location: `src/blocks/{{slug}}-featured/`
94-
- Features: Highlight featured {{name_plural_lower}}
82+
**Note**: Card and Featured blocks are implemented as patterns using the Collection block.
9583

9684
---
9785

@@ -127,7 +115,8 @@ date: 2025-12-01
127115

128116
- [ ] **Block Patterns**
129117
- Location: `patterns/`
130-
- Files: {{slug}}-archive.php, {{slug}}-card.php, {{slug}}-grid.php
118+
- Files: {{slug}}-archive.php, {{slug}}-grid.php
119+
- Note: Implement card and featured displays as patterns
131120

132121
---
133122

.github/custom-instructions.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ You are an expert WordPress multi-block plugin developer working on {{name}}, a
101101
```
102102
{{slug}}/
103103
├── src/
104-
│ ├── blocks/
105-
│ │ ├── {{slug}}-card/
106-
│ │ ├── {{slug}}-collection/
107-
│ │ ├── {{slug}}-slider/
108-
│ │ └── {{slug}}-featured/
109104
│ ├── components/
110105
│ │ ├── Slider/
111106
│ │ ├── PostSelector/
@@ -114,9 +109,7 @@ You are an expert WordPress multi-block plugin developer working on {{name}}, a
114109
│ ├── utils/
115110
│ └── scss/
116111
├── inc/
117-
│ ├── class-post-types.php
118-
│ ├── class-taxonomies.php
119-
│ ├── class-fields.php
112+
│ ├── class-content-model-manager.php
120113
│ ├── class-repeater-fields.php
121114
│ ├── class-block-templates.php
122115
│ ├── class-block-bindings.php
@@ -181,14 +174,14 @@ You are an expert WordPress multi-block plugin developer working on {{name}}, a
181174

182175
### Custom Post Types
183176

184-
- Register in `inc/class-post-types.php`
177+
- Register via JSON files in `/scf-json/` using SCF Local JSON format (handled by `inc/class-scf-json.php`)
185178
- Enable block editor support (`show_in_rest`)
186179
- Define block templates for consistent editing
187180

188181
### Custom Fields
189182

190183
- Use Secure Custom Fields (SCF) API
191-
- Register fields in `inc/class-fields.php`
184+
- Register fields via JSON files in `/scf-json/` using SCF field group format (handled by `inc/class-scf-json.php`)
192185
- Implement repeater fields for complex data
193186
- Use Block Bindings for field display
194187

@@ -254,7 +247,7 @@ Use these variables in templates and configuration files:
254247

255248
**Adding Custom Fields**
256249

257-
1. Register field group in `inc/class-fields.php`
250+
1. Register field group via JSON files in `/scf-json/` using SCF format (handled by `inc/class-scf-json.php`)
258251
2. Use `acf_add_local_field_group()` API
259252
3. Implement block binding if needed
260253
4. Test field functionality

.github/instructions/block-json.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ $alignment = $attributes['alignment'] ?? 'left';
334334
$post_id = $block->context['postId'] ?? get_the_ID();
335335

336336
?>
337-
<div class="wp-block-{{namespace}}-{{slug}}-card align<?php echo esc_attr( $alignment ); ?>">
337+
<div class="wp-block-{{namespace}}-custom-block align<?php echo esc_attr( $alignment ); ?>">
338338
<?php echo wp_kses_post( $content ); ?>
339339
</div>
340340
```

.github/instructions/folder-structure.instructions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ Use this guide when creating, moving, or auditing files. It covers where to plac
188188

189189
**Block**:
190190

191-
- **Location**: `src/blocks/{{slug}}-{block-name}/`
191+
- **Location**: `src/blocks/{block-name}/` (custom blocks only, no templates provided)
192192
- **Files**: `block.json`, `edit.js`, `save.js`, `render.php`, `style.scss`, `editor.scss`
193-
- **Example**: `src/blocks/{{slug}}-card/`
193+
- **Example**: `src/blocks/custom-block/`
194194

195195
**Test File**:
196196

@@ -496,8 +496,8 @@ fs.rmSync(tmpDir, { recursive: true, force: true });
496496
### 2. Mirror Test Structure
497497

498498
```text
499-
src/blocks/{{slug}}-card/edit.js
500-
tests/js/blocks/{{slug}}-card.test.js
499+
src/blocks/custom-block/edit.js
500+
tests/js/blocks/custom-block.test.js
501501
```
502502

503503
### 3. Namespace Everything

.github/instructions/generate-plugin.instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ⚠️ WARNING: Strict Mustache Placeholder Enforcement
22

3-
All contributors must use the correct mustache placeholders in all template files, folders, and code. Do not use generic placeholders (like `{{slug}}`) where a more specific one is required (e.g., `{{cpt1_slug}}`, `{{taxonomy1_slug}}`).
3+
All contributors must use the correct mustache placeholders in all template files, folders, and code. Do not use generic placeholders (like `{{slug}}`) where a more specific one is required (e.g., `{{cpt_slug}}`, `{{taxonomy1_slug}}`).
44

55
**Never hard-code plugin-specific values** in the scaffold. All identifiers, class names, translation domains, and meta keys must use the appropriate placeholder as defined in `scripts/mustache-variables-registry.json`.
66

@@ -179,7 +179,7 @@ When generating taxonomy functionality:
179179
```php
180180
// Use UPPERCASE namespace
181181
define( '{{namespace|upper}}_VERSION', '{{version}}' );
182-
define( '{{namespace|upper}}_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
182+
define( '{{namespace|upper}}_DIR', plugin_dir_path( __FILE__ ) );
183183
```
184184

185185
**Classes:**

0 commit comments

Comments
 (0)