|
| 1 | +--- |
| 2 | +trigger: always_on |
| 3 | +description: Enterprise code change principles for safe, minimal-scope modifications. |
| 4 | +--- |
| 5 | + |
| 6 | +# Enterprise Code Change Principles |
| 7 | + |
| 8 | +Critical principles for enterprise-level plugin development. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Core Principles |
| 13 | + |
| 14 | +1. **NEVER guess**: Always search and verify before making changes |
| 15 | +2. **Minimal scope**: Fix at the most specific location, closest to the problem |
| 16 | +3. **Backward compatibility**: Maintain 100% compatibility with existing callers |
| 17 | +4. **No custom solutions**: Never invent new patterns. Use existing ones or search the web to review best practices, then follow the official WordPress standards or VIP guidelines. |
| 18 | +5. **User changes are final**: If user makes manual changes, treat as authoritative |
| 19 | +6. **Multi-issue fixes**: When fixing multiple issues in one request, run all 6 phases independently for each issue. Findings from one issue's phases may inform the next, but every phase is mandatory for every issue, even when issues share a root cause. |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Analysis Phase |
| 24 | + |
| 25 | +Before proposing solutions: |
| 26 | + |
| 27 | +### Phase 1: Understand |
| 28 | + |
| 29 | +- Read and understand the complete issue |
| 30 | +- Clarify expected vs actual behavior |
| 31 | +- Identify reproduction steps |
| 32 | +- Determine scope: which plugin(s), which feature(s) |
| 33 | +- **Cross-plugin**: Identify if the feature or setting exists in Lite, Pro, or both. Understand the full feature context across all relevant plugins |
| 34 | + - Working on an addon: research must include Lite AND Pro |
| 35 | + - Working on Pro: research must include Lite |
| 36 | + - Working on Lite: check if the change affects Pro or any active addon |
| 37 | + |
| 38 | +### Phase 2: Locate |
| 39 | + |
| 40 | +- Use code_search to find the root cause (not just symptoms) |
| 41 | +- Trace execution flow from entry point to failure |
| 42 | +- **Analyze complete context** of the class or file being changed — all features, logic, and flows |
| 43 | +- **Trace parent hierarchy**: search parent classes and files up to plugin root |
| 44 | +- **CSS-Specific Rules - Trace complete style cascade**: When debugging CSS on an element, identify ALL classes on the element and its ancestors, then search for ALL CSS rules affecting it (not just the obvious class). Understand the complete cascade before proposing changes |
| 45 | +- Identify ALL affected locations in the codebase |
| 46 | +- Map dependencies: what calls this code, what does this code call |
| 47 | +- Check plugin requirements: must code work standalone or require Pro/addons |
| 48 | +- **Cross-plugin**: Search for the same feature, helper, or code path in Lite and Pro (and addons if relevant). Understand how data flows between plugins |
| 49 | + |
| 50 | +### Phase 3: Research |
| 51 | + |
| 52 | +- **Never invent custom solutions if existing patterns exist** |
| 53 | +- Find existing patterns: search models, controllers, helpers, views for similar functionality |
| 54 | +- Study pattern usage: search ALL places using the pattern |
| 55 | +- Search official WordPress/VIP docs: function parameters, return types, deprecated alternatives |
| 56 | +- Search platform-specific docs: performance and security best practices |
| 57 | +- Verify alignment: ensure approach matches existing codebase patterns |
| 58 | +- **Cross-plugin**: Search for existing patterns and helpers in Lite and Pro that already solve the problem. Reuse them instead of inventing new solutions |
| 59 | +- **Iterate**: if a better pattern is found, repeat from Phase 2 |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Solution Phase |
| 64 | + |
| 65 | +### Phase 4: Select Solution |
| 66 | + |
| 67 | +- Propose 2-3 solutions with trade-offs clearly stated |
| 68 | +- Select the solution with minimal scope and lowest risk |
| 69 | +- Fix at the most specific location, closest to root cause |
| 70 | +- Prefer adding safety checks over refactoring |
| 71 | +- Fix must be testable without touching other code |
| 72 | +- **Verify changes are not overkill**: If affecting several areas, review everything carefully to make sure the fix is not excessive. If it is, go back to Phase 2 |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +## Change Phase |
| 77 | + |
| 78 | +### Phase 5: Implement |
| 79 | + |
| 80 | +- Never refactor unrelated code in the same commit |
| 81 | +- If a rule conflicts with existing code in the file being modified, follow the rule for new code but do not refactor unrelated existing code |
| 82 | +- Make the smallest change that completely solves the problem |
| 83 | +- **CSS-Specific Rules - Never modify shared CSS classes**: If a CSS class is already used elsewhere in the plugin, do not change its behavior. Instead, add a new specific class for the feature and define new styles for it |
| 84 | +- Use Big-O to compare algorithms and choose the most efficient one for large inputs and iterations |
| 85 | +- Never change method signatures, return types, or data structures |
| 86 | +- Add defensive checks where data comes in, not where used everywhere |
| 87 | +- Add PHPDoc/JSDoc for new methods/properties/functions and comments for complex logic |
| 88 | +- Never guess the version number and use `@since x.x` as the version placeholder in docblocks |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Change Verification Phase |
| 93 | + |
| 94 | +### Phase 6: Verify |
| 95 | + |
| 96 | +- Confirm fix resolves the reported issue |
| 97 | +- Confirm backward compatibility with existing callers |
| 98 | +- Confirm this change does not break any existing functionality |
| 99 | +- Test with Pro plugin active AND inactive |
| 100 | +- Test with empty data and missing keys |
| 101 | +- Confirm no PHP warnings, notices, or errors in any scenario |
| 102 | +- Test edge cases |
| 103 | +- Remove all debug code (error_log statements, debug comments, debug files) |
| 104 | +- Verify code passes phpcs/linting checks |
0 commit comments