@mytechtoday/augment-extensions 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/augment-extensions/domain-rules/wordpress/README.md +163 -0
- package/augment-extensions/domain-rules/wordpress/module.json +32 -0
- package/augment-extensions/domain-rules/wordpress/rules/coding-standards.md +617 -0
- package/augment-extensions/domain-rules/wordpress/rules/directory-structure.md +270 -0
- package/augment-extensions/domain-rules/wordpress/rules/file-patterns.md +423 -0
- package/augment-extensions/domain-rules/wordpress/rules/gutenberg-blocks.md +493 -0
- package/augment-extensions/domain-rules/wordpress/rules/performance.md +568 -0
- package/augment-extensions/domain-rules/wordpress/rules/plugin-development.md +510 -0
- package/augment-extensions/domain-rules/wordpress/rules/project-detection.md +251 -0
- package/augment-extensions/domain-rules/wordpress/rules/rest-api.md +501 -0
- package/augment-extensions/domain-rules/wordpress/rules/security.md +564 -0
- package/augment-extensions/domain-rules/wordpress/rules/theme-development.md +388 -0
- package/augment-extensions/domain-rules/wordpress/rules/woocommerce.md +441 -0
- package/augment-extensions/domain-rules/wordpress-plugin/README.md +139 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/ajax-plugin.md +1599 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/custom-post-type-plugin.md +1727 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block-plugin.md +428 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/gutenberg-block.md +422 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/mvc-plugin.md +1623 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/object-oriented-plugin.md +1343 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/rest-endpoint.md +734 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/settings-page-plugin.md +1350 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/simple-procedural-plugin.md +503 -0
- package/augment-extensions/domain-rules/wordpress-plugin/examples/singleton-plugin.md +971 -0
- package/augment-extensions/domain-rules/wordpress-plugin/module.json +53 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/activation-hooks.md +770 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/admin-interface.md +874 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/ajax-handlers.md +629 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/asset-management.md +559 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/context-providers.md +709 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/cron-jobs.md +736 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/database-management.md +1057 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/documentation-standards.md +463 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/frontend-functionality.md +478 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/gutenberg-blocks.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/internationalization.md +416 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/migration.md +667 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/performance-optimization.md +878 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-architecture.md +693 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/plugin-structure.md +352 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/rest-api.md +818 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/scaffolding-workflow.md +624 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/security-best-practices.md +866 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing-patterns.md +1165 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/testing.md +414 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/vscode-integration.md +751 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/woocommerce-integration.md +949 -0
- package/augment-extensions/domain-rules/wordpress-plugin/rules/wordpress-org-submission.md +458 -0
- package/augment-extensions/examples/gutenberg-block-plugin/README.md +101 -0
- package/augment-extensions/examples/gutenberg-block-plugin/examples/testimonial-block.md +428 -0
- package/augment-extensions/examples/gutenberg-block-plugin/module.json +40 -0
- package/augment-extensions/examples/rest-api-plugin/README.md +98 -0
- package/augment-extensions/examples/rest-api-plugin/examples/task-manager-api.md +1299 -0
- package/augment-extensions/examples/rest-api-plugin/module.json +40 -0
- package/augment-extensions/examples/woocommerce-extension/README.md +98 -0
- package/augment-extensions/examples/woocommerce-extension/examples/product-customizer.md +763 -0
- package/augment-extensions/examples/woocommerce-extension/module.json +40 -0
- package/augment-extensions/workflows/wordpress-plugin/README.md +232 -0
- package/augment-extensions/workflows/wordpress-plugin/ai-prompts.md +839 -0
- package/augment-extensions/workflows/wordpress-plugin/bead-decomposition-patterns.md +854 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/complete-plugin-example.md +540 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/custom-post-type-example.md +1083 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/feature-addition-workflow.md +669 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/plugin-creation-workflow.md +597 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/secure-form-handler-example.md +925 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/security-audit-workflow.md +752 -0
- package/augment-extensions/workflows/wordpress-plugin/examples/wordpress-org-submission-workflow.md +773 -0
- package/augment-extensions/workflows/wordpress-plugin/module.json +49 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/best-practices.md +942 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/development-workflow.md +702 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/submission-workflow.md +728 -0
- package/augment-extensions/workflows/wordpress-plugin/rules/testing-workflow.md +775 -0
- package/cli/dist/cli.js +5 -1
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/show.d.ts.map +1 -1
- package/cli/dist/commands/show.js +41 -0
- package/cli/dist/commands/show.js.map +1 -1
- package/modules.md +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
# Feature Addition Workflow Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates adding a new feature to an existing WordPress plugin using OpenSpec and Beads.
|
|
4
|
+
|
|
5
|
+
## Scenario
|
|
6
|
+
|
|
7
|
+
Adding a "Custom Fields" feature to an existing "Simple Contact Form" plugin to allow admins to add custom form fields beyond the default name, email, subject, and message fields.
|
|
8
|
+
|
|
9
|
+
## Existing Plugin
|
|
10
|
+
|
|
11
|
+
**Plugin**: Simple Contact Form (from complete-plugin-example.md)
|
|
12
|
+
|
|
13
|
+
**Current Features**:
|
|
14
|
+
- Frontend contact form with fixed fields (name, email, subject, message)
|
|
15
|
+
- Admin page to view submissions
|
|
16
|
+
- Email notifications
|
|
17
|
+
- AJAX submission
|
|
18
|
+
- Rate limiting
|
|
19
|
+
|
|
20
|
+
**New Feature**: Custom Fields
|
|
21
|
+
- Allow admins to create custom form fields
|
|
22
|
+
- Support field types: text, textarea, select, checkbox, radio
|
|
23
|
+
- Store custom field data with submissions
|
|
24
|
+
- Display custom fields in admin submissions view
|
|
25
|
+
|
|
26
|
+
## Workflow Steps
|
|
27
|
+
|
|
28
|
+
### Step 1: Create OpenSpec Change Proposal
|
|
29
|
+
|
|
30
|
+
**File**: `openspec/changes/custom-fields/proposal.md`
|
|
31
|
+
|
|
32
|
+
```markdown
|
|
33
|
+
---
|
|
34
|
+
id: custom-fields
|
|
35
|
+
relatedTasks: []
|
|
36
|
+
relatedRules: [module-development.md]
|
|
37
|
+
status: draft
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Add Custom Fields to Contact Form
|
|
41
|
+
|
|
42
|
+
## Motivation
|
|
43
|
+
|
|
44
|
+
Users have requested the ability to add custom fields to the contact form beyond
|
|
45
|
+
the default fields. This would allow collecting additional information like:
|
|
46
|
+
- Phone number
|
|
47
|
+
- Company name
|
|
48
|
+
- Department selection
|
|
49
|
+
- Budget range
|
|
50
|
+
- Preferred contact method
|
|
51
|
+
|
|
52
|
+
## Changes
|
|
53
|
+
|
|
54
|
+
1. Add custom fields management in admin
|
|
55
|
+
2. Modify database schema to store custom field definitions
|
|
56
|
+
3. Update form rendering to include custom fields
|
|
57
|
+
4. Update submission handler to save custom field data
|
|
58
|
+
5. Update admin submissions view to display custom field data
|
|
59
|
+
|
|
60
|
+
## Impact
|
|
61
|
+
|
|
62
|
+
### Breaking Changes
|
|
63
|
+
- None (backward compatible)
|
|
64
|
+
|
|
65
|
+
### Database Changes
|
|
66
|
+
- Create `wp_simple_contact_custom_fields` table
|
|
67
|
+
- Add `custom_fields_data` column to `wp_simple_contact_messages` table (JSON)
|
|
68
|
+
|
|
69
|
+
### Admin Changes
|
|
70
|
+
- New admin page: Tools > Contact Form > Custom Fields
|
|
71
|
+
- Add/edit/delete custom fields interface
|
|
72
|
+
- Drag-and-drop field ordering
|
|
73
|
+
|
|
74
|
+
### Frontend Changes
|
|
75
|
+
- Custom fields rendered in form based on admin configuration
|
|
76
|
+
- Validation for required custom fields
|
|
77
|
+
- Custom field data included in AJAX submission
|
|
78
|
+
|
|
79
|
+
## Timeline
|
|
80
|
+
|
|
81
|
+
- Database schema: 1 day
|
|
82
|
+
- Admin interface: 2-3 days
|
|
83
|
+
- Frontend integration: 1-2 days
|
|
84
|
+
- Testing: 1-2 days
|
|
85
|
+
|
|
86
|
+
## Dependencies
|
|
87
|
+
|
|
88
|
+
- Existing Simple Contact Form plugin
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Step 2: Create OpenSpec Spec Delta
|
|
92
|
+
|
|
93
|
+
**File**: `openspec/changes/custom-fields/specs/plugin-features/contact-form.md`
|
|
94
|
+
|
|
95
|
+
```markdown
|
|
96
|
+
---
|
|
97
|
+
id: plugin-features/contact-form
|
|
98
|
+
status: active
|
|
99
|
+
relatedTasks: []
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
# Delta for Contact Form Specification
|
|
103
|
+
|
|
104
|
+
## ADDED Requirements
|
|
105
|
+
|
|
106
|
+
### Requirement: Custom Fields Management
|
|
107
|
+
Admins MUST be able to create, edit, and delete custom form fields.
|
|
108
|
+
|
|
109
|
+
#### Scenario: Create custom field
|
|
110
|
+
- GIVEN an admin is on the Custom Fields page
|
|
111
|
+
- WHEN they click "Add Field"
|
|
112
|
+
- AND enter field details (label, type, required, options)
|
|
113
|
+
- AND click "Save"
|
|
114
|
+
- THEN the field is saved to the database
|
|
115
|
+
- AND appears in the fields list
|
|
116
|
+
- AND is rendered in the frontend form
|
|
117
|
+
|
|
118
|
+
#### Scenario: Edit custom field
|
|
119
|
+
- GIVEN a custom field exists
|
|
120
|
+
- WHEN an admin edits the field
|
|
121
|
+
- THEN changes are saved
|
|
122
|
+
- AND the frontend form updates immediately
|
|
123
|
+
|
|
124
|
+
#### Scenario: Delete custom field
|
|
125
|
+
- GIVEN a custom field exists
|
|
126
|
+
- WHEN an admin deletes the field
|
|
127
|
+
- THEN the field is removed from the database
|
|
128
|
+
- AND removed from the frontend form
|
|
129
|
+
- AND existing submission data is preserved
|
|
130
|
+
|
|
131
|
+
#### Scenario: Reorder fields
|
|
132
|
+
- GIVEN multiple custom fields exist
|
|
133
|
+
- WHEN an admin drags a field to a new position
|
|
134
|
+
- THEN the order is saved
|
|
135
|
+
- AND the frontend form reflects the new order
|
|
136
|
+
|
|
137
|
+
### Requirement: Custom Field Types
|
|
138
|
+
The system MUST support multiple field types.
|
|
139
|
+
|
|
140
|
+
**Supported Types**:
|
|
141
|
+
- Text input (single line)
|
|
142
|
+
- Textarea (multi-line)
|
|
143
|
+
- Select dropdown
|
|
144
|
+
- Checkbox (single)
|
|
145
|
+
- Radio buttons
|
|
146
|
+
- Email
|
|
147
|
+
- Phone
|
|
148
|
+
- URL
|
|
149
|
+
|
|
150
|
+
#### Scenario: Text field
|
|
151
|
+
- WHEN a text field is added
|
|
152
|
+
- THEN it renders as `<input type="text">`
|
|
153
|
+
- AND validates as required if configured
|
|
154
|
+
|
|
155
|
+
#### Scenario: Select field
|
|
156
|
+
- WHEN a select field is added with options
|
|
157
|
+
- THEN it renders as `<select>` with `<option>` elements
|
|
158
|
+
- AND validates selection if required
|
|
159
|
+
|
|
160
|
+
### Requirement: Custom Field Data Storage
|
|
161
|
+
Custom field data MUST be stored with each submission.
|
|
162
|
+
|
|
163
|
+
#### Scenario: Submit form with custom fields
|
|
164
|
+
- GIVEN a form has custom fields
|
|
165
|
+
- WHEN a user submits the form
|
|
166
|
+
- THEN custom field data is validated
|
|
167
|
+
- AND saved as JSON in `custom_fields_data` column
|
|
168
|
+
- AND included in email notification
|
|
169
|
+
|
|
170
|
+
## MODIFIED Requirements
|
|
171
|
+
|
|
172
|
+
### Requirement: Form Rendering (MODIFIED)
|
|
173
|
+
The system SHALL render both default and custom fields in the contact form.
|
|
174
|
+
|
|
175
|
+
#### Scenario: Render form (MODIFIED)
|
|
176
|
+
- WHEN the form is displayed
|
|
177
|
+
- THEN default fields are rendered (name, email, subject, message)
|
|
178
|
+
- AND custom fields are rendered in configured order (ADDED)
|
|
179
|
+
- AND all fields have proper labels and validation (CHANGED)
|
|
180
|
+
|
|
181
|
+
### Requirement: Submission Handling (MODIFIED)
|
|
182
|
+
The system SHALL validate and save both default and custom field data.
|
|
183
|
+
|
|
184
|
+
#### Scenario: Form submission (MODIFIED)
|
|
185
|
+
- WHEN a user submits the form
|
|
186
|
+
- THEN default fields are validated
|
|
187
|
+
- AND custom fields are validated (ADDED)
|
|
188
|
+
- AND all data is saved to database
|
|
189
|
+
- AND email notification includes custom field data (ADDED)
|
|
190
|
+
|
|
191
|
+
## REMOVED Requirements
|
|
192
|
+
|
|
193
|
+
(None for this change)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Step 3: Create Beads Tasks
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Create epic for custom fields feature
|
|
200
|
+
bd create "Add Custom Fields to Contact Form" -p 1 --type epic --label wordpress --label plugin --label feature
|
|
201
|
+
# Returns: bd-cf
|
|
202
|
+
|
|
203
|
+
# Database changes
|
|
204
|
+
bd create "Create custom_fields table schema" -p 0 --parent bd-cf --label database
|
|
205
|
+
# Returns: bd-cf.1
|
|
206
|
+
|
|
207
|
+
bd create "Add custom_fields_data column to messages table" -p 0 --parent bd-cf --label database
|
|
208
|
+
# Returns: bd-cf.2
|
|
209
|
+
|
|
210
|
+
bd create "Create database migration script" -p 0 --parent bd-cf --label database
|
|
211
|
+
# Returns: bd-cf.3
|
|
212
|
+
|
|
213
|
+
# Core classes
|
|
214
|
+
bd create "Create CustomField model class" -p 1 --parent bd-cf --label implementation
|
|
215
|
+
# Returns: bd-cf.4
|
|
216
|
+
|
|
217
|
+
bd create "Create FieldRenderer class" -p 1 --parent bd-cf --label implementation
|
|
218
|
+
# Returns: bd-cf.5
|
|
219
|
+
|
|
220
|
+
bd create "Create FieldValidator class" -p 1 --parent bd-cf --label implementation
|
|
221
|
+
# Returns: bd-cf.6
|
|
222
|
+
|
|
223
|
+
# Admin interface
|
|
224
|
+
bd create "Create Custom Fields admin page" -p 1 --parent bd-cf --label admin
|
|
225
|
+
# Returns: bd-cf.7
|
|
226
|
+
|
|
227
|
+
bd create "Add field creation UI" -p 1 --parent bd-cf --label admin
|
|
228
|
+
# Returns: bd-cf.8
|
|
229
|
+
|
|
230
|
+
bd create "Add field editing UI" -p 1 --parent bd-cf --label admin
|
|
231
|
+
# Returns: bd-cf.9
|
|
232
|
+
|
|
233
|
+
bd create "Add drag-and-drop ordering" -p 1 --parent bd-cf --label admin
|
|
234
|
+
# Returns: bd-cf.10
|
|
235
|
+
|
|
236
|
+
bd create "Add admin CSS/JS for custom fields" -p 1 --parent bd-cf --label admin
|
|
237
|
+
# Returns: bd-cf.11
|
|
238
|
+
|
|
239
|
+
# Frontend integration
|
|
240
|
+
bd create "Update form renderer to include custom fields" -p 1 --parent bd-cf --label frontend
|
|
241
|
+
# Returns: bd-cf.12
|
|
242
|
+
|
|
243
|
+
bd create "Update AJAX handler to process custom fields" -p 1 --parent bd-cf --label frontend
|
|
244
|
+
# Returns: bd-cf.13
|
|
245
|
+
|
|
246
|
+
bd create "Update email handler to include custom fields" -p 1 --parent bd-cf --label frontend
|
|
247
|
+
# Returns: bd-cf.14
|
|
248
|
+
|
|
249
|
+
bd create "Update admin submissions view" -p 1 --parent bd-cf --label admin
|
|
250
|
+
# Returns: bd-cf.15
|
|
251
|
+
|
|
252
|
+
# Security
|
|
253
|
+
bd create "Add nonce verification for custom field CRUD" -p 1 --parent bd-cf --label security
|
|
254
|
+
# Returns: bd-cf.16
|
|
255
|
+
|
|
256
|
+
bd create "Add capability checks for custom field management" -p 1 --parent bd-cf --label security
|
|
257
|
+
# Returns: bd-cf.17
|
|
258
|
+
|
|
259
|
+
bd create "Add sanitization for custom field data" -p 1 --parent bd-cf --label security
|
|
260
|
+
# Returns: bd-cf.18
|
|
261
|
+
|
|
262
|
+
# Testing
|
|
263
|
+
bd create "Write unit tests for custom fields" -p 1 --parent bd-cf --label testing
|
|
264
|
+
# Returns: bd-cf.19
|
|
265
|
+
|
|
266
|
+
bd create "Manual testing of custom fields feature" -p 2 --parent bd-cf --label testing
|
|
267
|
+
# Returns: bd-cf.20
|
|
268
|
+
|
|
269
|
+
# Documentation
|
|
270
|
+
bd create "Update plugin documentation" -p 2 --parent bd-cf --label documentation
|
|
271
|
+
# Returns: bd-cf.21
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Step 4: Add Task Dependencies
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Migration depends on schema changes
|
|
278
|
+
bd dep add bd-cf.3 bd-cf.1
|
|
279
|
+
bd dep add bd-cf.3 bd-cf.2
|
|
280
|
+
|
|
281
|
+
# Model depends on database
|
|
282
|
+
bd dep add bd-cf.4 bd-cf.3
|
|
283
|
+
|
|
284
|
+
# Renderer and Validator depend on Model
|
|
285
|
+
bd dep add bd-cf.5 bd-cf.4
|
|
286
|
+
bd dep add bd-cf.6 bd-cf.4
|
|
287
|
+
|
|
288
|
+
# Admin UI depends on Model
|
|
289
|
+
bd dep add bd-cf.7 bd-cf.4
|
|
290
|
+
bd dep add bd-cf.8 bd-cf.7
|
|
291
|
+
bd dep add bd-cf.9 bd-cf.7
|
|
292
|
+
bd dep add bd-cf.10 bd-cf.9
|
|
293
|
+
bd dep add bd-cf.11 bd-cf.10
|
|
294
|
+
|
|
295
|
+
# Frontend depends on Renderer and Validator
|
|
296
|
+
bd dep add bd-cf.12 bd-cf.5
|
|
297
|
+
bd dep add bd-cf.13 bd-cf.6
|
|
298
|
+
bd dep add bd-cf.14 bd-cf.13
|
|
299
|
+
bd dep add bd-cf.15 bd-cf.4
|
|
300
|
+
|
|
301
|
+
# Security depends on implementation
|
|
302
|
+
bd dep add bd-cf.16 bd-cf.8
|
|
303
|
+
bd dep add bd-cf.17 bd-cf.8
|
|
304
|
+
bd dep add bd-cf.18 bd-cf.13
|
|
305
|
+
|
|
306
|
+
# Testing depends on everything
|
|
307
|
+
bd dep add bd-cf.19 bd-cf.18
|
|
308
|
+
bd dep add bd-cf.20 bd-cf.19
|
|
309
|
+
|
|
310
|
+
# Documentation depends on testing
|
|
311
|
+
bd dep add bd-cf.21 bd-cf.20
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Step 5: Implementation
|
|
315
|
+
|
|
316
|
+
#### Task bd-cf.1: Create custom_fields Table Schema
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
bd update bd-cf.1 --status in_progress
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**File**: `includes/class-custom-field.php` (add table creation method)
|
|
323
|
+
|
|
324
|
+
```php
|
|
325
|
+
<?php
|
|
326
|
+
class Simple_Contact_Custom_Field {
|
|
327
|
+
public static function create_table() {
|
|
328
|
+
global $wpdb;
|
|
329
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
330
|
+
$charset_collate = $wpdb->get_charset_collate();
|
|
331
|
+
|
|
332
|
+
$sql = "CREATE TABLE $table_name (
|
|
333
|
+
id bigint(20) NOT NULL AUTO_INCREMENT,
|
|
334
|
+
field_key varchar(100) NOT NULL,
|
|
335
|
+
field_label varchar(255) NOT NULL,
|
|
336
|
+
field_type varchar(50) NOT NULL,
|
|
337
|
+
field_options text,
|
|
338
|
+
is_required tinyint(1) DEFAULT 0,
|
|
339
|
+
field_order int(11) DEFAULT 0,
|
|
340
|
+
created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
341
|
+
updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
342
|
+
PRIMARY KEY (id),
|
|
343
|
+
UNIQUE KEY field_key (field_key),
|
|
344
|
+
KEY field_order (field_order)
|
|
345
|
+
) $charset_collate;";
|
|
346
|
+
|
|
347
|
+
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
|
|
348
|
+
dbDelta($sql);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
bd comment bd-cf.1 "Created custom_fields table with unique field_key and ordering"
|
|
355
|
+
bd close bd-cf.1
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
#### Task bd-cf.2: Add custom_fields_data Column
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
bd update bd-cf.2 --status in_progress
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
**File**: `includes/class-contact-message.php` (add migration method)
|
|
365
|
+
|
|
366
|
+
```php
|
|
367
|
+
<?php
|
|
368
|
+
class Simple_Contact_Message {
|
|
369
|
+
// ... existing code ...
|
|
370
|
+
|
|
371
|
+
public static function add_custom_fields_column() {
|
|
372
|
+
global $wpdb;
|
|
373
|
+
$table_name = $wpdb->prefix . 'simple_contact_messages';
|
|
374
|
+
|
|
375
|
+
// Check if column exists
|
|
376
|
+
$column = $wpdb->get_results(
|
|
377
|
+
$wpdb->prepare(
|
|
378
|
+
"SELECT * FROM INFORMATION_SCHEMA.COLUMNS
|
|
379
|
+
WHERE TABLE_SCHEMA = %s
|
|
380
|
+
AND TABLE_NAME = %s
|
|
381
|
+
AND COLUMN_NAME = %s",
|
|
382
|
+
DB_NAME,
|
|
383
|
+
$table_name,
|
|
384
|
+
'custom_fields_data'
|
|
385
|
+
)
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
if (empty($column)) {
|
|
389
|
+
$wpdb->query(
|
|
390
|
+
"ALTER TABLE $table_name
|
|
391
|
+
ADD COLUMN custom_fields_data longtext AFTER message"
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
```bash
|
|
399
|
+
bd comment bd-cf.2 "Added custom_fields_data JSON column to messages table"
|
|
400
|
+
bd close bd-cf.2
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
#### Task bd-cf.3: Create Migration Script
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
bd ready # Shows bd-cf.3 is ready
|
|
407
|
+
bd update bd-cf.3 --status in_progress
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
**File**: `simple-contact-form.php` (update activation hook)
|
|
411
|
+
|
|
412
|
+
```php
|
|
413
|
+
<?php
|
|
414
|
+
// Update activation hook
|
|
415
|
+
register_activation_hook(__FILE__, 'simple_contact_form_activate');
|
|
416
|
+
function simple_contact_form_activate() {
|
|
417
|
+
require_once SIMPLE_CONTACT_FORM_PATH . 'includes/class-contact-message.php';
|
|
418
|
+
require_once SIMPLE_CONTACT_FORM_PATH . 'includes/class-custom-field.php';
|
|
419
|
+
|
|
420
|
+
// Create/update tables
|
|
421
|
+
Simple_Contact_Message::create_table();
|
|
422
|
+
Simple_Contact_Message::add_custom_fields_column();
|
|
423
|
+
Simple_Contact_Custom_Field::create_table();
|
|
424
|
+
|
|
425
|
+
// Set version for future migrations
|
|
426
|
+
update_option('simple_contact_form_db_version', '1.1.0');
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Check for updates on plugins_loaded
|
|
430
|
+
add_action('plugins_loaded', 'simple_contact_form_check_version');
|
|
431
|
+
function simple_contact_form_check_version() {
|
|
432
|
+
$current_version = get_option('simple_contact_form_db_version', '1.0.0');
|
|
433
|
+
|
|
434
|
+
if (version_compare($current_version, '1.1.0', '<')) {
|
|
435
|
+
simple_contact_form_activate();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
bd comment bd-cf.3 "Created migration script with version checking for automatic updates"
|
|
442
|
+
bd close bd-cf.3
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
#### Task bd-cf.4: Create CustomField Model Class
|
|
446
|
+
|
|
447
|
+
```bash
|
|
448
|
+
bd ready # Shows bd-cf.4 is ready
|
|
449
|
+
bd update bd-cf.4 --status in_progress
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**File**: `includes/class-custom-field.php` (add CRUD methods)
|
|
453
|
+
|
|
454
|
+
```php
|
|
455
|
+
<?php
|
|
456
|
+
class Simple_Contact_Custom_Field {
|
|
457
|
+
// ... table creation method from bd-cf.1 ...
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Get all custom fields ordered by field_order
|
|
461
|
+
*/
|
|
462
|
+
public static function get_all() {
|
|
463
|
+
global $wpdb;
|
|
464
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
465
|
+
|
|
466
|
+
return $wpdb->get_results(
|
|
467
|
+
"SELECT * FROM $table_name ORDER BY field_order ASC",
|
|
468
|
+
ARRAY_A
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Get custom field by ID
|
|
474
|
+
*/
|
|
475
|
+
public static function get_by_id($id) {
|
|
476
|
+
global $wpdb;
|
|
477
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
478
|
+
|
|
479
|
+
return $wpdb->get_row(
|
|
480
|
+
$wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $id),
|
|
481
|
+
ARRAY_A
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Create custom field
|
|
487
|
+
*/
|
|
488
|
+
public static function create($data) {
|
|
489
|
+
global $wpdb;
|
|
490
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
491
|
+
|
|
492
|
+
$wpdb->insert(
|
|
493
|
+
$table_name,
|
|
494
|
+
array(
|
|
495
|
+
'field_key' => sanitize_key($data['field_key']),
|
|
496
|
+
'field_label' => sanitize_text_field($data['field_label']),
|
|
497
|
+
'field_type' => sanitize_text_field($data['field_type']),
|
|
498
|
+
'field_options' => isset($data['field_options']) ? wp_json_encode($data['field_options']) : null,
|
|
499
|
+
'is_required' => isset($data['is_required']) ? (int) $data['is_required'] : 0,
|
|
500
|
+
'field_order' => isset($data['field_order']) ? (int) $data['field_order'] : 0
|
|
501
|
+
),
|
|
502
|
+
array('%s', '%s', '%s', '%s', '%d', '%d')
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
return $wpdb->insert_id;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Update custom field
|
|
510
|
+
*/
|
|
511
|
+
public static function update($id, $data) {
|
|
512
|
+
global $wpdb;
|
|
513
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
514
|
+
|
|
515
|
+
$update_data = array();
|
|
516
|
+
$formats = array();
|
|
517
|
+
|
|
518
|
+
if (isset($data['field_label'])) {
|
|
519
|
+
$update_data['field_label'] = sanitize_text_field($data['field_label']);
|
|
520
|
+
$formats[] = '%s';
|
|
521
|
+
}
|
|
522
|
+
if (isset($data['field_type'])) {
|
|
523
|
+
$update_data['field_type'] = sanitize_text_field($data['field_type']);
|
|
524
|
+
$formats[] = '%s';
|
|
525
|
+
}
|
|
526
|
+
if (isset($data['field_options'])) {
|
|
527
|
+
$update_data['field_options'] = wp_json_encode($data['field_options']);
|
|
528
|
+
$formats[] = '%s';
|
|
529
|
+
}
|
|
530
|
+
if (isset($data['is_required'])) {
|
|
531
|
+
$update_data['is_required'] = (int) $data['is_required'];
|
|
532
|
+
$formats[] = '%d';
|
|
533
|
+
}
|
|
534
|
+
if (isset($data['field_order'])) {
|
|
535
|
+
$update_data['field_order'] = (int) $data['field_order'];
|
|
536
|
+
$formats[] = '%d';
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return $wpdb->update(
|
|
540
|
+
$table_name,
|
|
541
|
+
$update_data,
|
|
542
|
+
array('id' => $id),
|
|
543
|
+
$formats,
|
|
544
|
+
array('%d')
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Delete custom field
|
|
550
|
+
*/
|
|
551
|
+
public static function delete($id) {
|
|
552
|
+
global $wpdb;
|
|
553
|
+
$table_name = $wpdb->prefix . 'simple_contact_custom_fields';
|
|
554
|
+
|
|
555
|
+
return $wpdb->delete(
|
|
556
|
+
$table_name,
|
|
557
|
+
array('id' => $id),
|
|
558
|
+
array('%d')
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
bd comment bd-cf.4 "Created CustomField model with full CRUD operations and sanitization"
|
|
566
|
+
bd close bd-cf.4
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
## Step 6: Continue Implementation
|
|
570
|
+
|
|
571
|
+
Following the dependency chain, implement remaining tasks:
|
|
572
|
+
|
|
573
|
+
- **bd-cf.5**: FieldRenderer class to render different field types
|
|
574
|
+
- **bd-cf.6**: FieldValidator class to validate custom field inputs
|
|
575
|
+
- **bd-cf.7-11**: Admin interface for managing custom fields
|
|
576
|
+
- **bd-cf.12-15**: Frontend integration
|
|
577
|
+
- **bd-cf.16-18**: Security hardening
|
|
578
|
+
- **bd-cf.19-20**: Testing
|
|
579
|
+
- **bd-cf.21**: Documentation
|
|
580
|
+
|
|
581
|
+
## Step 7: Testing and Completion
|
|
582
|
+
|
|
583
|
+
```bash
|
|
584
|
+
# Run unit tests
|
|
585
|
+
./vendor/bin/phpunit
|
|
586
|
+
|
|
587
|
+
# Manual testing
|
|
588
|
+
bd update bd-cf.20 --status in_progress
|
|
589
|
+
bd comment bd-cf.20 "Manual testing completed:
|
|
590
|
+
- ✓ Can create custom fields in admin
|
|
591
|
+
- ✓ Can edit and delete custom fields
|
|
592
|
+
- ✓ Drag-and-drop ordering works
|
|
593
|
+
- ✓ Custom fields render in frontend form
|
|
594
|
+
- ✓ Custom field data saves with submissions
|
|
595
|
+
- ✓ Custom field data displays in admin submissions view
|
|
596
|
+
- ✓ Email notifications include custom field data
|
|
597
|
+
- ✓ Validation works for required custom fields
|
|
598
|
+
- ✓ All field types render correctly (text, select, checkbox, etc.)
|
|
599
|
+
- ✓ Security: nonces verified, capabilities checked, inputs sanitized"
|
|
600
|
+
bd close bd-cf.20
|
|
601
|
+
|
|
602
|
+
# Update documentation
|
|
603
|
+
bd update bd-cf.21 --status in_progress
|
|
604
|
+
bd comment bd-cf.21 "Updated readme.txt with custom fields feature, added screenshots"
|
|
605
|
+
bd close bd-cf.21
|
|
606
|
+
|
|
607
|
+
# Close epic
|
|
608
|
+
bd close bd-cf
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
## Step 8: Archive OpenSpec Change
|
|
612
|
+
|
|
613
|
+
```bash
|
|
614
|
+
# Apply delta to source spec
|
|
615
|
+
# Merge ADDED and MODIFIED sections into openspec/specs/plugin-features/contact-form.md
|
|
616
|
+
|
|
617
|
+
# Move to archive
|
|
618
|
+
mv openspec/changes/custom-fields openspec/archive/custom-fields
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
## AI Agent Workflow
|
|
622
|
+
|
|
623
|
+
### Initial Prompt
|
|
624
|
+
|
|
625
|
+
```
|
|
626
|
+
Add a "Custom Fields" feature to the Simple Contact Form plugin.
|
|
627
|
+
|
|
628
|
+
Requirements:
|
|
629
|
+
- Allow admins to create custom form fields
|
|
630
|
+
- Support field types: text, textarea, select, checkbox, radio, email, phone, URL
|
|
631
|
+
- Store custom field definitions in database
|
|
632
|
+
- Store custom field data with each submission (JSON format)
|
|
633
|
+
- Admin interface for managing custom fields (add, edit, delete, reorder)
|
|
634
|
+
- Display custom fields in frontend form
|
|
635
|
+
- Include custom field data in email notifications
|
|
636
|
+
- Display custom field data in admin submissions view
|
|
637
|
+
|
|
638
|
+
Security:
|
|
639
|
+
- Nonce verification for custom field CRUD operations
|
|
640
|
+
- Capability checks (manage_options)
|
|
641
|
+
- Sanitize all inputs
|
|
642
|
+
- Validate custom field data on submission
|
|
643
|
+
|
|
644
|
+
Follow the existing plugin architecture and WordPress best practices.
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### Implementation Approach
|
|
648
|
+
|
|
649
|
+
1. **Create OpenSpec change proposal** with motivation and impact analysis
|
|
650
|
+
2. **Create spec delta** with ADDED/MODIFIED requirements
|
|
651
|
+
3. **Break down into Beads tasks** with clear dependencies
|
|
652
|
+
4. **Implement database changes first** (foundation)
|
|
653
|
+
5. **Build core classes** (model, renderer, validator)
|
|
654
|
+
6. **Add admin interface** for management
|
|
655
|
+
7. **Integrate with frontend** form and submission handler
|
|
656
|
+
8. **Harden security** with nonces, capabilities, sanitization
|
|
657
|
+
9. **Test thoroughly** with unit and manual tests
|
|
658
|
+
10. **Update documentation** and archive change
|
|
659
|
+
|
|
660
|
+
## Key Takeaways
|
|
661
|
+
|
|
662
|
+
- **Use OpenSpec deltas** to document changes to existing specs
|
|
663
|
+
- **Database migrations** should be version-checked and automatic
|
|
664
|
+
- **Backward compatibility** is critical for existing users
|
|
665
|
+
- **Security** must be applied to all new CRUD operations
|
|
666
|
+
- **Testing** should cover both new and existing functionality
|
|
667
|
+
- **Documentation** should explain new features clearly
|
|
668
|
+
- **Beads dependencies** ensure correct implementation order
|
|
669
|
+
|