|
| 1 | +# WordPress Block Developer Agent |
| 2 | + |
| 3 | +## Repository Context |
| 4 | + |
| 5 | +This agent works within the WordPress Block Development Examples monorepo. For comprehensive repository structure, build processes, and technical details, refer to the [Copilot Instructions](../copilot-instructions.md). |
| 6 | + |
| 7 | +## Agent Capabilities |
| 8 | + |
| 9 | +This agent specializes in WordPress block development within the Block Development Examples monorepo. It can handle: |
| 10 | + |
| 11 | +- Creating new block examples |
| 12 | +- Fixing bugs in existing blocks |
| 13 | +- Adding features to blocks |
| 14 | +- Updating block dependencies |
| 15 | +- Improving documentation |
| 16 | +- Writing tests for blocks |
| 17 | +- Performance optimizations |
| 18 | +- Accessibility improvements |
| 19 | +- Code refactoring |
| 20 | + |
| 21 | +## Issue Handling Guidelines |
| 22 | + |
| 23 | +### Bug Issues |
| 24 | + |
| 25 | +When assigned a bug issue: |
| 26 | + |
| 27 | +1. **Reproduce the issue** |
| 28 | + - Start the WordPress environment: `pnpm run env:start` |
| 29 | + - Navigate to the affected block example |
| 30 | + - Verify the reported behavior |
| 31 | + |
| 32 | +2. **Investigate root cause** |
| 33 | + - Check browser console for JavaScript errors |
| 34 | + - Review block registration in PHP files |
| 35 | + - Examine block.json for configuration issues |
| 36 | + - Check build output in `build/` directory |
| 37 | + |
| 38 | +3. **Fix the bug** |
| 39 | + - Make minimal changes to fix the issue |
| 40 | + - Preserve existing functionality |
| 41 | + - Follow WordPress coding standards |
| 42 | + |
| 43 | +4. **Test the fix** |
| 44 | + - Rebuild: `pnpm run build` |
| 45 | + - Test in block editor |
| 46 | + - Test on frontend |
| 47 | + - Verify no regressions |
| 48 | + |
| 49 | +5. **Update tests if needed** |
| 50 | + - Add test case for the bug if applicable |
| 51 | + - Run existing tests: `pnpm run test:e2e` |
| 52 | + |
| 53 | +### Enhancement Issues |
| 54 | + |
| 55 | +When assigned an enhancement: |
| 56 | + |
| 57 | +1. **Understand the requirement** |
| 58 | + - Review similar examples in other blocks |
| 59 | + - Check WordPress Block Editor documentation |
| 60 | + - Identify affected files |
| 61 | + |
| 62 | +2. **Plan the implementation** |
| 63 | + - Determine if this needs a new example or modification |
| 64 | + - List files that need changes |
| 65 | + - Consider backward compatibility |
| 66 | + |
| 67 | +3. **Implement the feature** |
| 68 | + - Follow existing patterns in the repository |
| 69 | + - Add necessary dependencies via pnpm |
| 70 | + - Include both editor and frontend functionality |
| 71 | + - Add proper internationalization |
| 72 | + |
| 73 | +4. **Add documentation** |
| 74 | + - Update inline code comments |
| 75 | + - Add JSDoc comments for new functions |
| 76 | + - Update block.json description if needed |
| 77 | + |
| 78 | +### New Block Example Issues |
| 79 | + |
| 80 | +When creating a new block example: |
| 81 | + |
| 82 | +1. **Use the template** |
| 83 | + ```bash |
| 84 | + pnpm run create-example |
| 85 | + ``` |
| 86 | + - Follow prompts for block configuration |
| 87 | + - Choose appropriate block type (static/dynamic) |
| 88 | + |
| 89 | +2. **Implement the example** |
| 90 | + - Focus on demonstrating ONE clear concept |
| 91 | + - Keep code minimal and educational |
| 92 | + - Add extensive comments explaining the concept |
| 93 | + |
| 94 | +3. **Structure the example** |
| 95 | + - `plugin.php` - Main plugin file with clear header |
| 96 | + - `src/block.json` - Block metadata |
| 97 | + - `src/index.js` - Block registration |
| 98 | + - `src/edit.js` - Editor component |
| 99 | + - `src/save.js` - Save component (for static blocks) |
| 100 | + - `src/render.php` - Server rendering (for dynamic blocks) |
| 101 | + - `src/style.scss` - Frontend styles |
| 102 | + - `src/editor.scss` - Editor-only styles |
| 103 | + - `src/view.js` - Frontend JavaScript (if needed) |
| 104 | + |
| 105 | +4. **Update repository metadata** |
| 106 | + ```bash |
| 107 | + pnpm run table:update |
| 108 | + ``` |
| 109 | + - This updates the documentation tables |
| 110 | + |
| 111 | +## Code Standards |
| 112 | + |
| 113 | +### JavaScript/React |
| 114 | +- Use modern ESNext syntax |
| 115 | +- Prefer functional components with hooks |
| 116 | +- Import WordPress dependencies from `@wordpress/*` packages |
| 117 | +- Use `useBlockProps()` for proper block wrapper |
| 118 | +- Include PropTypes or TypeScript types when beneficial for education |
| 119 | + |
| 120 | +### PHP |
| 121 | +- Follow WordPress PHP coding standards |
| 122 | +- Use tabs for indentation |
| 123 | +- Add proper plugin headers |
| 124 | +- Use `wp_register_block_type()` for block registration |
| 125 | +- Sanitize and escape all data |
| 126 | +- Add text domain for translations |
| 127 | + |
| 128 | +### CSS/SCSS |
| 129 | +- Use SCSS for styles |
| 130 | +- Follow WordPress CSS coding standards |
| 131 | +- Namespace classes with block name |
| 132 | +- Support RTL automatically |
| 133 | +- Keep specificity low |
| 134 | + |
| 135 | +## Testing Requirements |
| 136 | + |
| 137 | +### Before Marking Complete |
| 138 | + |
| 139 | +1. **Build successfully** |
| 140 | + ```bash |
| 141 | + pnpm run build |
| 142 | + ``` |
| 143 | + |
| 144 | +2. **Pass linting** |
| 145 | + ```bash |
| 146 | + pnpm run lint:js |
| 147 | + pnpm run lint:css |
| 148 | + composer run lint |
| 149 | + ``` |
| 150 | + |
| 151 | +3. **Test in WordPress** |
| 152 | + - Block inserts without errors |
| 153 | + - Editor functionality works |
| 154 | + - Frontend renders correctly |
| 155 | + - No console errors |
| 156 | + - Works with alignment/width options |
| 157 | + |
| 158 | +4. **Cross-browser testing** |
| 159 | + - Chrome/Edge |
| 160 | + - Firefox |
| 161 | + - Safari (if available) |
| 162 | + |
| 163 | +5. **Accessibility check** |
| 164 | + - Keyboard navigation works |
| 165 | + - Screen reader announces properly |
| 166 | + - Proper ARIA attributes |
| 167 | + - Sufficient color contrast |
| 168 | + |
| 169 | +## Common Patterns |
| 170 | + |
| 171 | +### Adding Interactivity API |
| 172 | + |
| 173 | +```javascript |
| 174 | +// In view.js |
| 175 | +import { store, getContext } from '@wordpress/interactivity'; |
| 176 | + |
| 177 | +store( 'create-block/example', { |
| 178 | + actions: { |
| 179 | + toggle: () => { |
| 180 | + const context = getContext(); |
| 181 | + context.isOpen = !context.isOpen; |
| 182 | + }, |
| 183 | + }, |
| 184 | +}); |
| 185 | +``` |
| 186 | + |
| 187 | +### Dynamic Block with Attributes |
| 188 | + |
| 189 | +```php |
| 190 | +// In render.php |
| 191 | +$wrapper_attributes = get_block_wrapper_attributes(); |
| 192 | +$content = isset( $attributes['content'] ) ? esc_html( $attributes['content'] ) : ''; |
| 193 | + |
| 194 | +printf( |
| 195 | + '<div %1$s>%2$s</div>', |
| 196 | + $wrapper_attributes, |
| 197 | + $content |
| 198 | +); |
| 199 | +``` |
| 200 | + |
| 201 | +### Block Supports |
| 202 | + |
| 203 | +```json |
| 204 | +// In block.json |
| 205 | +"supports": { |
| 206 | + "html": false, |
| 207 | + "color": { |
| 208 | + "text": true, |
| 209 | + "background": true, |
| 210 | + "gradients": true |
| 211 | + }, |
| 212 | + "spacing": { |
| 213 | + "padding": true, |
| 214 | + "margin": true |
| 215 | + }, |
| 216 | + "typography": { |
| 217 | + "fontSize": true, |
| 218 | + "lineHeight": true |
| 219 | + } |
| 220 | +} |
| 221 | +``` |
| 222 | + |
| 223 | +### Custom Block Controls |
| 224 | + |
| 225 | +```javascript |
| 226 | +// In edit.js |
| 227 | +import { InspectorControls } from '@wordpress/block-editor'; |
| 228 | +import { PanelBody, ToggleControl } from '@wordpress/components'; |
| 229 | + |
| 230 | +// Inside Edit component |
| 231 | +<InspectorControls> |
| 232 | + <PanelBody title={ __( 'Settings', 'textdomain' ) }> |
| 233 | + <ToggleControl |
| 234 | + label={ __( 'Show Feature', 'textdomain' ) } |
| 235 | + checked={ attributes.showFeature } |
| 236 | + onChange={ ( value ) => setAttributes( { showFeature: value } ) } |
| 237 | + /> |
| 238 | + </PanelBody> |
| 239 | +</InspectorControls> |
| 240 | +``` |
| 241 | + |
| 242 | +## Decision Criteria |
| 243 | + |
| 244 | +### When to create a new example vs. modify existing |
| 245 | +- **New example** if demonstrating a fundamentally different concept |
| 246 | +- **Modify existing** if enhancing or fixing current functionality |
| 247 | + |
| 248 | +### When to use static vs. dynamic blocks |
| 249 | +- **Static blocks** for content that doesn't change after saving |
| 250 | +- **Dynamic blocks** for content that needs server-side processing or external data |
| 251 | + |
| 252 | +### When to add frontend JavaScript |
| 253 | +- Only when interactivity is essential to the example |
| 254 | +- Prefer CSS-only solutions when possible |
| 255 | +- Use Interactivity API for modern interactive examples |
| 256 | + |
| 257 | +## Success Criteria |
| 258 | + |
| 259 | +An issue is successfully completed when: |
| 260 | + |
| 261 | +1. ✅ All requirements from the issue are implemented |
| 262 | +2. ✅ Code follows WordPress and repository standards |
| 263 | +3. ✅ No build errors or linting warnings |
| 264 | +4. ✅ Block works in WordPress without console errors |
| 265 | +5. ✅ Documentation/comments explain the implementation |
| 266 | +6. ✅ Tests pass (if applicable) |
| 267 | +7. ✅ Accessibility requirements are met |
| 268 | +8. ✅ Example clearly demonstrates its intended concept |
| 269 | + |
| 270 | +## Communication |
| 271 | + |
| 272 | +### Status Updates |
| 273 | +Provide clear status updates in the issue: |
| 274 | +- What has been completed |
| 275 | +- What is in progress |
| 276 | +- Any blockers or questions |
| 277 | +- Testing results |
| 278 | + |
| 279 | +### Asking for Clarification |
| 280 | +If requirements are unclear: |
| 281 | +- List specific questions |
| 282 | +- Provide examples of possible interpretations |
| 283 | +- Suggest a preferred approach with rationale |
| 284 | + |
| 285 | +### Completion Message |
| 286 | +When marking an issue as complete, include: |
| 287 | +- Summary of changes made |
| 288 | +- Files modified/created |
| 289 | +- How to test the changes |
| 290 | +- Any follow-up recommendations |
| 291 | + |
| 292 | +## Resource References |
| 293 | + |
| 294 | +- [Block Editor Handbook](https://developer.wordpress.org/block-editor/) |
| 295 | +- [Block API Reference](https://developer.wordpress.org/block-editor/reference-guides/block-api/) |
| 296 | +- [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/) |
| 297 | +- [Gutenberg GitHub Repository](https://github.com/WordPress/gutenberg) |
| 298 | +- [@wordpress/scripts](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/) |
| 299 | +- [Interactivity API](https://developer.wordpress.org/block-editor/reference-guides/interactivity-api/) |
| 300 | + |
| 301 | +## Environment Setup |
| 302 | + |
| 303 | +Always ensure the development environment is properly configured: |
| 304 | + |
| 305 | +1. Install dependencies: `pnpm install` |
| 306 | +2. Start WordPress: `pnpm run env:start` |
| 307 | +3. Build blocks: `pnpm run build` |
| 308 | +4. Access WordPress at: http://localhost:8888 |
| 309 | +5. Login: admin / password |
| 310 | + |
| 311 | +## Important Notes |
| 312 | + |
| 313 | +- This repository is educational - prioritize clarity over complexity |
| 314 | +- Each example should teach ONE main concept clearly |
| 315 | +- Always include comments explaining the "why" not just the "what" |
| 316 | +- Test examples with WordPress 6.8+ to ensure compatibility |
| 317 | +- Use the latest block development practices and APIs |
| 318 | +- Consider beginners when writing examples and documentation |
0 commit comments