Files
peptide-reconstitution-calc…/CONVENTIONS.md
peptiderepo 9aa5309eb4 feat: ship Peptide Reconstitution Calculator v1.0.0
Interactive reconstitution calculator with peptide-specific presets.

Core features:
- [prc_calculator] shortcode with instant client-side math
- Concentration (mg/mL), mcg/unit, injection volume, syringe units, doses/vial
- Live presets from PR Core dosing data (graceful fallback to 8 defaults)
- REST API (prc/v1): presets list/detail + server-side calculate
- Transient-cached presets with event-driven invalidation
- Dark mode + responsive design (320px+)
- Full teardown in uninstall.php

12 PHP files (max 241 lines), 1 JS file, 1 CSS file.
CI: PHP lint 8.1-8.3, PHPCS WordPress, 300-line check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 14:23:59 +07:00

49 lines
2.1 KiB
Markdown

# Peptide Reconstitution Calculator — Conventions
## Naming
- **Class prefix:** `PRC_` — all classes use this prefix.
- **Hook prefix:** `prc_` — all actions and filters start with this.
- **Option prefix:** `prc_` — all wp_options keys start with this.
- **Transient prefix:** `prc_` — all transients start with this.
- **CSS prefix:** `.prc-` — all CSS classes.
- **JS global:** `prcConfig` — inline configuration object.
- **Text domain:** `peptide-reconstitution-calculator`.
- **REST namespace:** `prc/v1`.
## File Naming
Autoloader convention: `PRC_Foo_Bar` maps to `class-prc-foo-bar.php`.
Files live in `includes/` or one level of subdirectory under `includes/`.
## How To: Add a New Preset
1. Add an entry to `PRC_Default_Presets::get_all()` in `includes/class-prc-default-presets.php`.
2. Each preset must include: slug, name, vial_sizes_mg, default_vial_mg, recommended_water_ml, dose_range_min, dose_range_max, dose_unit, typical_frequency, evidence_strength, dosing_row_count, source.
## How To: Modify Calculation Logic
1. Update the calculation in `PRC_Math` (`includes/class-prc-math.php`).
2. Mirror the same change in `assets/js/calculator.js` — the `calculate()` function.
3. Both must produce identical results for the same inputs.
## How To: Add a New Result Field
1. Add the calculation to `PRC_Math::calculate()`.
2. Add the JS mirror in `calculator.js` `calculate()` function.
3. Add a result card in `PRC_Shortcode::render_calculator_html()`.
4. Add CSS for the new card if needed.
## Error Handling
- Math functions return 0 for invalid inputs (division by zero, negative values).
- REST endpoints use WordPress validation callbacks on args.
- The JS calculator hides the results panel when inputs are incomplete.
- The preset provider returns built-in defaults on any PR Core failure.
## Cache Strategy
- Presets are cached in a WordPress transient (`prc_presets_all`) for 1 hour.
- Cache is invalidated by `PRC_Cache_Listener` on PR Core dosing/peptide publish events.
- Cache is also invalidated on plugin activation (flush on fresh start).