Implements ADR-0002: canonical peptide schema as shared data layer for the peptiderepo.com ecosystem. All Tier 1 tools (Reconstitution Calculator, Dosage Reference, Legal Status Tracker, PSA enhancements) build on this. Includes: - pr_peptide CPT with REST, taxonomies, 11 meta fields - 3 custom tables: pr_dosing_rows, pr_legal_cells, pr_ai_candidate_queue - Sequential migration runner with schema versioning - 4 typed DTOs and 4 repository classes (full CRUD) - REST API (pr-core/v1): 6 endpoints (read public, write auth-gated) - Admin UI: 3 meta boxes, custom columns, AI candidate queue page - Shared disclaimer component (shortcode + static API) - JSON-LD Drug schema emission on single peptide pages - Seed data fixture (3 peptides, 10 dosing rows, 5 legal cells) - Full teardown in uninstall.php - CI: PHP lint 8.0-8.2, PHPCS WordPress, 300-line check All 22 PHP files under 300 lines. Highest: peptide-cpt at 265. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Plugin activation handler.
|
|
*
|
|
* What: Runs migrations, adds capabilities, flushes rewrite rules.
|
|
* Who calls it: register_activation_hook() in peptide-repo-core.php.
|
|
* Dependencies: PR_Core_Migration_Runner.
|
|
*
|
|
* @see peptide-repo-core.php — Registers this class on activation.
|
|
*/
|
|
class PR_Core_Activator {
|
|
|
|
/**
|
|
* Run on plugin activation.
|
|
*
|
|
* Side effects: database table creation, capability grants, rewrite flush.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function activate(): void {
|
|
// Run all pending migrations (creates tables).
|
|
$runner = new PR_Core_Migration_Runner();
|
|
$runner->run_pending();
|
|
|
|
// Register CPT so rewrite rules exist before flush.
|
|
PR_Core_Peptide_CPT::register_peptide_post_type();
|
|
PR_Core_Peptide_CPT::register_taxonomies();
|
|
|
|
// Grant manage_peptide_content to administrators and editors.
|
|
self::add_capabilities();
|
|
|
|
// Flush rewrite rules for the new CPT.
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Grant the manage_peptide_content capability to appropriate roles.
|
|
*
|
|
* Side effects: modifies role capabilities in database.
|
|
*
|
|
* @return void
|
|
*/
|
|
private static function add_capabilities(): void {
|
|
$cap = 'manage_peptide_content';
|
|
$roles = [ 'administrator', 'editor' ];
|
|
|
|
foreach ( $roles as $role_name ) {
|
|
$role = get_role( $role_name );
|
|
if ( $role && ! $role->has_cap( $cap ) ) {
|
|
$role->add_cap( $cap );
|
|
}
|
|
}
|
|
}
|
|
}
|