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>
2.1 KiB
2.1 KiB
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
- Add an entry to
PRC_Default_Presets::get_all()inincludes/class-prc-default-presets.php. - 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
- Update the calculation in
PRC_Math(includes/class-prc-math.php). - Mirror the same change in
assets/js/calculator.js— thecalculate()function. - Both must produce identical results for the same inputs.
How To: Add a New Result Field
- Add the calculation to
PRC_Math::calculate(). - Add the JS mirror in
calculator.jscalculate()function. - Add a result card in
PRC_Shortcode::render_calculator_html(). - 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_Listeneron PR Core dosing/peptide publish events. - Cache is also invalidated on plugin activation (flush on fresh start).