|
| 1 | +--- |
| 2 | +name: simpletoc-wordpress-standards |
| 3 | +description: Use when working on the SimpleTOC WordPress plugin, especially for Gutenberg block changes, PHP render logic, settings-page work, styling changes, or editor sidebar options. Apply when implementation quality must stay close to WordPress core patterns: prefer standards, official APIs, block metadata, Settings API, sanitized output, and maintainable SCSS over hacks, CSS tricks, or ad-hoc workarounds. |
| 4 | +--- |
| 5 | + |
| 6 | +# SimpleTOC WordPress Standards |
| 7 | + |
| 8 | +Follow these rules for all changes in this plugin. |
| 9 | + |
| 10 | +## Core Rules |
| 11 | + |
| 12 | +- Stay close to WordPress core and Gutenberg standards. |
| 13 | +- Prefer existing Gutenberg elements, WordPress functions, official APIs, block metadata, block-editor components, and the WordPress Settings API. |
| 14 | +- Write as little custom code as possible. Less is more. |
| 15 | +- Avoid hacks, CSS tricks, hidden coupling, and one-off workarounds. |
| 16 | +- Avoid inline styles unless a user-selected value must be output dynamically and there is no cleaner standard path. |
| 17 | +- Keep layout and reusable presentation rules in SCSS/CSS, not in PHP strings. |
| 18 | +- Sanitize all dynamic PHP output with the appropriate WordPress escaping helpers. |
| 19 | + |
| 20 | +## Documentation Workflow |
| 21 | + |
| 22 | +- Update `readme.txt` only when changing plugin documentation. |
| 23 | +- Do not edit `README.md` by hand. It is generated automatically from `readme.txt` by the GitHub Actions workflow. |
| 24 | +- Keep `readme.txt` valid for WordPress.org first; the generated Markdown README is secondary. |
| 25 | + |
| 26 | +## Block Workflow |
| 27 | + |
| 28 | +- Treat `src/block.json` as the source of truth for block attributes and asset registration. |
| 29 | +- Treat `src/edit.js` as editor configuration only. |
| 30 | +- Remember that SimpleTOC is a dynamic block: frontend markup is rendered in `plugin.php`, not `save.js`. |
| 31 | +- When adding a new editor option, wire it through block attributes first, then implement the frontend effect in the PHP render path or registered frontend styles. |
| 32 | +- Rebuild generated files after source changes so `build/` stays in sync. |
| 33 | + |
| 34 | +## Styling Workflow |
| 35 | + |
| 36 | +- Prefer wrapper classes and registered block stylesheets over hard-coded CSS in PHP. |
| 37 | +- Reuse Gutenberg conventions such as palette-driven colors, `has-background`, and block wrapper attributes when they fit. |
| 38 | +- For optional styling features, expose explicit settings instead of baking in fixed presets unless the requirement is truly global. |
| 39 | +- For global styling behavior, add the option to the SimpleTOC settings page and store it via the existing options flow. |
| 40 | + |
| 41 | +## Settings Workflow |
| 42 | + |
| 43 | +- Add global options in `simpletoc-admin-settings.php`. |
| 44 | +- Register options with `register_setting()`, render them with `add_settings_field()`, and keep labels/help text concise. |
| 45 | +- Respect existing filter overrides when the settings page already follows that pattern. |
| 46 | +- If a global option forces behavior, keep block-level UI simple and make the server-side precedence explicit. |
| 47 | + |
| 48 | +## Project Preferences |
| 49 | + |
| 50 | +- Prefer maintainable, standard-compliant solutions over fast shortcuts. |
| 51 | +- If a request appears to require a workaround, stop and look for the clean WordPress-native approach first. |
| 52 | +- If a compromise is unavoidable, state the tradeoff explicitly before implementing it. |
0 commit comments