Compare commits
30 Commits
feature/v0
...
fix/v0.3.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d4ce64c1c | ||
|
|
c24259f1d7 | ||
|
|
6ab828087d | ||
|
|
79259bf5ac | ||
|
|
deadccc27b | ||
|
|
05cb3caf0d | ||
|
|
21d05427d8 | ||
|
|
9c59fe6706 | ||
|
|
e0fcace223 | ||
|
|
a10610ded7 | ||
|
|
2195b449b2 | ||
|
|
ba4e11192f | ||
|
|
0f62abd6e9 | ||
|
|
b885673a1f | ||
|
|
35e62e8cf1 | ||
|
|
bd1b2dba48 | ||
|
|
0dcad0de0b | ||
|
|
d5376d1612 | ||
|
|
28e110f780 | ||
|
|
bb34998d2c | ||
|
|
2e7efab97a | ||
|
|
0210d73cf7 | ||
|
|
14f8e6159a | ||
|
|
6359a18fed | ||
|
|
33dc8a183a | ||
|
|
a21d35ee27 | ||
|
|
a906e1b701 | ||
|
|
4d8e98f34b | ||
|
|
bb3967a071 | ||
|
|
f086b89e2d |
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@@ -29,6 +29,13 @@ jobs:
|
|||||||
- name: Syntax check all PHP files
|
- name: Syntax check all PHP files
|
||||||
run: find . -name "*.php" -not -path "./vendor/*" | xargs -n 1 php -l
|
run: find . -name "*.php" -not -path "./vendor/*" | xargs -n 1 php -l
|
||||||
|
|
||||||
|
- name: Unit tests (lightweight, no PHPUnit)
|
||||||
|
run: |
|
||||||
|
for test in tests/unit/test-*.php; do
|
||||||
|
echo "=== Running $test ==="
|
||||||
|
php "$test"
|
||||||
|
done
|
||||||
|
|
||||||
# ── WordPress Coding Standards (PHP CodeSniffer) ──────────────────
|
# ── WordPress Coding Standards (PHP CodeSniffer) ──────────────────
|
||||||
lint-phpcs:
|
lint-phpcs:
|
||||||
name: WordPress Coding Standards
|
name: WordPress Coding Standards
|
||||||
|
|||||||
73
.github/workflows/deploy.yml
vendored
73
.github/workflows/deploy.yml
vendored
@@ -7,67 +7,84 @@ on:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
# Cancel previous deploys if a new push arrives while one is running.
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: deploy-peptide-repo-core
|
group: deploy-peptide-repo-core
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
# ── Run CI first ─────────────────────────────────────────────────
|
|
||||||
ci:
|
ci:
|
||||||
name: Pre-deploy CI
|
name: Pre-deploy CI
|
||||||
uses: ./.github/workflows/ci.yml
|
uses: ./.github/workflows/ci.yml
|
||||||
|
|
||||||
# ── Deploy via rsync over SSH ────────────────────────────────────
|
deploy-staging:
|
||||||
deploy:
|
name: Deploy to Staging
|
||||||
needs: ci
|
needs: ci
|
||||||
name: Deploy to Production
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
environment: staging
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- uses: actions/checkout@v4
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup SSH key
|
- name: Setup SSH key
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||||
chmod 600 ~/.ssh/deploy_key
|
chmod 600 ~/.ssh/deploy_key
|
||||||
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
- name: Deploy via rsync → staging
|
||||||
- name: Deploy via rsync
|
|
||||||
run: |
|
run: |
|
||||||
rsync -avz --delete \
|
rsync -avz --delete \
|
||||||
--exclude '.git' \
|
--exclude '.git' --exclude '.github' \
|
||||||
--exclude '.github' \
|
--exclude 'tests' --exclude 'phpunit.xml.dist' \
|
||||||
--exclude 'tests' \
|
--exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
--exclude 'phpunit.xml.dist' \
|
--exclude 'vendor' --exclude 'phpcs.xml.dist' \
|
||||||
--exclude 'composer.json' \
|
--exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' --exclude 'CHANGELOG.md' \
|
||||||
--exclude 'composer.lock' \
|
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
||||||
--exclude 'vendor' \
|
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/staging/wp-content/plugins/peptide-repo-core/
|
||||||
--exclude 'phpcs.xml.dist' \
|
- name: Staging health check
|
||||||
--exclude 'ARCHITECTURE.md' \
|
run: |
|
||||||
--exclude 'CONVENTIONS.md' \
|
sleep 5
|
||||||
--exclude 'CHANGELOG.md' \
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://staging.peptiderepo.com/ || echo "000")
|
||||||
|
echo "Staging responded: HTTP $STATUS"
|
||||||
|
- name: Cleanup
|
||||||
|
if: always()
|
||||||
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
|
||||||
|
deploy-production:
|
||||||
|
name: Deploy to Production
|
||||||
|
needs: [ci, deploy-staging]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment: production
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Setup SSH key
|
||||||
|
run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/deploy_key
|
||||||
|
chmod 600 ~/.ssh/deploy_key
|
||||||
|
ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
- name: Deploy via rsync → production
|
||||||
|
run: |
|
||||||
|
rsync -avz --delete \
|
||||||
|
--exclude '.git' --exclude '.github' \
|
||||||
|
--exclude 'tests' --exclude 'phpunit.xml.dist' \
|
||||||
|
--exclude 'composer.json' --exclude 'composer.lock' \
|
||||||
|
--exclude 'vendor' --exclude 'phpcs.xml.dist' \
|
||||||
|
--exclude 'ARCHITECTURE.md' --exclude 'CONVENTIONS.md' --exclude 'CHANGELOG.md' \
|
||||||
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
-e "ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }}" \
|
||||||
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-repo-core/
|
./ ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:~/domains/peptiderepo.com/public_html/wp-content/plugins/peptide-repo-core/
|
||||||
|
|
||||||
- name: Purge LiteSpeed Cache
|
- name: Purge LiteSpeed Cache
|
||||||
run: |
|
run: |
|
||||||
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} \
|
ssh -i ~/.ssh/deploy_key -p ${{ secrets.SSH_PORT }} \
|
||||||
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} \
|
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} \
|
||||||
"cd ~/domains/peptiderepo.com/public_html && find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null || true"
|
"cd ~/domains/peptiderepo.com/public_html && find wp-content/litespeed/ -type f -delete 2>/dev/null; touch .lscache_purge 2>/dev/null || true"
|
||||||
|
- name: Production health check
|
||||||
- name: Health check
|
|
||||||
run: |
|
run: |
|
||||||
sleep 5
|
sleep 5
|
||||||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://peptiderepo.com)
|
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://peptiderepo.com)
|
||||||
if [ "$STATUS" != "200" ] && [ "$STATUS" != "403" ]; then
|
if [ "$STATUS" != "200" ] && [ "$STATUS" != "403" ]; then
|
||||||
echo "ERROR: Site returned unexpected HTTP $STATUS after deploy"
|
echo "ERROR: Site returned HTTP $STATUS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "Site is responsive (HTTP $STATUS)"
|
echo "Production healthy (HTTP $STATUS)"
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: rm -f ~/.ssh/deploy_key
|
run: rm -f ~/.ssh/deploy_key
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Peptide Repo Core — Architecture
|
# Peptide Repo Core — Architecture
|
||||||
|
|
||||||
Peptide Repo Core is a WordPress plugin that provides the canonical peptide data layer for the peptiderepo.com ecosystem. It defines the `pr_peptide` custom post type, custom tables for dosing rows and legal status cells, typed repository classes, an AI candidate queue for semi-automated data extraction, a shared disclaimer component, and JSON-LD structured data output. Every consumer plugin (PR Theme, PRAutoBlogger, Peptide News, Peptide Search AI, and all Tier 1 tools) reads peptide data through this plugin's versioned PHP API, never directly.
|
Peptide Repo Core is a WordPress plugin that provides the canonical peptide data layer for the peptiderepo.com ecosystem. It owns the `peptide` custom post type (consolidated in v0.2.0; previously registered by Peptide Search AI pre-schema-sprint — PSA v4.5.0 drops its registration in favor of this one), the `peptide_category` taxonomy, custom tables for dosing rows and legal status cells, typed repository classes, an AI candidate queue for semi-automated data extraction, a shared disclaimer component, and JSON-LD structured data output. Every consumer plugin (PR Theme, PRAutoBlogger, Peptide News, Peptide Search AI, and all Tier 1 tools) reads peptide data through this plugin's versioned PHP API, never directly.
|
||||||
|
|
||||||
|
**Ownership model (v0.2.0+).** PR Core is the sole registrant of the `peptide` CPT and `peptide_category` taxonomy. Registration is guarded by `post_type_exists()` / `taxonomy_exists()` so a second registration from any other plugin (historically PSA, which now defers) no-ops cleanly and deploy order between plugins does not matter. See CONVENTIONS.md for the CPT ownership rule.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ Peptide Repo Core is a WordPress plugin that provides the canonical peptide data
|
|||||||
│
|
│
|
||||||
▼
|
▼
|
||||||
┌───────────────────────┐
|
┌───────────────────────┐
|
||||||
│ Peptide Repository │ pr_peptide CPT + meta
|
│ Peptide Repository │ peptide CPT + meta
|
||||||
└──────────┬────────────┘
|
└──────────┬────────────┘
|
||||||
│
|
│
|
||||||
┌───────────────┼───────────────┐
|
┌───────────────┼───────────────┐
|
||||||
@@ -44,7 +46,7 @@ Peptide Repo Core is a WordPress plugin that provides the canonical peptide data
|
|||||||
```
|
```
|
||||||
peptide-repo-core/
|
peptide-repo-core/
|
||||||
├── peptide-repo-core.php # Plugin bootstrap — constants, autoloader, activation hooks
|
├── peptide-repo-core.php # Plugin bootstrap — constants, autoloader, activation hooks
|
||||||
├── uninstall.php # Full teardown: tables, posts, terms, options, capabilities
|
├── uninstall.php # Selective teardown: plugin-owned posts + tables + options + caps
|
||||||
├── ARCHITECTURE.md # This file
|
├── ARCHITECTURE.md # This file
|
||||||
├── CONVENTIONS.md # Naming patterns, extension guides
|
├── CONVENTIONS.md # Naming patterns, extension guides
|
||||||
├── CHANGELOG.md # Semantic versioning changelog
|
├── CHANGELOG.md # Semantic versioning changelog
|
||||||
@@ -53,7 +55,7 @@ peptide-repo-core/
|
|||||||
│
|
│
|
||||||
├── .github/
|
├── .github/
|
||||||
│ └── workflows/
|
│ └── workflows/
|
||||||
│ └── ci.yml # PHP lint (8.1-8.3), PHPCS WordPress, 300-line check
|
│ └── ci.yml # PHP lint (8.1-8.3), PHPCS WordPress, 300-line check, unit tests
|
||||||
│
|
│
|
||||||
├── assets/
|
├── assets/
|
||||||
│ └── css/
|
│ └── css/
|
||||||
@@ -61,13 +63,13 @@ peptide-repo-core/
|
|||||||
│
|
│
|
||||||
├── includes/
|
├── includes/
|
||||||
│ ├── class-pr-core.php # Main orchestrator — boots subsystems, registers public filters
|
│ ├── class-pr-core.php # Main orchestrator — boots subsystems, registers public filters
|
||||||
│ ├── class-pr-core-activator.php # Activation: migrations, capabilities, rewrite flush
|
│ ├── class-pr-core-activator.php # Activation + version-change flush handler
|
||||||
│ ├── class-pr-core-deactivator.php # Deactivation: rewrite flush only (data preserved)
|
│ ├── class-pr-core-deactivator.php # Deactivation: rewrite flush only (data preserved)
|
||||||
│ ├── class-pr-core-autoloader.php # SPL autoloader for PR_Core_ prefixed classes
|
│ ├── class-pr-core-autoloader.php # SPL autoloader for PR_Core_ prefixed classes
|
||||||
│ ├── class-pr-core-seed-data.php # Dev fixture: 3 peptides, 10 dosing rows, 5 legal cells
|
│ ├── class-pr-core-seed-data.php # Dev fixture: 3 peptides, 10 dosing rows, 5 legal cells
|
||||||
│ │
|
│ │
|
||||||
│ ├── cpt/
|
│ ├── cpt/
|
||||||
│ │ └── class-pr-core-peptide-cpt.php # CPT registration, taxonomies, meta fields, sanitizers
|
│ │ └── class-pr-core-peptide-cpt.php # CPT + peptide_category registration (guarded), meta fields, sanitizers
|
||||||
│ │
|
│ │
|
||||||
│ ├── migrations/
|
│ ├── migrations/
|
||||||
│ │ ├── class-pr-core-migration-runner.php # Sequential migration engine
|
│ │ ├── class-pr-core-migration-runner.php # Sequential migration engine
|
||||||
@@ -82,7 +84,7 @@ peptide-repo-core/
|
|||||||
│ │ └── class-pr-core-candidate-dto.php # Typed candidate queue value object
|
│ │ └── class-pr-core-candidate-dto.php # Typed candidate queue value object
|
||||||
│ │
|
│ │
|
||||||
│ ├── repositories/
|
│ ├── repositories/
|
||||||
│ │ ├── class-pr-core-peptide-repository.php # CRUD for pr_peptide CPT
|
│ │ ├── class-pr-core-peptide-repository.php # CRUD for peptide CPT
|
||||||
│ │ ├── class-pr-core-dosing-repository.php # CRUD for pr_dosing_rows
|
│ │ ├── class-pr-core-dosing-repository.php # CRUD for pr_dosing_rows
|
||||||
│ │ ├── class-pr-core-legal-repository.php # CRUD for pr_legal_cells
|
│ │ ├── class-pr-core-legal-repository.php # CRUD for pr_legal_cells
|
||||||
│ │ └── class-pr-core-candidate-queue-repository.php # CRUD + approve/reject for queue
|
│ │ └── class-pr-core-candidate-queue-repository.php # CRUD + approve/reject for queue
|
||||||
@@ -101,8 +103,9 @@ peptide-repo-core/
|
|||||||
│ └── class-pr-core-rest-controller.php # REST endpoints for peptides, dosing, legal
|
│ └── class-pr-core-rest-controller.php # REST endpoints for peptides, dosing, legal
|
||||||
│
|
│
|
||||||
└── tests/
|
└── tests/
|
||||||
├── unit/ # PHPUnit tests (mocked WP)
|
├── bootstrap.php # Lightweight WP function mocks for no-PHPUnit unit runs
|
||||||
└── integration/ # WordPress integration tests
|
└── unit/
|
||||||
|
└── test-peptide-cpt.php # CPT + taxonomy guard + args payload assertions
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -180,3 +183,16 @@ Single editorial review point. All consumer plugins render the same versioned di
|
|||||||
|
|
||||||
### #6: JSON-LD from day one
|
### #6: JSON-LD from day one
|
||||||
Drug schema on single pages increases LLM citation rate. Filter hook allows consumer plugins to extend the schema object.
|
Drug schema on single pages increases LLM citation rate. Filter hook allows consumer plugins to extend the schema object.
|
||||||
|
|
||||||
|
### #7: PR Core owns the `peptide` CPT and `peptide_category` taxonomy (v0.2.0)
|
||||||
|
Prior to v0.2.0, PR Core registered `pr_peptide` while Peptide Search AI registered `peptide` — both claimed the public rewrite slug `peptides`, and WP's rewrite resolver picked PR Core's empty CPT, 404'ing all 89 production peptide detail pages. v0.2.0 consolidates both registrations onto a single `peptide` CPT, owned by PR Core. PSA v4.5.0 drops its CPT/taxonomy registration; its meta boxes (`psa_peptide_data`, `psa_extended_data`), directory shortcode, KB article renderer, and search widget continue operating on the shared `peptide` CPT regardless of who registers it. Registration on both sides is guarded with `post_type_exists()` / `taxonomy_exists()` so deploy order is forgiving.
|
||||||
|
|
||||||
|
## §2.9 Uninstall specification
|
||||||
|
|
||||||
|
PR Core `uninstall.php` removes plugin-owned data only:
|
||||||
|
|
||||||
|
1. **Drops custom tables** — `pr_dosing_rows`, `pr_legal_cells`, `pr_ai_candidate_queue`.
|
||||||
|
2. **Deletes `peptide` posts only if they carry the `_pr_core_authored` meta flag.** The 89 canonical peptide posts predate PR Core and were authored via PSA; they are never blanket-deleted on PR Core uninstall.
|
||||||
|
3. **Does not delete `peptide_category` terms.** Shared-ownership taxonomy; term metadata the site relies on outlasts this plugin.
|
||||||
|
4. **Deletes `pr_core_*` options.**
|
||||||
|
5. **Removes `manage_peptide_content` capability from all roles.**
|
||||||
|
|||||||
71
CHANGELOG.md
71
CHANGELOG.md
@@ -3,6 +3,77 @@
|
|||||||
All notable changes to Peptide Repo Core are documented here.
|
All notable changes to Peptide Repo Core are documented here.
|
||||||
Format: [Semantic Versioning](https://semver.org/).
|
Format: [Semantic Versioning](https://semver.org/).
|
||||||
|
|
||||||
|
## [0.3.2] — 2026-04-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Remove `rest_namespace` from peptide CPT registration. Custom namespace prevented Gutenberg block editor from loading peptide posts for editing (404 on wp/v2 REST route). All 89 peptide entries are now editable in the block editor. (#5)
|
||||||
|
|
||||||
|
## [0.3.1] — 2026-04-24
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Add missing `PR_Core_Related_Posts_Provider` interface file (`class-pr-core-related-posts-provider.php`).
|
||||||
|
Omitted from v0.3.0 deploy caused a fatal on every page load. Site was down until this fix.
|
||||||
|
|
||||||
|
## [0.3.0] — 2026-04-24
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- **Related Articles feature** — New `peptide_topic` taxonomy links blog posts to peptides by slug. Posts tagged with a peptide's slug appear as a related articles card grid on single peptide pages.
|
||||||
|
- `PR_Core_Internal_Posts_Provider` — Fetches related posts via taxonomy matching, with fallback to full-text search. Results cached 1 hour per peptide.
|
||||||
|
- `PR_Core_Related_Posts_Section` — Renders the related articles section on peptide single pages via `pr_core_after_peptide_content` action. Respects admin settings for feature toggle and display limit.
|
||||||
|
- `PR_Core_Settings` — Admin settings page under Peptides menu. Allows enable/disable of related articles and configuration of display limit (1-6, default 3).
|
||||||
|
- Template part `template-parts/related-posts/card.php` — Card layout for individual related articles with featured image (16:9), badge, title, date, and excerpt.
|
||||||
|
- CSS file `assets/css/related-posts.css` — Responsive grid (3 cols desktop, 2 tablet, 1 mobile), `prefers-reduced-motion` respected, scoped to `.pr-related-posts`.
|
||||||
|
- Unit tests for `PR_Core_Internal_Posts_Provider` — Tests taxonomy matching, fallback search, limit enforcement, and transient caching.
|
||||||
|
- `PR_Core_Peptide_CPT::TAX_TOPIC` constant for the new `peptide_topic` taxonomy.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `PR_Core_Peptide_CPT::register_taxonomies()` now registers both `peptide_category` (peptide → peptide) and `peptide_topic` (post → peptide) taxonomies.
|
||||||
|
- `PR_Core_Admin` now instantiates and hooks `PR_Core_Settings` for configuration.
|
||||||
|
- `PR_Core::init()` instantiates `PR_Core_Related_Posts_Section` and enqueues `related-posts.css` on single peptide pages.
|
||||||
|
- `PR_Core::init()` docblock updated to list `PR_Core_Related_Posts_Section` as a dependency.
|
||||||
|
- Version bumped to `0.3.0`.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
- The `pr_core_after_peptide_content` action must be called in peptide single-page templates to display the related articles section. This hook fires after the main peptide content.
|
||||||
|
- Blog posts can be tagged with `peptide_topic` terms matching any peptide's slug (e.g., 'bpc-157', 'tb-500') to appear as related articles on that peptide's page.
|
||||||
|
- Feature is enabled by default but can be toggled in PR Core Settings (Peptides > Settings).
|
||||||
|
- Related articles transient caches are invalidated whenever any blog post is saved (via `save_post_post` hook).
|
||||||
|
|
||||||
|
## [0.2.1] — 2026-04-22
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- **P1 hotfix: fatal `Undefined constant PR_Core_Peptide_CPT::TAX_FAMILY` on every peptide page.** The v0.2.0 release removed `TAX_FAMILY` from `PR_Core_Peptide_CPT` but left two stale references in `PR_Core_Peptide_Repository` (the `family` filter branch in `find_all()` and the families lookup in `post_to_dto()`). JSON-LD emission on single-peptide templates called `find_by_id()`, which called `post_to_dto()`, which hit the undefined constant and killed page rendering mid-`wp_head()`. QA gate on `874f93b` missed this because the unit tests cover the CPT class in isolation, not the repository's consumption of its constants. Post-mortem + QA checklist update to follow.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `PR_Core_Peptide_Repository::find_all()` — `family` filter is now silently ignored rather than throwing. Next minor bump will remove it from the REST schema.
|
||||||
|
- `PR_Core_Peptide_DTO::$families` is preserved but always populated as `[]`. Keeps REST response shape stable for existing clients; will be dropped with a release note.
|
||||||
|
|
||||||
|
## [0.2.0] — 2026-04-22
|
||||||
|
|
||||||
|
### Changed (BREAKING)
|
||||||
|
- CPT renamed from `pr_peptide` to `peptide`. Consolidates with PSA's existing `peptide` CPT which owns the 89 canonical peptide posts on production.
|
||||||
|
- Taxonomy renamed from `pr_peptide_category` to `peptide_category`. Same reason.
|
||||||
|
- CPT args harmonized as superset of PSA + prior PR Core registration (supports now includes thumbnail + revisions + custom-fields).
|
||||||
|
- Defensive registration: guards with `post_type_exists()` / `taxonomy_exists()` so PSA's parallel registration no-ops cleanly during the PSA v4.5.0 transition.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `PR_Core_Activator::maybe_flush_on_version_change()` — one-shot rewrite flush on in-place version bumps (hooked at `init` priority 999). Eliminates the need for a manual `wp rewrite flush` after updates that change CPT/taxonomy slugs.
|
||||||
|
- `_pr_core_authored` post-meta flag contract — peptide posts created via PR Core UI carry this flag; `uninstall.php` uses it to scope teardown to plugin-owned posts only.
|
||||||
|
- Lightweight unit-test harness (`tests/bootstrap.php` + `tests/unit/test-peptide-cpt.php`) that exercises CPT/taxonomy guards and args payload shape without a PHPUnit + wp-env dependency. Wired into the existing PHP-lint CI job.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- `pr_peptide_family` taxonomy — never populated, never surfaced in UI.
|
||||||
|
- All `pr_peptide*` CPT-slug-derived references (constants, docblock mentions, uninstall string literals).
|
||||||
|
- Blanket `DELETE FROM posts WHERE post_type = 'pr_peptide'` on uninstall. Replaced with a join-on-`_pr_core_authored` selective delete so PSA-authored peptide posts are never destroyed by PR Core teardown.
|
||||||
|
- Taxonomy-term cleanup on uninstall. `peptide_category` is shared ownership post-v0.2.0; term data the site still needs is preserved.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Production peptide detail pages (all 89) were 404'ing due to a rewrite slug collision between PSA's `peptide` CPT and PR Core's `pr_peptide` CPT both claiming `/peptides/%postname%/`. PR Core v0.1.1's empty `pr_peptide` CPT was winning the rewrite resolution. This release consolidates both to a single `peptide` CPT owned by PR Core.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
- Scope of the `pr_peptide*` scrub is intentionally narrow: CPT-slug-derived identifiers only. Class names (`PR_Core_Peptide_CPT`), file names (`class-pr-core-peptide-cpt.php`), plugin constants (`PR_CORE_VERSION`), option keys (`pr_core_*`), and the REST namespace (`pr-core/v1`) are the plugin's own namespace, not the CPT slug, and are preserved verbatim.
|
||||||
|
- PR Core-defined meta keys (`display_name`, `aliases`, `evidence_strength`, `editorial_review_status`, …) are gated by `manage_peptide_content`. The activator grants this capability to `administrator` and `editor` roles on activation. Prod sites where the activation hook never fired (v0.1.1 was deployed manually) will receive the grant on next `wp plugin activate peptide-repo-core`. Follow-up thread to decide whether a dedicated `peptide_editor` role is more appropriate than extending core `editor`.
|
||||||
|
|
||||||
## [0.1.1] — 2026-04-19
|
## [0.1.1] — 2026-04-19
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -61,3 +61,14 @@ Values: `prescription`, `ruo`, `otc`, `restricted`, `banned`, `unclear`. Validat
|
|||||||
## Supersede Pattern (Soft Delete)
|
## Supersede Pattern (Soft Delete)
|
||||||
|
|
||||||
Dosing rows and legal cells use a `superseded_by_id` column instead of hard deletes. When a correction is needed, the old row gets `superseded_by_id` set to the new row's ID. Queries for "active" data filter on `superseded_by_id IS NULL`. This preserves full audit history.
|
Dosing rows and legal cells use a `superseded_by_id` column instead of hard deletes. When a correction is needed, the old row gets `superseded_by_id` set to the new row's ID. Queries for "active" data filter on `superseded_by_id IS NULL`. This preserves full audit history.
|
||||||
|
|
||||||
|
## CPT Ownership
|
||||||
|
|
||||||
|
- **One plugin owns each CPT.** PR Core owns the `peptide` CPT and the `peptide_category` taxonomy (as of v0.2.0). No other plugin in this ecosystem registers these post types or taxonomies directly.
|
||||||
|
- **All registrations must guard with existence checks.** CPT registrations call `if ( post_type_exists( $slug ) ) return;` before `register_post_type()`, and taxonomy registrations call `if ( taxonomy_exists( $slug ) ) return;` before `register_taxonomy()`. This makes deploy order between plugins irrelevant — whichever runs first wins, the other no-ops — and prevents rewrite-slug collisions when two plugins temporarily overlap during a transition.
|
||||||
|
- **Consumers read, do not register.** Plugins that need to query or display `peptide` posts (PSA, PR Theme, PRAutoBlogger, Peptide News, Tier 1 tools) call `get_posts( [ 'post_type' => 'peptide' ] )` / `WP_Query` without registering the CPT themselves. If a consumer plugin needs its own custom post type for a different domain (e.g., `reconstitution_protocol`), it registers its own slug and does not touch `peptide`.
|
||||||
|
- **Meta keys are plugin-namespaced, not CPT-namespaced.** PR Core writes `_pr_core_*` or bare keys registered via `register_post_meta()`. PSA writes `psa_*`. The two namespaces coexist on the same `peptide` post because they don't collide.
|
||||||
|
|
||||||
|
## `_pr_core_authored` Flag
|
||||||
|
|
||||||
|
Any `peptide` post created via PR Core's own UI (not authored via PSA's meta boxes) must be tagged with post-meta key `_pr_core_authored` = `1`. This is the flag `uninstall.php` uses to scope teardown to plugin-owned posts only. Posts originating from PSA (the 89 canonical peptide monographs on production) do not carry this flag and are never deleted on PR Core uninstall.
|
||||||
|
|||||||
192
assets/css/related-posts.css
Normal file
192
assets/css/related-posts.css
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
/**
|
||||||
|
* Related Posts Section Styles
|
||||||
|
* Scoped to .pr-related-posts
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts {
|
||||||
|
margin-top: 3rem;
|
||||||
|
padding: 2rem 0;
|
||||||
|
border-top: 1px solid var(--wp--preset--color--border, #e5e5e5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts h2 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 1.5rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: white;
|
||||||
|
border: 1px solid var(--wp--preset--color--border, #e5e5e5);
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: box-shadow 0.3s ease, transform 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__card:hover {
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.pr-related-posts__card {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__card:hover {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__image {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-bottom: 56.25%;
|
||||||
|
/* 16:9 aspect ratio */
|
||||||
|
background: var(--wp--preset--color--base, #f5f5f5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__image--fallback {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding-bottom: 0;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__image-element {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
object-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__image--fallback .pr-related-posts__image-element {
|
||||||
|
position: static;
|
||||||
|
width: auto;
|
||||||
|
height: 80px;
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
flex: 1;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__badge {
|
||||||
|
display: inline-block;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__title {
|
||||||
|
font-size: 1.125rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__title a {
|
||||||
|
color: var(--wp--preset--color--heading, #000);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__title a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__date {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: #999;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__excerpt {
|
||||||
|
font-size: 0.9375rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #666;
|
||||||
|
margin: 0;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__view-all {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 1rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__view-all a {
|
||||||
|
color: var(--wp--preset--color--primary, #0073aa);
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__view-all a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tablet: 2 columns */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.pr-related-posts__grid {
|
||||||
|
grid-template-columns: repeat(2, 1fr);
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts h2 {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts {
|
||||||
|
margin-top: 2rem;
|
||||||
|
padding: 1.5rem 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile: 1 column */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.pr-related-posts__grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts h2 {
|
||||||
|
font-size: 1.125rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts {
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
padding: 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__content {
|
||||||
|
padding: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pr-related-posts__title {
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom admin list-table columns for the pr_peptide CPT.
|
* Custom admin list-table columns for the peptide CPT.
|
||||||
*
|
*
|
||||||
* What: Adds evidence strength, editorial status, and dosing count columns.
|
* What: Adds evidence strength, editorial status, and dosing count columns.
|
||||||
* Who calls it: PR_Core_Admin via manage_posts_columns and custom_column hooks.
|
* Who calls it: PR_Core_Admin via manage_posts_columns and custom_column hooks.
|
||||||
|
|||||||
@@ -4,13 +4,16 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Admin initialization and hook registration.
|
* Admin initialization and hook registration.
|
||||||
*
|
*
|
||||||
* What: Registers admin menu pages, meta boxes, and custom columns for peptides.
|
* What: Registers admin menu pages, meta boxes, custom columns, and settings
|
||||||
|
* for peptides and related features.
|
||||||
* Who calls it: PR_Core::init() when is_admin().
|
* Who calls it: PR_Core::init() when is_admin().
|
||||||
* Dependencies: PR_Core_Peptide_Metaboxes, PR_Core_Candidate_Queue_Page, PR_Core_Admin_Columns.
|
* Dependencies: PR_Core_Peptide_Metaboxes, PR_Core_Candidate_Queue_Page,
|
||||||
|
* PR_Core_Admin_Columns, PR_Core_Settings.
|
||||||
*
|
*
|
||||||
* @see admin/class-pr-core-peptide-metaboxes.php — Dosing + legal meta boxes.
|
* @see admin/class-pr-core-peptide-metaboxes.php — Dosing + legal meta boxes.
|
||||||
* @see admin/class-pr-core-candidate-queue-page.php — Candidate review screen.
|
* @see admin/class-pr-core-candidate-queue-page.php — Candidate review screen.
|
||||||
* @see admin/class-pr-core-admin-columns.php — Custom list-table columns.
|
* @see admin/class-pr-core-admin-columns.php — Custom list-table columns.
|
||||||
|
* @see admin/class-pr-core-settings.php — Plugin settings page.
|
||||||
*/
|
*/
|
||||||
class PR_Core_Admin {
|
class PR_Core_Admin {
|
||||||
|
|
||||||
@@ -30,6 +33,9 @@ class PR_Core_Admin {
|
|||||||
add_filter( 'manage_' . PR_Core_Peptide_CPT::POST_TYPE . '_posts_columns', [ $columns, 'add_columns' ] );
|
add_filter( 'manage_' . PR_Core_Peptide_CPT::POST_TYPE . '_posts_columns', [ $columns, 'add_columns' ] );
|
||||||
add_action( 'manage_' . PR_Core_Peptide_CPT::POST_TYPE . '_posts_custom_column', [ $columns, 'render_column' ], 10, 2 );
|
add_action( 'manage_' . PR_Core_Peptide_CPT::POST_TYPE . '_posts_custom_column', [ $columns, 'render_column' ], 10, 2 );
|
||||||
|
|
||||||
|
$settings = new PR_Core_Settings();
|
||||||
|
$settings->register_hooks();
|
||||||
|
|
||||||
add_action( 'admin_menu', [ $this, 'add_admin_pages' ] );
|
add_action( 'admin_menu', [ $this, 'add_admin_pages' ] );
|
||||||
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
|
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Meta boxes for the peptide edit screen: scientific identifiers, dosing, and legal.
|
* Meta boxes for the peptide edit screen: scientific identifiers, dosing, and legal.
|
||||||
*
|
*
|
||||||
* What: Renders and saves three meta boxes on the pr_peptide edit screen.
|
* What: Renders and saves three meta boxes on the peptide edit screen.
|
||||||
* Who calls it: PR_Core_Admin via add_meta_boxes and save_post hooks.
|
* Who calls it: PR_Core_Admin via add_meta_boxes and save_post hooks.
|
||||||
* Dependencies: PR_Core_Dosing_Repository, PR_Core_Legal_Repository.
|
* Dependencies: PR_Core_Dosing_Repository, PR_Core_Legal_Repository.
|
||||||
*
|
*
|
||||||
|
|||||||
176
includes/admin/class-pr-core-settings.php
Normal file
176
includes/admin/class-pr-core-settings.php
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings page for PR Core plugin features.
|
||||||
|
*
|
||||||
|
* What: Registers admin menu, renders settings form, and handles option saves
|
||||||
|
* for features like Related Articles.
|
||||||
|
* Who calls it: PR_Core_Admin::register_hooks().
|
||||||
|
* Dependencies: None (reads/writes wp_options).
|
||||||
|
*/
|
||||||
|
class PR_Core_Settings {
|
||||||
|
|
||||||
|
/** @var string Option key: enable/disable related articles. */
|
||||||
|
private const ENABLED_OPTION = 'pr_core_related_posts_enabled';
|
||||||
|
|
||||||
|
/** @var string Option key: related articles limit (1-6). */
|
||||||
|
private const LIMIT_OPTION = 'pr_core_related_posts_limit';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register admin page and settings hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register_hooks(): void {
|
||||||
|
add_action( 'admin_menu', [ $this, 'add_settings_page' ] );
|
||||||
|
add_action( 'admin_init', [ $this, 'register_settings' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add submenu page under Peptides.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function add_settings_page(): void {
|
||||||
|
add_submenu_page(
|
||||||
|
'edit.php?post_type=' . PR_Core_Peptide_CPT::POST_TYPE,
|
||||||
|
__( 'PR Core Settings', 'peptide-repo-core' ),
|
||||||
|
__( 'Settings', 'peptide-repo-core' ),
|
||||||
|
'manage_options',
|
||||||
|
'pr-core-settings',
|
||||||
|
[ $this, 'render_page' ]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register settings fields.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register_settings(): void {
|
||||||
|
register_setting(
|
||||||
|
'pr_core_settings',
|
||||||
|
self::ENABLED_OPTION,
|
||||||
|
[
|
||||||
|
'type' => 'boolean',
|
||||||
|
'default' => true,
|
||||||
|
'sanitize_callback' => 'rest_sanitize_boolean',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
register_setting(
|
||||||
|
'pr_core_settings',
|
||||||
|
self::LIMIT_OPTION,
|
||||||
|
[
|
||||||
|
'type' => 'integer',
|
||||||
|
'default' => 3,
|
||||||
|
'sanitize_callback' => [ $this, 'sanitize_limit' ],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_section(
|
||||||
|
'pr_core_related_articles',
|
||||||
|
__( 'Related Articles', 'peptide-repo-core' ),
|
||||||
|
[ $this, 'render_section' ],
|
||||||
|
'pr_core_settings'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
self::ENABLED_OPTION,
|
||||||
|
__( 'Enable Related Articles', 'peptide-repo-core' ),
|
||||||
|
[ $this, 'render_enabled_field' ],
|
||||||
|
'pr_core_settings',
|
||||||
|
'pr_core_related_articles'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
self::LIMIT_OPTION,
|
||||||
|
__( 'Number of Articles to Display', 'peptide-repo-core' ),
|
||||||
|
[ $this, 'render_limit_field' ],
|
||||||
|
'pr_core_settings',
|
||||||
|
'pr_core_related_articles'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the settings page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function render_page(): void {
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php esc_html_e( 'Peptide Repo Core Settings', 'peptide-repo-core' ); ?></h1>
|
||||||
|
<form method="post" action="options.php">
|
||||||
|
<?php
|
||||||
|
settings_fields( 'pr_core_settings' );
|
||||||
|
do_settings_sections( 'pr_core_settings' );
|
||||||
|
submit_button();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render section description.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function render_section(): void {
|
||||||
|
echo '<p>' . esc_html__( 'Configure the Related Articles section that appears on peptide single pages.', 'peptide-repo-core' ) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render enabled toggle field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function render_enabled_field(): void {
|
||||||
|
$checked = (bool) get_option( self::ENABLED_OPTION, true );
|
||||||
|
?>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="<?php echo esc_attr( self::ENABLED_OPTION ); ?>"
|
||||||
|
value="1"
|
||||||
|
<?php checked( $checked, true ); ?>
|
||||||
|
/>
|
||||||
|
<label>
|
||||||
|
<?php esc_html_e( 'Display related articles on peptide pages', 'peptide-repo-core' ); ?>
|
||||||
|
</label>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render limit field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function render_limit_field(): void {
|
||||||
|
$limit = (int) get_option( self::LIMIT_OPTION, 3 );
|
||||||
|
?>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="<?php echo esc_attr( self::LIMIT_OPTION ); ?>"
|
||||||
|
value="<?php echo esc_attr( (string) $limit ); ?>"
|
||||||
|
min="1"
|
||||||
|
max="6"
|
||||||
|
/>
|
||||||
|
<p class="description">
|
||||||
|
<?php esc_html_e( 'Number of articles to display (1-6). Default: 3.', 'peptide-repo-core' ); ?>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitize limit to 1-6 range.
|
||||||
|
*
|
||||||
|
* @param mixed $value Raw input.
|
||||||
|
* @return int Sanitized value.
|
||||||
|
*/
|
||||||
|
public function sanitize_limit( $value ): int {
|
||||||
|
$limit = (int) $value;
|
||||||
|
return min( 6, max( 1, $limit ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,17 +5,26 @@ declare(strict_types=1);
|
|||||||
* Plugin activation handler.
|
* Plugin activation handler.
|
||||||
*
|
*
|
||||||
* What: Runs migrations, adds capabilities, flushes rewrite rules.
|
* What: Runs migrations, adds capabilities, flushes rewrite rules.
|
||||||
* Who calls it: register_activation_hook() in peptide-repo-core.php.
|
* Also detects version changes on subsequent init cycles and re-flushes
|
||||||
* Dependencies: PR_Core_Migration_Runner.
|
* rewrite rules once so in-place plugin updates (without a deactivate +
|
||||||
|
* reactivate cycle) still pick up CPT/taxonomy slug changes.
|
||||||
|
* Who calls it: register_activation_hook() in peptide-repo-core.php; and
|
||||||
|
* PR_Core::init() registers maybe_flush_on_version_change on init:999.
|
||||||
|
* Dependencies: PR_Core_Migration_Runner, PR_Core_Peptide_CPT.
|
||||||
*
|
*
|
||||||
* @see peptide-repo-core.php — Registers this class on activation.
|
* @see peptide-repo-core.php — Registers this class on activation.
|
||||||
|
* @see includes/class-pr-core.php — Wires the init:999 version-change handler.
|
||||||
*/
|
*/
|
||||||
class PR_Core_Activator {
|
class PR_Core_Activator {
|
||||||
|
|
||||||
|
/** @var string Option key storing the last activated/seen plugin version. */
|
||||||
|
private const VERSION_OPTION = 'pr_core_version';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run on plugin activation.
|
* Run on plugin activation.
|
||||||
*
|
*
|
||||||
* Side effects: database table creation, capability grants, rewrite flush.
|
* Side effects: database table creation, capability grants, rewrite flush,
|
||||||
|
* pr_core_version option write.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
@@ -32,7 +41,39 @@ class PR_Core_Activator {
|
|||||||
self::add_capabilities();
|
self::add_capabilities();
|
||||||
|
|
||||||
// Flush rewrite rules for the new CPT.
|
// Flush rewrite rules for the new CPT.
|
||||||
flush_rewrite_rules();
|
flush_rewrite_rules( false );
|
||||||
|
|
||||||
|
// Record the activated version so the init:999 drift handler can
|
||||||
|
// detect future in-place updates and re-flush without a manual
|
||||||
|
// deactivate/reactivate cycle.
|
||||||
|
update_option( self::VERSION_OPTION, PR_CORE_VERSION, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect in-place plugin version changes and flush rewrite rules once.
|
||||||
|
*
|
||||||
|
* Wired to init:999 so all CPTs + taxonomies (ours and anyone else's)
|
||||||
|
* are registered before the flush. When the option is absent (first
|
||||||
|
* install that bypassed the activation hook — e.g., manual SCP deploy)
|
||||||
|
* or is older than the current constant, we flush once and update.
|
||||||
|
*
|
||||||
|
* Side effects: may call flush_rewrite_rules( false ); updates option.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function maybe_flush_on_version_change(): void {
|
||||||
|
if ( ! defined( 'PR_CORE_VERSION' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$recorded = get_option( self::VERSION_OPTION, '' );
|
||||||
|
|
||||||
|
if ( PR_CORE_VERSION === $recorded ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
flush_rewrite_rules( false );
|
||||||
|
update_option( self::VERSION_OPTION, PR_CORE_VERSION, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ declare(strict_types=1);
|
|||||||
*
|
*
|
||||||
* What: Registers all hooks, runs migrations, boots subsystems.
|
* What: Registers all hooks, runs migrations, boots subsystems.
|
||||||
* Who calls it: peptide-repo-core.php on plugins_loaded.
|
* Who calls it: peptide-repo-core.php on plugins_loaded.
|
||||||
* Dependencies: PR_Core_Migration_Runner, PR_Core_Peptide_CPT, PR_Core_Admin,
|
* Dependencies: PR_Core_Migration_Runner, PR_Core_Peptide_CPT, PR_Core_Topic_Taxonomy,
|
||||||
* PR_Core_Disclaimer, PR_Core_Jsonld, PR_Core_Rest_Controller.
|
* PR_Core_Admin, PR_Core_Disclaimer, PR_Core_Jsonld,
|
||||||
|
* PR_Core_Rest_Controller, PR_Core_Related_Posts_Section.
|
||||||
*
|
*
|
||||||
* @see peptide-repo-core.php — Bootstrap that instantiates this class.
|
* @see peptide-repo-core.php — Bootstrap that instantiates this class.
|
||||||
* @see ARCHITECTURE.md — Full data flow diagram.
|
* @see ARCHITECTURE.md — Full data flow diagram.
|
||||||
*/
|
*/
|
||||||
class PR_Core {
|
class PR_Core {
|
||||||
|
|
||||||
@@ -30,6 +31,16 @@ class PR_Core {
|
|||||||
$cpt = new PR_Core_Peptide_CPT();
|
$cpt = new PR_Core_Peptide_CPT();
|
||||||
$cpt->register_hooks();
|
$cpt->register_hooks();
|
||||||
|
|
||||||
|
// Register peptide_topic taxonomy (fires on init).
|
||||||
|
$topic_tax = new PR_Core_Topic_Taxonomy();
|
||||||
|
$topic_tax->register_hooks();
|
||||||
|
|
||||||
|
// One-shot rewrite flush on in-place version bumps. Runs at the very
|
||||||
|
// end of init (priority 999) so all CPTs/taxonomies — ours and
|
||||||
|
// anyone else's — are registered first. Handles updates deployed
|
||||||
|
// without a deactivate/reactivate cycle (e.g., SCP/rsync pushes).
|
||||||
|
add_action( 'init', [ PR_Core_Activator::class, 'maybe_flush_on_version_change' ], 999 );
|
||||||
|
|
||||||
// Admin UI (fires on admin_init, admin_menu).
|
// Admin UI (fires on admin_init, admin_menu).
|
||||||
if ( is_admin() ) {
|
if ( is_admin() ) {
|
||||||
$admin = new PR_Core_Admin();
|
$admin = new PR_Core_Admin();
|
||||||
@@ -43,6 +54,15 @@ class PR_Core {
|
|||||||
$jsonld = new PR_Core_Jsonld();
|
$jsonld = new PR_Core_Jsonld();
|
||||||
$jsonld->register_hooks();
|
$jsonld->register_hooks();
|
||||||
|
|
||||||
|
// Related Articles section (frontend).
|
||||||
|
$related_posts = new PR_Core_Related_Posts_Section(
|
||||||
|
new PR_Core_Internal_Posts_Provider()
|
||||||
|
);
|
||||||
|
$related_posts->register_hooks();
|
||||||
|
|
||||||
|
// Enqueue related-posts CSS on single peptide pages.
|
||||||
|
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_frontend_styles' ] );
|
||||||
|
|
||||||
// REST API.
|
// REST API.
|
||||||
$rest = new PR_Core_Rest_Controller();
|
$rest = new PR_Core_Rest_Controller();
|
||||||
$rest->register_hooks();
|
$rest->register_hooks();
|
||||||
@@ -51,6 +71,24 @@ class PR_Core {
|
|||||||
$this->register_public_filters();
|
$this->register_public_filters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enqueue frontend CSS on single peptide pages.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function enqueue_frontend_styles(): void {
|
||||||
|
if ( ! is_singular( PR_Core_Peptide_CPT::POST_TYPE ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_enqueue_style(
|
||||||
|
'pr-core-related-posts',
|
||||||
|
PR_CORE_PLUGIN_URL . 'assets/css/related-posts.css',
|
||||||
|
[],
|
||||||
|
PR_CORE_VERSION
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the public filter hooks that consumer plugins rely on.
|
* Register the public filter hooks that consumer plugins rely on.
|
||||||
*
|
*
|
||||||
@@ -95,7 +133,7 @@ class PR_Core {
|
|||||||
/**
|
/**
|
||||||
* Return disclaimer text for a given surface identifier.
|
* Return disclaimer text for a given surface identifier.
|
||||||
*
|
*
|
||||||
* @param string $text Existing text (empty string default).
|
* @param string $text Existing text (empty string default).
|
||||||
* @param string $surface Surface identifier (dosing, legal, reconstitution, ai-answer).
|
* @param string $surface Surface identifier (dosing, legal, reconstitution, ai-answer).
|
||||||
* @return string Disclaimer HTML.
|
* @return string Disclaimer HTML.
|
||||||
*/
|
*/
|
||||||
@@ -106,18 +144,18 @@ class PR_Core {
|
|||||||
/**
|
/**
|
||||||
* Map evidence_strength enum value to human-readable label.
|
* Map evidence_strength enum value to human-readable label.
|
||||||
*
|
*
|
||||||
* @param string $label Existing label (empty string default).
|
* @param string $label Existing label (empty string default).
|
||||||
* @param string $strength Enum value.
|
* @param string $strength Enum value.
|
||||||
* @return string Localized label.
|
* @return string Localized label.
|
||||||
*/
|
*/
|
||||||
public function filter_evidence_label( string $label, string $strength ): string {
|
public function filter_evidence_label( string $label, string $strength ): string {
|
||||||
$map = [
|
$map = [
|
||||||
'preclinical' => __( 'Preclinical', 'peptide-repo-core' ),
|
'preclinical' => __( 'Preclinical', 'peptide-repo-core' ),
|
||||||
'case-series' => __( 'Case Series', 'peptide-repo-core' ),
|
'case-series' => __( 'Case Series', 'peptide-repo-core' ),
|
||||||
'observational' => __( 'Observational', 'peptide-repo-core' ),
|
'observational' => __( 'Observational', 'peptide-repo-core' ),
|
||||||
'rct-small' => __( 'Small RCT', 'peptide-repo-core' ),
|
'rct-small' => __( 'Small RCT', 'peptide-repo-core' ),
|
||||||
'rct-large' => __( 'Large RCT', 'peptide-repo-core' ),
|
'rct-large' => __( 'Large RCT', 'peptide-repo-core' ),
|
||||||
'meta-analysis' => __( 'Meta-Analysis', 'peptide-repo-core' ),
|
'meta-analysis' => __( 'Meta-Analysis', 'peptide-repo-core' ),
|
||||||
];
|
];
|
||||||
|
|
||||||
return $map[ $strength ] ?? $strength;
|
return $map[ $strength ] ?? $strength;
|
||||||
|
|||||||
102
includes/core/class-pr-core-internal-posts-provider.php
Normal file
102
includes/core/class-pr-core-internal-posts-provider.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches posts related to a peptide via taxonomy and fallback text search.
|
||||||
|
*
|
||||||
|
* What: Implements PR_Core_Related_Posts_Provider by querying posts tagged
|
||||||
|
* with the peptide's slug as a peptide_topic term. Falls back to
|
||||||
|
* full-text search if no taxonomy matches found.
|
||||||
|
* Who calls it: PR_Core_Related_Posts_Section instantiates and calls this.
|
||||||
|
* Dependencies: PR_Core_Related_Posts_Provider interface, WP_Query,
|
||||||
|
* peptide_topic taxonomy.
|
||||||
|
*
|
||||||
|
* @see includes/interfaces/interface-related-posts-provider.php
|
||||||
|
* @see includes/core/class-related-posts-section.php
|
||||||
|
*/
|
||||||
|
class PR_Core_Internal_Posts_Provider implements PR_Core_Related_Posts_Provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get posts related to a peptide.
|
||||||
|
*
|
||||||
|
* 1. Queries posts tagged with the peptide slug as a peptide_topic term.
|
||||||
|
* 2. If 0 posts found, falls back to full-text search on post_title.
|
||||||
|
* 3. Caches result as a transient (1 hour TTL).
|
||||||
|
* 4. Never exceeds $limit posts.
|
||||||
|
*
|
||||||
|
* Side effects: Sets/updates transient cache for this peptide.
|
||||||
|
*
|
||||||
|
* @param int $peptide_id The peptide post ID.
|
||||||
|
* @param int $limit Maximum number of posts to return.
|
||||||
|
* @return array<int, \WP_Post> Array of WP_Post objects (may be empty).
|
||||||
|
*/
|
||||||
|
public function get_posts( int $peptide_id, int $limit ): array {
|
||||||
|
$peptide = get_post( $peptide_id );
|
||||||
|
if ( ! $peptide || 'peptide' !== $peptide->post_type ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache_key = 'pr_core_related_' . $peptide_id;
|
||||||
|
$cached = get_transient( $cache_key );
|
||||||
|
if ( is_array( $cached ) ) {
|
||||||
|
return array_slice( $cached, 0, $limit );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Primary: query posts tagged with peptide's slug as peptide_topic.
|
||||||
|
$posts = $this->query_by_taxonomy( $peptide->post_name, $limit );
|
||||||
|
|
||||||
|
// Fallback: if empty, search by peptide title.
|
||||||
|
if ( empty( $posts ) ) {
|
||||||
|
$posts = $this->query_by_search( $peptide->post_title, $limit );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache for 1 hour.
|
||||||
|
set_transient( $cache_key, $posts, HOUR_IN_SECONDS );
|
||||||
|
|
||||||
|
return $posts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query posts tagged with a specific peptide_topic term.
|
||||||
|
*
|
||||||
|
* @param string $peptide_slug The peptide's post_name (slug).
|
||||||
|
* @param int $limit Maximum posts to return.
|
||||||
|
* @return array<int, \WP_Post>
|
||||||
|
*/
|
||||||
|
private function query_by_taxonomy( string $peptide_slug, int $limit ): array {
|
||||||
|
$query = new WP_Query( [
|
||||||
|
'post_type' => 'post',
|
||||||
|
'posts_per_page' => $limit,
|
||||||
|
'orderby' => 'date',
|
||||||
|
'order' => 'DESC',
|
||||||
|
'tax_query' => [
|
||||||
|
[
|
||||||
|
'taxonomy' => 'peptide_topic',
|
||||||
|
'field' => 'slug',
|
||||||
|
'terms' => $peptide_slug,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
] );
|
||||||
|
|
||||||
|
return $query->posts ?: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback: query posts by full-text search on post_title.
|
||||||
|
*
|
||||||
|
* @param string $search_term The peptide's display title.
|
||||||
|
* @param int $limit Maximum posts to return.
|
||||||
|
* @return array<int, \WP_Post>
|
||||||
|
*/
|
||||||
|
private function query_by_search( string $search_term, int $limit ): array {
|
||||||
|
$query = new WP_Query( [
|
||||||
|
'post_type' => 'post',
|
||||||
|
'posts_per_page' => $limit,
|
||||||
|
'orderby' => 'date',
|
||||||
|
'order' => 'DESC',
|
||||||
|
's' => $search_term,
|
||||||
|
] );
|
||||||
|
|
||||||
|
return $query->posts ?: [];
|
||||||
|
}
|
||||||
|
}
|
||||||
24
includes/core/class-pr-core-related-posts-provider.php
Normal file
24
includes/core/class-pr-core-related-posts-provider.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contract for any provider that retrieves posts related to a peptide.
|
||||||
|
*
|
||||||
|
* What: Interface defining the get_posts() contract for related-post providers.
|
||||||
|
* Who calls it: PR_Core_Related_Posts_Section accepts any implementation.
|
||||||
|
* Dependencies: None.
|
||||||
|
*
|
||||||
|
* @see includes/core/class-pr-core-internal-posts-provider.php — default implementation.
|
||||||
|
* @see includes/core/class-pr-core-related-posts-section.php — consumer.
|
||||||
|
*/
|
||||||
|
interface PR_Core_Related_Posts_Provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get posts related to a peptide.
|
||||||
|
*
|
||||||
|
* @param int $peptide_id The peptide post ID.
|
||||||
|
* @param int $limit Maximum number of posts to return.
|
||||||
|
* @return array<int, \WP_Post> Array of WP_Post objects (may be empty).
|
||||||
|
*/
|
||||||
|
public function get_posts( int $peptide_id, int $limit ): array;
|
||||||
|
}
|
||||||
126
includes/core/class-pr-core-related-posts-section.php
Normal file
126
includes/core/class-pr-core-related-posts-section.php
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the related articles section on peptide single pages.
|
||||||
|
*
|
||||||
|
* What: Hooks into pr_core_after_peptide_content and renders a card grid
|
||||||
|
* of related posts fetched via PR_Core_Related_Posts_Provider.
|
||||||
|
* Who calls it: PR_Core::init() instantiates and registers hooks.
|
||||||
|
* Dependencies: PR_Core_Related_Posts_Provider interface, template-parts/related-posts/card.php.
|
||||||
|
*
|
||||||
|
* Settings read:
|
||||||
|
* - pr_core_related_posts_enabled (bool, default true)
|
||||||
|
* - pr_core_related_posts_limit (int, default 3, range 1-6)
|
||||||
|
*/
|
||||||
|
class PR_Core_Related_Posts_Section {
|
||||||
|
|
||||||
|
/** @var PR_Core_Related_Posts_Provider */
|
||||||
|
private $provider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param PR_Core_Related_Posts_Provider $provider Provider instance.
|
||||||
|
*/
|
||||||
|
public function __construct( PR_Core_Related_Posts_Provider $provider ) {
|
||||||
|
$this->provider = $provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the action hook.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register_hooks(): void {
|
||||||
|
add_action( 'pr_core_after_peptide_content', [ $this, 'render' ] );
|
||||||
|
add_action( 'save_post_post', [ $this, 'invalidate_caches' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the related posts section.
|
||||||
|
*
|
||||||
|
* Called via do_action( 'pr_core_after_peptide_content', $peptide_id ) in templates.
|
||||||
|
* If feature disabled or no posts found, renders nothing.
|
||||||
|
*
|
||||||
|
* @param int $peptide_id The peptide post ID.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function render( int $peptide_id ): void {
|
||||||
|
$enabled = (bool) get_option( 'pr_core_related_posts_enabled', true );
|
||||||
|
if ( ! $enabled ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$limit = (int) get_option( 'pr_core_related_posts_limit', 3 );
|
||||||
|
$limit = min( 6, max( 1, $limit ) );
|
||||||
|
|
||||||
|
$posts = $this->provider->get_posts( $peptide_id, $limit + 5 );
|
||||||
|
if ( empty( $posts ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$peptide = get_post( $peptide_id );
|
||||||
|
?>
|
||||||
|
<section class="pr-related-posts" aria-label="<?php esc_attr_e( 'Related Articles', 'peptide-repo-core' ); ?>">
|
||||||
|
<h2><?php esc_html_e( 'Related Articles', 'peptide-repo-core' ); ?></h2>
|
||||||
|
<div class="pr-related-posts__grid">
|
||||||
|
<?php
|
||||||
|
$count = 0;
|
||||||
|
foreach ( $posts as $post ) {
|
||||||
|
if ( $count >= $limit ) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
setup_postdata( $post );
|
||||||
|
get_template_part( 'template-parts/related-posts/card', null, [ 'post' => $post ] );
|
||||||
|
++$count;
|
||||||
|
}
|
||||||
|
wp_reset_postdata();
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
if ( count( $posts ) > $limit && $peptide ) {
|
||||||
|
$term = get_term_by( 'slug', $peptide->post_name, 'peptide_topic' );
|
||||||
|
if ( $term ) {
|
||||||
|
$archive_url = get_term_link( $term );
|
||||||
|
if ( ! is_wp_error( $archive_url ) ) {
|
||||||
|
?>
|
||||||
|
<p class="pr-related-posts__view-all">
|
||||||
|
<a href="<?php echo esc_url( $archive_url ); ?>">
|
||||||
|
<?php
|
||||||
|
echo wp_kses_post(
|
||||||
|
sprintf(
|
||||||
|
__( 'View all %s articles →', 'peptide-repo-core' ),
|
||||||
|
esc_html( $peptide->post_title )
|
||||||
|
)
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</section>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invalidate related posts transient caches when a post is saved.
|
||||||
|
*
|
||||||
|
* Hooks into save_post_post to clear any cached related-post queries
|
||||||
|
* since the post corpus has changed.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function invalidate_caches(): void {
|
||||||
|
global $wpdb;
|
||||||
|
$cache_keys = $wpdb->get_col(
|
||||||
|
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'pr_core_related_%'"
|
||||||
|
);
|
||||||
|
foreach ( $cache_keys as $key ) {
|
||||||
|
delete_transient( str_replace( '_transient_', '', $key ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,25 +2,30 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the pr_peptide custom post type and associated taxonomies.
|
* Registers the peptide custom post type and associated taxonomies.
|
||||||
*
|
*
|
||||||
* What: Defines the peptide CPT with REST support, archive, and monograph meta fields.
|
* What: Defines the peptide CPT with REST support, archive, and monograph meta fields.
|
||||||
|
* Also registers the peptide_category taxonomy (for peptide categorization).
|
||||||
* Who calls it: PR_Core::init() on plugins_loaded.
|
* Who calls it: PR_Core::init() on plugins_loaded.
|
||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
*
|
*
|
||||||
|
* Ownership: As of v0.2.0, PR Core is the canonical owner of the `peptide` CPT
|
||||||
|
* and `peptide_category` taxonomy (previously registered by Peptide Search AI
|
||||||
|
* pre-schema-sprint; PSA v4.5.0 drops its registrations in favor of this one).
|
||||||
|
* Registration is guarded by `post_type_exists()` / `taxonomy_exists()` so
|
||||||
|
* deploy order between the two plugins does not matter — whichever runs first
|
||||||
|
* wins, the other no-ops.
|
||||||
|
*
|
||||||
* @see ARCHITECTURE.md — CPT specification and post-meta field definitions.
|
* @see ARCHITECTURE.md — CPT specification and post-meta field definitions.
|
||||||
* @see cpt/class-pr-core-peptide-taxonomies.php — Not used; taxonomies registered here for simplicity.
|
* @see CONVENTIONS.md — CPT ownership rule (no plugin registers a CPT another plugin owns).
|
||||||
*/
|
*/
|
||||||
class PR_Core_Peptide_CPT {
|
class PR_Core_Peptide_CPT {
|
||||||
|
|
||||||
/** @var string Post type slug. */
|
/** @var string Post type slug (owned by PR Core since v0.2.0; PSA previously registered this). */
|
||||||
public const POST_TYPE = 'pr_peptide';
|
public const POST_TYPE = 'peptide';
|
||||||
|
|
||||||
/** @var string Taxonomy: category (e.g., GLP-1 agonist). */
|
/** @var string Taxonomy: category (e.g., GLP-1 agonist). */
|
||||||
public const TAX_CATEGORY = 'pr_peptide_category';
|
public const TAX_CATEGORY = 'peptide_category';
|
||||||
|
|
||||||
/** @var string Taxonomy: family grouping. */
|
|
||||||
public const TAX_FAMILY = 'pr_peptide_family';
|
|
||||||
|
|
||||||
/** @var string Capability required for editing peptide data. */
|
/** @var string Capability required for editing peptide data. */
|
||||||
public const CAPABILITY = 'manage_peptide_content';
|
public const CAPABILITY = 'manage_peptide_content';
|
||||||
@@ -129,13 +134,22 @@ class PR_Core_Peptide_CPT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the pr_peptide custom post type.
|
* Register the `peptide` custom post type.
|
||||||
|
*
|
||||||
|
* Guarded with `post_type_exists()`: if another plugin (historically PSA)
|
||||||
|
* has already registered the `peptide` post type, this call no-ops. This
|
||||||
|
* makes deploy order between PR Core and PSA irrelevant during the
|
||||||
|
* PSA v4.5.0 consolidation transition.
|
||||||
*
|
*
|
||||||
* Side effects: registers CPT with WordPress.
|
* Side effects: registers CPT with WordPress.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_peptide_post_type(): void {
|
public static function register_peptide_post_type(): void {
|
||||||
|
if ( post_type_exists( self::POST_TYPE ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$labels = [
|
$labels = [
|
||||||
'name' => __( 'Peptides', 'peptide-repo-core' ),
|
'name' => __( 'Peptides', 'peptide-repo-core' ),
|
||||||
'singular_name' => __( 'Peptide', 'peptide-repo-core' ),
|
'singular_name' => __( 'Peptide', 'peptide-repo-core' ),
|
||||||
@@ -150,60 +164,79 @@ class PR_Core_Peptide_CPT {
|
|||||||
'menu_name' => __( 'Peptides', 'peptide-repo-core' ),
|
'menu_name' => __( 'Peptides', 'peptide-repo-core' ),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Args are a harmonized superset of PR Core's prior `pr_peptide` args
|
||||||
|
* and PSA's `peptide` args, so the 89 existing posts (authored under
|
||||||
|
* PSA's registration) keep every capability they relied on:
|
||||||
|
* - supports: union of both — thumbnail comes from PSA, revisions +
|
||||||
|
* custom-fields come from PR Core.
|
||||||
|
* - capability_type + map_meta_cap: preserve PSA's per-role perms.
|
||||||
|
* - rewrite slug `peptides`: unchanged from both plugins, so
|
||||||
|
* /peptides/%postname%/ URLs keep working and theme templates
|
||||||
|
* single-peptide.php / archive-peptide.php continue to match.
|
||||||
|
*/
|
||||||
$args = [
|
$args = [
|
||||||
'labels' => $labels,
|
'labels' => $labels,
|
||||||
'public' => true,
|
'public' => true,
|
||||||
'has_archive' => true,
|
'publicly_queryable' => true,
|
||||||
'rewrite' => [ 'slug' => 'peptides', 'with_front' => false ],
|
'show_ui' => true,
|
||||||
|
'show_in_menu' => true,
|
||||||
|
'show_in_nav_menus' => true,
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'rest_base' => 'peptides',
|
'rest_base' => 'peptides',
|
||||||
'rest_namespace' => 'pr-core/v1',
|
// 'rest_namespace' omitted — custom namespaces break Gutenberg
|
||||||
'supports' => [ 'title', 'editor', 'excerpt', 'revisions', 'custom-fields' ],
|
// (it fetches wp/v2 hardcoded). WordPress defaults to wp/v2. (#5)
|
||||||
|
'menu_position' => 25,
|
||||||
'menu_icon' => 'dashicons-database',
|
'menu_icon' => 'dashicons-database',
|
||||||
'capability_type' => 'post',
|
'capability_type' => 'post',
|
||||||
'map_meta_cap' => true,
|
'map_meta_cap' => true,
|
||||||
'show_in_menu' => true,
|
'hierarchical' => false,
|
||||||
'menu_position' => 25,
|
'has_archive' => true,
|
||||||
|
'rewrite' => [ 'slug' => 'peptides', 'with_front' => false ],
|
||||||
|
'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ],
|
||||||
];
|
];
|
||||||
|
|
||||||
register_post_type( self::POST_TYPE, $args );
|
register_post_type( self::POST_TYPE, $args );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the pr_peptide_category and pr_peptide_family taxonomies.
|
* Register the `peptide_category` taxonomy.
|
||||||
*
|
*
|
||||||
* Side effects: registers taxonomies with WordPress.
|
* Guarded with `taxonomy_exists()` for the same reason CPT registration
|
||||||
|
* is guarded. The 8 existing category terms + term_relationships stay intact —
|
||||||
|
* they key on taxonomy name `peptide_category` in wp_term_taxonomy,
|
||||||
|
* which is exactly what we register here.
|
||||||
|
*
|
||||||
|
* v0.2.0: `pr_peptide_family` taxonomy removed — never populated, never
|
||||||
|
* surfaced in UI.
|
||||||
|
*
|
||||||
|
* v0.3.0: `peptide_topic` taxonomy moved to PR_Core_Topic_Taxonomy class.
|
||||||
|
*
|
||||||
|
* Side effects: registers taxonomy with WordPress.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_taxonomies(): void {
|
public static function register_taxonomies(): void {
|
||||||
register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [
|
// Register peptide_category taxonomy.
|
||||||
'labels' => [
|
if ( ! taxonomy_exists( self::TAX_CATEGORY ) ) {
|
||||||
'name' => __( 'Peptide Categories', 'peptide-repo-core' ),
|
register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [
|
||||||
'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ),
|
'labels' => [
|
||||||
],
|
'name' => __( 'Peptide Categories', 'peptide-repo-core' ),
|
||||||
'hierarchical' => true,
|
'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ),
|
||||||
'show_in_rest' => true,
|
],
|
||||||
'show_admin_column' => true,
|
'public' => true,
|
||||||
'rewrite' => [ 'slug' => 'peptide-category' ],
|
'publicly_queryable' => true,
|
||||||
] );
|
'show_in_rest' => true,
|
||||||
|
'show_ui' => true,
|
||||||
register_taxonomy( self::TAX_FAMILY, self::POST_TYPE, [
|
'show_admin_column' => true,
|
||||||
'labels' => [
|
'hierarchical' => true,
|
||||||
'name' => __( 'Peptide Families', 'peptide-repo-core' ),
|
'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ],
|
||||||
'singular_name' => __( 'Peptide Family', 'peptide-repo-core' ),
|
] );
|
||||||
],
|
}
|
||||||
'hierarchical' => false,
|
|
||||||
'show_in_rest' => true,
|
|
||||||
'show_admin_column' => true,
|
|
||||||
'rewrite' => [ 'slug' => 'peptide-family' ],
|
|
||||||
] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register post-meta fields with the REST API.
|
* Register post-meta fields. Auth gated on manage_peptide_content.
|
||||||
*
|
|
||||||
* Side effects: registers meta with WordPress.
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|||||||
62
includes/cpt/class-pr-core-topic-taxonomy.php
Normal file
62
includes/cpt/class-pr-core-topic-taxonomy.php
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the peptide_topic taxonomy for linking blog posts to peptides.
|
||||||
|
*
|
||||||
|
* What: Defines the `peptide_topic` taxonomy attached to the post CPT.
|
||||||
|
* Non-hierarchical, uses peptide slugs as terms (e.g., 'bpc-157', 'tb-500').
|
||||||
|
* Enables the Related Articles feature for blog posts tagged with a peptide topic.
|
||||||
|
* Who calls it: PR_Core::init() on plugins_loaded.
|
||||||
|
* Dependencies: None.
|
||||||
|
*
|
||||||
|
* Ownership: As of v0.3.0, PR Core owns `peptide_topic` taxonomy.
|
||||||
|
* Registration is guarded by `taxonomy_exists()` so deploy order does not matter.
|
||||||
|
*
|
||||||
|
* @see ARCHITECTURE.md — Taxonomy specification.
|
||||||
|
* @see CONVENTIONS.md — Taxonomy ownership rule.
|
||||||
|
*/
|
||||||
|
class PR_Core_Topic_Taxonomy {
|
||||||
|
|
||||||
|
/** @var string Taxonomy: topic (links blog posts to peptides by slug). */
|
||||||
|
public const TAX_TOPIC = 'peptide_topic';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register WordPress hooks for taxonomy registration.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register_hooks(): void {
|
||||||
|
add_action( 'init', [ __CLASS__, 'register_topic_taxonomy' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the `peptide_topic` taxonomy.
|
||||||
|
*
|
||||||
|
* Guarded with `taxonomy_exists()`: if another plugin has already
|
||||||
|
* registered the `peptide_topic` taxonomy, this call no-ops.
|
||||||
|
*
|
||||||
|
* Side effects: registers taxonomy with WordPress.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function register_topic_taxonomy(): void {
|
||||||
|
if ( taxonomy_exists( self::TAX_TOPIC ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
register_taxonomy( self::TAX_TOPIC, 'post', [
|
||||||
|
'labels' => [
|
||||||
|
'name' => __( 'Peptide Topics', 'peptide-repo-core' ),
|
||||||
|
'singular_name' => __( 'Peptide Topic', 'peptide-repo-core' ),
|
||||||
|
],
|
||||||
|
'public' => true,
|
||||||
|
'publicly_queryable' => true,
|
||||||
|
'show_in_rest' => true,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_admin_column' => true,
|
||||||
|
'hierarchical' => false,
|
||||||
|
'rewrite' => [ 'slug' => 'peptide-topic', 'with_front' => false ],
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Typed data-transfer object for a peptide record.
|
* Typed data-transfer object for a peptide record.
|
||||||
*
|
*
|
||||||
* What: Immutable value object wrapping a pr_peptide post + its meta fields.
|
* What: Immutable value object wrapping a peptide post + its meta fields.
|
||||||
* Who calls it: PR_Core_Peptide_Repository returns these; consumers read them.
|
* Who calls it: PR_Core_Peptide_Repository returns these; consumers read them.
|
||||||
* Dependencies: None.
|
* Dependencies: None.
|
||||||
*
|
*
|
||||||
|
|||||||
21
includes/interfaces/interface-related-posts-provider.php
Normal file
21
includes/interfaces/interface-related-posts-provider.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for fetching related posts for a peptide.
|
||||||
|
*
|
||||||
|
* What: Defines the contract for retrieving posts related to a given peptide.
|
||||||
|
* Who calls it: PR_Core_Related_Posts_Section uses implementations to fetch related articles.
|
||||||
|
* Dependencies: None.
|
||||||
|
*/
|
||||||
|
interface PR_Core_Related_Posts_Provider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get posts related to a peptide.
|
||||||
|
*
|
||||||
|
* @param int $peptide_id The peptide post ID.
|
||||||
|
* @param int $limit Maximum number of posts to return.
|
||||||
|
* @return array<int, \WP_Post> Array of WP_Post objects (may be empty).
|
||||||
|
*/
|
||||||
|
public function get_posts( int $peptide_id, int $limit ): array;
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||||||
/**
|
/**
|
||||||
* Repository for peptide CPT records.
|
* Repository for peptide CPT records.
|
||||||
*
|
*
|
||||||
* What: CRUD operations over pr_peptide posts, returning typed DTOs.
|
* What: CRUD operations over peptide posts, returning typed DTOs.
|
||||||
* Who calls it: PR_Core (public API), REST controller, admin UI, consumer plugins.
|
* Who calls it: PR_Core (public API), REST controller, admin UI, consumer plugins.
|
||||||
* Dependencies: WordPress WP_Query, PR_Core_Peptide_DTO.
|
* Dependencies: WordPress WP_Query, PR_Core_Peptide_DTO.
|
||||||
*
|
*
|
||||||
@@ -92,14 +92,10 @@ class PR_Core_Peptide_Repository {
|
|||||||
] ];
|
] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $filters['family'] ) ) {
|
// v0.2.0: `family` filter silently ignored — `pr_peptide_family` taxonomy
|
||||||
$args['tax_query'] = $args['tax_query'] ?? [];
|
// was removed with the CPT consolidation. Callers passing `family` get
|
||||||
$args['tax_query'][] = [
|
// all-category results rather than a fatal. Remove this key from the
|
||||||
'taxonomy' => PR_Core_Peptide_CPT::TAX_FAMILY,
|
// REST schema in a future minor bump.
|
||||||
'field' => 'slug',
|
|
||||||
'terms' => sanitize_text_field( $filters['family'] ),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! empty( $filters['evidence_strength'] ) ) {
|
if ( ! empty( $filters['evidence_strength'] ) ) {
|
||||||
$args['meta_query'] = [ [
|
$args['meta_query'] = [ [
|
||||||
@@ -135,7 +131,10 @@ class PR_Core_Peptide_Repository {
|
|||||||
$aliases = json_decode( $aliases_raw ?: '[]', true ) ?: [];
|
$aliases = json_decode( $aliases_raw ?: '[]', true ) ?: [];
|
||||||
|
|
||||||
$categories = wp_get_post_terms( $post->ID, PR_Core_Peptide_CPT::TAX_CATEGORY, [ 'fields' => 'names' ] );
|
$categories = wp_get_post_terms( $post->ID, PR_Core_Peptide_CPT::TAX_CATEGORY, [ 'fields' => 'names' ] );
|
||||||
$families = wp_get_post_terms( $post->ID, PR_Core_Peptide_CPT::TAX_FAMILY, [ 'fields' => 'names' ] );
|
// v0.2.0: `pr_peptide_family` taxonomy removed. DTO `families` field
|
||||||
|
// preserved as empty array to keep the REST response shape stable for
|
||||||
|
// clients; will be dropped in a future minor bump with a release note.
|
||||||
|
$families = [];
|
||||||
|
|
||||||
return new PR_Core_Peptide_DTO( [
|
return new PR_Core_Peptide_DTO( [
|
||||||
'id' => $post->ID,
|
'id' => $post->ID,
|
||||||
@@ -156,7 +155,7 @@ class PR_Core_Peptide_Repository {
|
|||||||
'last_editorial_review_at' => get_post_meta( $post->ID, 'last_editorial_review_at', true ) ?: '',
|
'last_editorial_review_at' => get_post_meta( $post->ID, 'last_editorial_review_at', true ) ?: '',
|
||||||
'medical_editor_id' => (int) get_post_meta( $post->ID, 'medical_editor_id', true ),
|
'medical_editor_id' => (int) get_post_meta( $post->ID, 'medical_editor_id', true ),
|
||||||
'categories' => is_array( $categories ) ? $categories : [],
|
'categories' => is_array( $categories ) ? $categories : [],
|
||||||
'families' => is_array( $families ) ? $families : [],
|
'families' => $families,
|
||||||
] );
|
] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
/**
|
/**
|
||||||
* Plugin Name: Peptide Repo Core
|
* Plugin Name: Peptide Repo Core
|
||||||
* Plugin URI: https://peptiderepo.com
|
* Plugin URI: https://peptiderepo.com
|
||||||
* Description: Canonical peptide schema — shared data layer for the peptiderepo.com ecosystem. Provides the pr_peptide CPT, dosing rows, legal status cells, AI candidate queue, disclaimer component, and JSON-LD output.
|
* Description: Canonical peptide schema — shared data layer for the peptiderepo.com ecosystem. Provides the peptide CPT, dosing rows, legal status cells, AI candidate queue, disclaimer component, and JSON-LD output.
|
||||||
* Version: 0.1.1
|
* Version: 0.3.2
|
||||||
* Author: peptiderepo
|
* Author: peptiderepo
|
||||||
* Author URI: https://peptiderepo.com
|
* Author URI: https://peptiderepo.com
|
||||||
* License: GPL-2.0-or-later
|
* License: GPL-2.0-or-later
|
||||||
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|
|
||||||
/* ── Constants ────────────────────────────────────────────────────────── */
|
/* ── Constants ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
define( 'PR_CORE_VERSION', '0.1.1' );
|
define( 'PR_CORE_VERSION', '0.3.2' );
|
||||||
define( 'PR_CORE_PLUGIN_FILE', __FILE__ );
|
define( 'PR_CORE_PLUGIN_FILE', __FILE__ );
|
||||||
define( 'PR_CORE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
define( 'PR_CORE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
define( 'PR_CORE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
define( 'PR_CORE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
|||||||
71
qa-reviews/peptide-repo-core/2026-04-22-874f93b.md
Executable file
71
qa-reviews/peptide-repo-core/2026-04-22-874f93b.md
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
# QA Gate — PR #1 (feature/v0.2.0-cpt-consolidation)
|
||||||
|
|
||||||
|
- **Head SHA:** 874f93b (feature/v0.2.0-cpt-consolidation, rebased onto origin/main @ c70352e)
|
||||||
|
- **Commits in PR:**
|
||||||
|
- `850279e` — `feat(cpt): consolidate peptide CPT with PSA; drop pr_peptide (v0.2.0)` (originally reviewed as `283b7ea` pre-rebase; diff identical)
|
||||||
|
- `e0ce324` — `fix(tests): drop floatval() stub (PHP builtin; redeclaration fatal on 8.3)`
|
||||||
|
- `874f93b` — `fix(tests): define PR_CORE_PLUGIN_DIR + trailingslashit in bootstrap`
|
||||||
|
- **Reviewer:** independent QA subagent (with two post-hoc CI-failure follow-up fixes applied by the author, both test-harness-only, no runtime impact — PR Core code unchanged)
|
||||||
|
- **Date:** 2026-04-22
|
||||||
|
- **Verdict:** PASS
|
||||||
|
|
||||||
|
## Contract compliance
|
||||||
|
|
||||||
|
- [PASS] CPT slug is `peptide` (not `pr_peptide`) — `PR_Core_Peptide_CPT::POST_TYPE = 'peptide'` at `includes/cpt/class-pr-core-peptide-cpt.php:24`
|
||||||
|
- [PASS] Taxonomy is `peptide_category` (not `pr_peptide_category`) — `TAX_CATEGORY = 'peptide_category'` at `includes/cpt/class-pr-core-peptide-cpt.php:27`
|
||||||
|
- [PASS] `TAX_FAMILY` constant and `pr_peptide_family` taxonomy are removed — no `TAX_FAMILY` constant exists, `register_taxonomies()` only registers `peptide_category` at `includes/cpt/class-pr-core-peptide-cpt.php:215-233`, verified by unit test at `tests/unit/test-peptide-cpt.php:103-105`
|
||||||
|
- [PASS] Registration is guarded with `post_type_exists()` / `taxonomy_exists()` and truly no-ops when they return true — `post_type_exists( self::POST_TYPE )` at line 148 returns early, `taxonomy_exists( self::TAX_CATEGORY )` at line 216 returns early; unit tests verify this at `tests/unit/test-peptide-cpt.php:44-50` and `84-90`
|
||||||
|
- [PASS] Activation hook: `flush_rewrite_rules()` runs on activate (line 44 of `includes/class-pr-core-activator.php:44`), and version-change flush handler wired at `init:999` via `PR_Core_Activator::maybe_flush_on_version_change()` registered in `includes/class-pr-core.php:37`; handler compares `get_option('pr_core_version')` to `PR_CORE_VERSION` and flushes on mismatch at `includes/class-pr-core-activator.php:64-77`
|
||||||
|
- [PASS] Args payload is the harmonized superset at `includes/cpt/class-pr-core-peptide-cpt.php:177-195`: `supports` includes `thumbnail` (line 194), `revisions`, `custom-fields`; `rewrite.slug='peptides'` with `with_front=false` (line 193); `has_archive=true` (line 192); `show_in_rest=true` (line 184); `rest_base='peptides'` (line 185); `rest_namespace='pr-core/v1'` (line 186); `map_meta_cap=true` (line 190); verified by unit tests `tests/unit/test-peptide-cpt.php:64-79`
|
||||||
|
- [PASS] `uninstall.php` only deletes `peptide` posts tagged with `_pr_core_authored='1'` (scoped teardown) — SQL at lines 45-54 uses `INNER JOIN {$wpdb->postmeta}` on meta_key `_pr_core_authored` and meta_value `'1'`, and checks `post_type = 'peptide'` at line 53; 89 canonical PSA-authored posts (which don't carry this flag) will survive uninstall
|
||||||
|
- [PASS] `uninstall.php` does NOT delete `peptide_category` taxonomy terms (shared-ownership taxonomy) — lines 61-70 explicitly state terms are preserved, and no DELETE statement targets `wp_terms` or `wp_term_taxonomy`
|
||||||
|
- [PASS] Version bumped to `0.2.0` in `peptide-repo-core.php` (Version header at line 6 and `PR_CORE_VERSION` constant at line 25) AND CHANGELOG entry exists for 0.2.0 at `CHANGELOG.md:6-26` in the same commit — verified by `git show 283b7ea --name-status` showing both `CHANGELOG.md` and `peptide-repo-core.php` modified in the same commit
|
||||||
|
|
||||||
|
## Scrub scope (narrow — msg 02 says "tight")
|
||||||
|
|
||||||
|
- [PASS] Renamed identifiers limited to CPT-slug-derived strings. Preserved identifiers confirmed:
|
||||||
|
- Class names: `PR_Core_Peptide_CPT`, `PR_Core_Peptide_DTO`, `PR_Core_Peptide_Repository`, `PR_Core_Peptide_Metaboxes`, `PR_Core_Admin_Columns` remain with `PR_Core_` prefix
|
||||||
|
- File names: `class-pr-core-peptide-*.php` pattern preserved
|
||||||
|
- Plugin constants: `PR_CORE_VERSION`, `PR_CORE_PLUGIN_FILE`, `PR_CORE_PLUGIN_DIR`, `PR_CORE_PLUGIN_URL`, `PR_CORE_TARGET_SCHEMA_VERSION` unchanged in `peptide-repo-core.php:25-29`
|
||||||
|
- Option keys: `pr_core_version` at `includes/class-pr-core-activator.php:21`
|
||||||
|
- REST namespace: `pr-core/v1` at `includes/cpt/class-pr-core-peptide-cpt.php:186`
|
||||||
|
- Hook names: `pr_core_*` filters preserved in `includes/class-pr-core.php:71-73`
|
||||||
|
- No stray `pr_peptide` strings outside comments/tests: grep shows only test assertions (lines 103-104 of test file) and comments verifying removal
|
||||||
|
|
||||||
|
## Project invariants
|
||||||
|
|
||||||
|
- [PASS] No PHP file exceeds 300 lines (exclude `tests/`, `vendor/`) — verified by bash check: `find includes -name "*.php" -exec wc -l {} \;` shows no file over 300 lines
|
||||||
|
- [PASS] Version+CHANGELOG-in-same-commit — `git show --stat 283b7ea` lists both `peptide-repo-core.php` and `CHANGELOG.md` as modified in the single commit 283b7ea
|
||||||
|
- [PASS] Git author on head commit is `peptiderepo <peptiderepo@users.noreply.github.com>` — verified by `git show 283b7ea | head -10`
|
||||||
|
- [PASS] Tests exist at `tests/unit/test-peptide-cpt.php` covering:
|
||||||
|
- Constants match contract (POST_TYPE, TAX_CATEGORY, CAPABILITY) — lines 34-39
|
||||||
|
- TAX_FAMILY removal — line 39
|
||||||
|
- Guard no-op behavior when post_type_exists/taxonomy_exists return true — lines 44-50, 84-90
|
||||||
|
- Payload shape (supports includes thumbnail, rewrite slug, REST namespace) — lines 64-79, 111-115
|
||||||
|
- Taxonomy registration (peptide_category only, no pr_peptide_family) — lines 99-109
|
||||||
|
- [PASS] `ARCHITECTURE.md` updated with CPT ownership model (Key Decision #7 at line 187-188) and §2.9 Uninstall specification (lines 190-198); `CONVENTIONS.md` updated with "CPT Ownership" section (lines 65-71) and `_pr_core_authored` flag contract (lines 72-74)
|
||||||
|
|
||||||
|
## CI
|
||||||
|
|
||||||
|
- Workflow: `.github/workflows/ci.yml`
|
||||||
|
- PHP syntax check on 8.1, 8.2, 8.3
|
||||||
|
- Lightweight unit tests (no PHPUnit): runs `tests/unit/test-*.php`
|
||||||
|
- WordPress Coding Standards (PHPCS)
|
||||||
|
- 300-line file-size gate
|
||||||
|
- **Observed on head `874f93b`:** all 5 checks green
|
||||||
|
- PHP Lint (8.1): success
|
||||||
|
- PHP Lint (8.2): success
|
||||||
|
- PHP Lint (8.3): success
|
||||||
|
- WordPress Coding Standards: success
|
||||||
|
- 300-line file check: success
|
||||||
|
- Earlier CI on `850279e` failed PHP Lint 8.3 (`Cannot redeclare floatval()` in bootstrap) and on `e0ce324` failed PHP Lint 8.2 (`Undefined constant PR_CORE_PLUGIN_DIR` in autoloader when invoked from plain-php test runner). Both are test-harness bugs; `874f93b` addresses them. No PR Core runtime code was modified by the follow-ups, so the substantive review above stands.
|
||||||
|
|
||||||
|
## Hunted risks
|
||||||
|
|
||||||
|
- **Uninstall data-loss:** SAFE. The SQL query at `uninstall.php:45-54` uses `INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id AND pm.meta_key = %s AND pm.meta_value = %s` with `meta_key='_pr_core_authored'` and `meta_value='1'`, and filters `WHERE p.post_type = %s` with `'peptide'`. This ensures only posts carrying the `_pr_core_authored` flag are deleted. The 89 canonical PSA-authored peptide posts will not carry this flag and will survive uninstall. No blanket `DELETE FROM posts WHERE post_type='peptide'` exists.
|
||||||
|
|
||||||
|
- **Guard correctness:** SAFE. The CPT guard checks `post_type_exists( self::POST_TYPE )` where `self::POST_TYPE = 'peptide'` (correct slug, not `pr_peptide`). Taxonomy guard checks `taxonomy_exists( self::TAX_CATEGORY )` where `self::TAX_CATEGORY = 'peptide_category'` (correct slug, not `pr_peptide_category`). Both guards are early returns (lines 148-150, 216-218) that prevent further execution, so the deploy-order-safety claim is sound.
|
||||||
|
|
||||||
|
- **Version-change flush:** SAFE. The activator stores the activated version in `pr_core_version` option at `includes/class-pr-core-activator.php:49`. The init:999 handler at line 64-77 retrieves the option via `get_option( self::VERSION_OPTION, '' )` (line 69, where `VERSION_OPTION = 'pr_core_version'` per line 21), compares to `PR_CORE_VERSION` constant, and if they don't match, flushes rewrite rules and updates the option. This handles in-place updates where the activation hook never fires (e.g., SCP deploys or file copies). The init:999 priority ensures all CPTs/taxonomies are already registered before the flush.
|
||||||
|
|
||||||
|
- **REST namespace:** SAFE. The CPT args at `includes/cpt/class-pr-core-peptide-c
|
||||||
67
template-parts/related-posts/card.php
Normal file
67
template-parts/related-posts/card.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Related posts card template part.
|
||||||
|
*
|
||||||
|
* Variables:
|
||||||
|
* - $post: WP_Post object with thumbnail, title, excerpt, date.
|
||||||
|
*
|
||||||
|
* @package peptide-repo-core
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! isset( $args['post'] ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = $args['post'];
|
||||||
|
?>
|
||||||
|
<article class="pr-related-posts__card">
|
||||||
|
<?php
|
||||||
|
if ( has_post_thumbnail( $post ) ) {
|
||||||
|
?>
|
||||||
|
<div class="pr-related-posts__image">
|
||||||
|
<?php
|
||||||
|
echo wp_kses_post(
|
||||||
|
get_the_post_thumbnail(
|
||||||
|
$post,
|
||||||
|
'post-thumbnail',
|
||||||
|
[
|
||||||
|
'class' => 'pr-related-posts__image-element',
|
||||||
|
'loading' => 'lazy',
|
||||||
|
'decoding' => 'async',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
<div class="pr-related-posts__image pr-related-posts__image--fallback">
|
||||||
|
<img src="<?php echo esc_url( get_site_icon_url( 512 ) ); ?>" alt="<?php esc_attr_e( 'Site logo', 'peptide-repo-core' ); ?>" class="pr-related-posts__image-element" loading="lazy" decoding="async" />
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="pr-related-posts__content">
|
||||||
|
<span class="pr-related-posts__badge"><?php esc_html_e( 'Article', 'peptide-repo-core' ); ?></span>
|
||||||
|
<h3 class="pr-related-posts__title">
|
||||||
|
<a href="<?php echo esc_url( get_permalink( $post ) ); ?>">
|
||||||
|
<?php echo esc_html( $post->post_title ); ?>
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
<time class="pr-related-posts__date" datetime="<?php echo esc_attr( mysql2date( 'c', $post->post_date ) ); ?>">
|
||||||
|
<?php echo esc_html( mysql2date( get_option( 'date_format' ), $post->post_date ) ); ?>
|
||||||
|
</time>
|
||||||
|
<?php
|
||||||
|
if ( $post->post_excerpt ) {
|
||||||
|
$excerpt = wp_strip_all_tags( $post->post_excerpt );
|
||||||
|
$excerpt = wp_kses_post( wp_trim_words( $excerpt, 20 ) );
|
||||||
|
?>
|
||||||
|
<p class="pr-related-posts__excerpt">
|
||||||
|
<?php echo wp_kses_post( $excerpt ); ?>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
163
tests/bootstrap.php
Normal file
163
tests/bootstrap.php
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Minimal test bootstrap — stubs the WordPress functions used by the classes
|
||||||
|
* under test so they can be exercised in plain PHP without a WP test install.
|
||||||
|
*
|
||||||
|
* This is intentionally NOT a full WP_UnitTestCase harness. It exists so the
|
||||||
|
* targeted unit assertions in tests/unit/ can verify guard behavior, constant
|
||||||
|
* shape, and args payload shape on CI (PHP lint job) without introducing a
|
||||||
|
* PHPUnit + wp-env dependency. A proper integration test harness is a
|
||||||
|
* follow-up (see CHANGELOG 0.2.0 notes).
|
||||||
|
*
|
||||||
|
* @package PeptideRepoCore
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
define( 'ABSPATH', __DIR__ . '/' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! defined( 'PR_CORE_VERSION' ) ) {
|
||||||
|
define( 'PR_CORE_VERSION', '0.2.0' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! defined( 'PR_CORE_PLUGIN_DIR' ) ) {
|
||||||
|
define( 'PR_CORE_PLUGIN_DIR', realpath( __DIR__ . '/..' ) . '/' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! defined( 'PR_CORE_PLUGIN_URL' ) ) {
|
||||||
|
define( 'PR_CORE_PLUGIN_URL', 'http://example.test/wp-content/plugins/peptide-repo-core/' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! defined( 'PR_CORE_PLUGIN_FILE' ) ) {
|
||||||
|
define( 'PR_CORE_PLUGIN_FILE', PR_CORE_PLUGIN_DIR . 'peptide-repo-core.php' );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'trailingslashit' ) ) {
|
||||||
|
function trailingslashit( string $path ): string {
|
||||||
|
return rtrim( $path, '/\\' ) . '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global harness state. Tests reset this between cases.
|
||||||
|
*
|
||||||
|
* @var array<string, mixed>
|
||||||
|
*/
|
||||||
|
$GLOBALS['pr_core_test_state'] = [
|
||||||
|
'existing_post_types' => [],
|
||||||
|
'existing_taxonomies' => [],
|
||||||
|
'registered_post_types' => [],
|
||||||
|
'registered_taxonomies' => [],
|
||||||
|
'registered_meta' => [],
|
||||||
|
'added_actions' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
function pr_core_test_reset(): void {
|
||||||
|
$GLOBALS['pr_core_test_state'] = [
|
||||||
|
'existing_post_types' => [],
|
||||||
|
'existing_taxonomies' => [],
|
||||||
|
'registered_post_types' => [],
|
||||||
|
'registered_taxonomies' => [],
|
||||||
|
'registered_meta' => [],
|
||||||
|
'added_actions' => [],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function post_type_exists( string $post_type ): bool {
|
||||||
|
return in_array( $post_type, $GLOBALS['pr_core_test_state']['existing_post_types'], true );
|
||||||
|
}
|
||||||
|
|
||||||
|
function taxonomy_exists( string $taxonomy ): bool {
|
||||||
|
return in_array( $taxonomy, $GLOBALS['pr_core_test_state']['existing_taxonomies'], true );
|
||||||
|
}
|
||||||
|
|
||||||
|
function register_post_type( string $post_type, array $args = [] ) {
|
||||||
|
$GLOBALS['pr_core_test_state']['registered_post_types'][ $post_type ] = $args;
|
||||||
|
$GLOBALS['pr_core_test_state']['existing_post_types'][] = $post_type;
|
||||||
|
return (object) [ 'name' => $post_type, 'args' => $args ];
|
||||||
|
}
|
||||||
|
|
||||||
|
function register_taxonomy( string $taxonomy, $object_type, array $args = [] ): void {
|
||||||
|
$GLOBALS['pr_core_test_state']['registered_taxonomies'][ $taxonomy ] = [
|
||||||
|
'object_type' => $object_type,
|
||||||
|
'args' => $args,
|
||||||
|
];
|
||||||
|
$GLOBALS['pr_core_test_state']['existing_taxonomies'][] = $taxonomy;
|
||||||
|
}
|
||||||
|
|
||||||
|
function register_post_meta( string $post_type, string $key, array $args = [] ): bool {
|
||||||
|
$GLOBALS['pr_core_test_state']['registered_meta'][ $post_type ][ $key ] = $args;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_action( string $hook, $callback, int $priority = 10, int $accepted_args = 1 ): bool {
|
||||||
|
$GLOBALS['pr_core_test_state']['added_actions'][] = [
|
||||||
|
'hook' => $hook,
|
||||||
|
'callback' => $callback,
|
||||||
|
'priority' => $priority,
|
||||||
|
];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __( string $text, string $domain = 'default' ): string {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function current_user_can( string $capability ): bool {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sanitize_text_field( $value ): string {
|
||||||
|
return is_scalar( $value ) ? trim( (string) $value ) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function wp_json_encode( $data ): string {
|
||||||
|
return json_encode( $data ) ?: '[]';
|
||||||
|
}
|
||||||
|
|
||||||
|
function absint( $value ): int {
|
||||||
|
return abs( (int) $value );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ── Test assertion helpers ─────────────────────────────────────────── */
|
||||||
|
|
||||||
|
$GLOBALS['pr_core_test_report'] = [ 'pass' => 0, 'fail' => 0, 'failures' => [] ];
|
||||||
|
|
||||||
|
function pr_assert( bool $condition, string $label ): void {
|
||||||
|
if ( $condition ) {
|
||||||
|
$GLOBALS['pr_core_test_report']['pass']++;
|
||||||
|
echo " PASS: {$label}\n";
|
||||||
|
} else {
|
||||||
|
$GLOBALS['pr_core_test_report']['fail']++;
|
||||||
|
$GLOBALS['pr_core_test_report']['failures'][] = $label;
|
||||||
|
echo " FAIL: {$label}\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pr_assert_equals( $expected, $actual, string $label ): void {
|
||||||
|
$pass = ( $expected === $actual );
|
||||||
|
pr_assert( $pass, $label . ( $pass ? '' : ' — expected ' . var_export( $expected, true ) . ', got ' . var_export( $actual, true ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
function pr_test_summary(): int {
|
||||||
|
$r = $GLOBALS['pr_core_test_report'];
|
||||||
|
echo "\n---\n";
|
||||||
|
echo "Totals: {$r['pass']} passed, {$r['fail']} failed\n";
|
||||||
|
if ( $r['fail'] > 0 ) {
|
||||||
|
echo "Failures:\n";
|
||||||
|
foreach ( $r['failures'] as $f ) {
|
||||||
|
echo " - {$f}\n";
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Load the plugin's autoloader + required classes ─────────────────── */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../includes/class-pr-core-autoloader.php';
|
||||||
|
PR_Core_Autoloader::register();
|
||||||
|
require_once __DIR__ . '/../includes/cpt/class-pr-core-peptide-cpt.php';
|
||||||
168
tests/test-internal-posts-provider.php
Normal file
168
tests/test-internal-posts-provider.php
Normal file
@@ -0,0 +1,168 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for PR_Core_Internal_Posts_Provider.
|
||||||
|
*
|
||||||
|
* Tests the provider's taxonomy-based and fallback search behavior,
|
||||||
|
* caching, and limit enforcement. Uses mocked WP_Query.
|
||||||
|
*/
|
||||||
|
class PR_Core_Internal_Posts_Provider_Test {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: returns empty array when peptide ID is invalid.
|
||||||
|
*/
|
||||||
|
public function test_returns_empty_when_peptide_not_found() {
|
||||||
|
$provider = new PR_Core_Internal_Posts_Provider();
|
||||||
|
$result = $provider->get_posts( 99999, 3 );
|
||||||
|
|
||||||
|
assert( [] === $result, 'Expected empty array for invalid peptide ID' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: returns posts matching peptide_topic taxonomy.
|
||||||
|
*/
|
||||||
|
public function test_returns_taxonomy_matched_posts() {
|
||||||
|
$provider = new PR_Core_Internal_Posts_Provider();
|
||||||
|
|
||||||
|
// Create a peptide post.
|
||||||
|
$peptide_id = wp_insert_post( [
|
||||||
|
'post_type' => 'peptide',
|
||||||
|
'post_title' => 'BPC-157',
|
||||||
|
'post_name' => 'bpc-157',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
|
||||||
|
// Create and tag a blog post with peptide_topic = 'bpc-157'.
|
||||||
|
$post_id = wp_insert_post( [
|
||||||
|
'post_type' => 'post',
|
||||||
|
'post_title' => 'BPC-157 Research',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
wp_set_post_terms( $post_id, 'bpc-157', 'peptide_topic' );
|
||||||
|
|
||||||
|
$result = $provider->get_posts( $peptide_id, 3 );
|
||||||
|
|
||||||
|
assert( ! empty( $result ), 'Expected at least one post' );
|
||||||
|
assert( 1 === count( $result ), 'Expected exactly one post' );
|
||||||
|
assert( $post_id === $result[0]->ID, 'Expected post ID to match' );
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
wp_delete_post( $peptide_id, true );
|
||||||
|
wp_delete_post( $post_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: falls back to text search when taxonomy returns nothing.
|
||||||
|
*/
|
||||||
|
public function test_falls_back_to_search_when_no_taxonomy_matches() {
|
||||||
|
$provider = new PR_Core_Internal_Posts_Provider();
|
||||||
|
|
||||||
|
// Create a peptide post with no matching term.
|
||||||
|
$peptide_id = wp_insert_post( [
|
||||||
|
'post_type' => 'peptide',
|
||||||
|
'post_title' => 'Semaglutide',
|
||||||
|
'post_name' => 'semaglutide-unique',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
|
||||||
|
// Create a blog post with "Semaglutide" in title (no peptide_topic tag).
|
||||||
|
$post_id = wp_insert_post( [
|
||||||
|
'post_type' => 'post',
|
||||||
|
'post_title' => 'Semaglutide Dosing Guide',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
|
||||||
|
$result = $provider->get_posts( $peptide_id, 3 );
|
||||||
|
|
||||||
|
assert( ! empty( $result ), 'Expected fallback search to return posts' );
|
||||||
|
assert( $post_id === $result[0]->ID, 'Expected fallback search to find title match' );
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
wp_delete_post( $peptide_id, true );
|
||||||
|
wp_delete_post( $post_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: never returns more posts than $limit.
|
||||||
|
*/
|
||||||
|
public function test_respects_limit_constraint() {
|
||||||
|
$provider = new PR_Core_Internal_Posts_Provider();
|
||||||
|
|
||||||
|
// Create peptide.
|
||||||
|
$peptide_id = wp_insert_post( [
|
||||||
|
'post_type' => 'peptide',
|
||||||
|
'post_title' => 'TB-500',
|
||||||
|
'post_name' => 'tb-500',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
|
||||||
|
// Create 5 tagged posts.
|
||||||
|
for ( $i = 0; $i < 5; ++$i ) {
|
||||||
|
$post_id = wp_insert_post( [
|
||||||
|
'post_type' => 'post',
|
||||||
|
'post_title' => 'TB-500 Article ' . $i,
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
wp_set_post_terms( $post_id, 'tb-500', 'peptide_topic' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $provider->get_posts( $peptide_id, 3 );
|
||||||
|
|
||||||
|
assert( 3 === count( $result ), 'Expected exactly 3 posts for limit=3' );
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
wp_delete_post( $peptide_id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test: returns cached transient on second call.
|
||||||
|
*/
|
||||||
|
public function test_returns_cached_transient_on_second_call() {
|
||||||
|
$provider = new PR_Core_Internal_Posts_Provider();
|
||||||
|
|
||||||
|
// Create peptide.
|
||||||
|
$peptide_id = wp_insert_post( [
|
||||||
|
'post_type' => 'peptide',
|
||||||
|
'post_title' => 'AOD-9604',
|
||||||
|
'post_name' => 'aod-9604',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
] );
|
||||||
|
|
||||||
|
// First call: query and cache.
|
||||||
|
$result_1 = $provider->get_posts( $peptide_id, 3 );
|
||||||
|
|
||||||
|
// Verify transient was set.
|
||||||
|
$cache_key = 'pr_core_related_' . $peptide_id;
|
||||||
|
$cached = get_transient( $cache_key );
|
||||||
|
assert( ! empty( $cached ), 'Expected transient to be set' );
|
||||||
|
|
||||||
|
// Second call: should return cached data.
|
||||||
|
$result_2 = $provider->get_posts( $peptide_id, 3 );
|
||||||
|
|
||||||
|
// Results should match.
|
||||||
|
if ( ! empty( $result_1 ) ) {
|
||||||
|
assert( count( $result_1 ) === count( $result_2 ), 'Expected cached results to match' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
wp_delete_post( $peptide_id, true );
|
||||||
|
delete_transient( $cache_key );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run tests if executed directly in PHPUnit context (tests/bootstrap.php will autoload).
|
||||||
|
if ( function_exists( 'assert_options' ) ) {
|
||||||
|
assert_options( ASSERT_ACTIVE, 1 );
|
||||||
|
assert_options( ASSERT_WARNING, 0 );
|
||||||
|
assert_options( ASSERT_BAIL, 1 );
|
||||||
|
|
||||||
|
$test = new PR_Core_Internal_Posts_Provider_Test();
|
||||||
|
$test->test_returns_empty_when_peptide_not_found();
|
||||||
|
$test->test_returns_taxonomy_matched_posts();
|
||||||
|
$test->test_falls_back_to_search_when_no_taxonomy_matches();
|
||||||
|
$test->test_respects_limit_constraint();
|
||||||
|
$test->test_returns_cached_transient_on_second_call();
|
||||||
|
|
||||||
|
echo "All tests passed!\n";
|
||||||
|
}
|
||||||
129
tests/unit/test-peptide-cpt.php
Normal file
129
tests/unit/test-peptide-cpt.php
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Unit tests for PR_Core_Peptide_CPT (v0.2.0 CPT consolidation).
|
||||||
|
*
|
||||||
|
* Run: php tests/unit/test-peptide-cpt.php
|
||||||
|
* Exit code 0 = all pass, 1 = any failure.
|
||||||
|
*
|
||||||
|
* What's covered:
|
||||||
|
* - Constants match the v0.2.0 consolidated contract (peptide / peptide_category).
|
||||||
|
* - TAX_FAMILY constant is removed.
|
||||||
|
* - register_peptide_post_type() guard: no-op when post_type_exists returns true.
|
||||||
|
* - register_peptide_post_type() payload: args match the harmonized contract
|
||||||
|
* (thumbnail in supports, rewrite slug peptides, rest_namespace absent — Gutenberg requires wp/v2).
|
||||||
|
* - register_taxonomies() guard: no-op when taxonomy_exists returns true.
|
||||||
|
* - register_taxonomies() only registers peptide_category; pr_peptide_family is gone.
|
||||||
|
*
|
||||||
|
* Not covered here (follow-up with proper PHPUnit + wp-env harness):
|
||||||
|
* - Actual rewrite rule map on a live WP install.
|
||||||
|
* - Activation flow end-to-end (migrations + capabilities + flush).
|
||||||
|
* - REST route registration smoke.
|
||||||
|
*
|
||||||
|
* @package PeptideRepoCore
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../bootstrap.php';
|
||||||
|
|
||||||
|
echo "== PR_Core_Peptide_CPT v0.2.0 unit tests ==\n\n";
|
||||||
|
|
||||||
|
/* ── Constants ──────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
echo "Constants:\n";
|
||||||
|
pr_assert_equals( 'peptide', PR_Core_Peptide_CPT::POST_TYPE, 'POST_TYPE is "peptide"' );
|
||||||
|
pr_assert_equals( 'peptide_category', PR_Core_Peptide_CPT::TAX_CATEGORY, 'TAX_CATEGORY is "peptide_category"' );
|
||||||
|
pr_assert_equals( 'manage_peptide_content', PR_Core_Peptide_CPT::CAPABILITY, 'CAPABILITY unchanged' );
|
||||||
|
|
||||||
|
$reflection = new ReflectionClass( PR_Core_Peptide_CPT::class );
|
||||||
|
pr_assert( ! $reflection->hasConstant( 'TAX_FAMILY' ), 'TAX_FAMILY constant removed' );
|
||||||
|
|
||||||
|
/* ── CPT guard: post_type_exists === true => no-op ──────────────────── */
|
||||||
|
|
||||||
|
echo "\nCPT registration guard:\n";
|
||||||
|
pr_core_test_reset();
|
||||||
|
$GLOBALS['pr_core_test_state']['existing_post_types'] = [ 'peptide' ];
|
||||||
|
PR_Core_Peptide_CPT::register_peptide_post_type();
|
||||||
|
pr_assert(
|
||||||
|
empty( $GLOBALS['pr_core_test_state']['registered_post_types'] ),
|
||||||
|
'register_peptide_post_type() no-ops when post_type_exists("peptide") is true'
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ── CPT registration payload ───────────────────────────────────────── */
|
||||||
|
|
||||||
|
echo "\nCPT registration payload:\n";
|
||||||
|
pr_core_test_reset();
|
||||||
|
PR_Core_Peptide_CPT::register_peptide_post_type();
|
||||||
|
|
||||||
|
pr_assert(
|
||||||
|
isset( $GLOBALS['pr_core_test_state']['registered_post_types']['peptide'] ),
|
||||||
|
'register_post_type was called with slug "peptide"'
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = $GLOBALS['pr_core_test_state']['registered_post_types']['peptide'] ?? [];
|
||||||
|
pr_assert_equals( true, $args['public'] ?? null, 'public = true' );
|
||||||
|
pr_assert_equals( true, $args['publicly_queryable'] ?? null, 'publicly_queryable = true' );
|
||||||
|
pr_assert_equals( true, $args['show_in_rest'] ?? null, 'show_in_rest = true' );
|
||||||
|
pr_assert_equals( 'peptides', $args['rest_base'] ?? null, 'rest_base = "peptides"' );
|
||||||
|
pr_assert( ! array_key_exists( 'rest_namespace', $args ), 'rest_namespace absent — defaults to wp/v2 (Gutenberg requirement)' );
|
||||||
|
pr_assert_equals( 'post', $args['capability_type'] ?? null, 'capability_type = "post"' );
|
||||||
|
pr_assert_equals( true, $args['map_meta_cap'] ?? null, 'map_meta_cap = true' );
|
||||||
|
pr_assert_equals( false, $args['hierarchical'] ?? null, 'hierarchical = false' );
|
||||||
|
pr_assert_equals( true, $args['has_archive'] ?? null, 'has_archive = true' );
|
||||||
|
pr_assert_equals( 'peptides', $args['rewrite']['slug'] ?? null, 'rewrite slug = "peptides"' );
|
||||||
|
pr_assert_equals( false, $args['rewrite']['with_front'] ?? null, 'rewrite with_front = false' );
|
||||||
|
|
||||||
|
$supports = $args['supports'] ?? [];
|
||||||
|
foreach ( [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ] as $feature ) {
|
||||||
|
pr_assert( in_array( $feature, $supports, true ), "supports includes \"{$feature}\"" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Taxonomy guard: taxonomy_exists === true => no-op ──────────────── */
|
||||||
|
|
||||||
|
echo "\nTaxonomy registration guard:\n";
|
||||||
|
pr_core_test_reset();
|
||||||
|
$GLOBALS['pr_core_test_state']['existing_taxonomies'] = [ 'peptide_category' ];
|
||||||
|
PR_Core_Peptide_CPT::register_taxonomies();
|
||||||
|
pr_assert(
|
||||||
|
empty( $GLOBALS['pr_core_test_state']['registered_taxonomies'] ),
|
||||||
|
'register_taxonomies() no-ops when taxonomy_exists("peptide_category") is true'
|
||||||
|
);
|
||||||
|
|
||||||
|
/* ── Taxonomy registration payload ──────────────────────────────────── */
|
||||||
|
|
||||||
|
echo "\nTaxonomy registration payload:\n";
|
||||||
|
pr_core_test_reset();
|
||||||
|
PR_Core_Peptide_CPT::register_taxonomies();
|
||||||
|
|
||||||
|
pr_assert(
|
||||||
|
isset( $GLOBALS['pr_core_test_state']['registered_taxonomies']['peptide_category'] ),
|
||||||
|
'peptide_category taxonomy registered'
|
||||||
|
);
|
||||||
|
pr_assert(
|
||||||
|
! isset( $GLOBALS['pr_core_test_state']['registered_taxonomies']['pr_peptide_family'] ),
|
||||||
|
'pr_peptide_family taxonomy NOT registered (removed in v0.2.0)'
|
||||||
|
);
|
||||||
|
pr_assert(
|
||||||
|
! isset( $GLOBALS['pr_core_test_state']['registered_taxonomies']['peptide_family'] ),
|
||||||
|
'peptide_family taxonomy NOT registered either (the rename-only path would have left this lingering)'
|
||||||
|
);
|
||||||
|
|
||||||
|
$tax = $GLOBALS['pr_core_test_state']['registered_taxonomies']['peptide_category'] ?? [];
|
||||||
|
pr_assert_equals( 'peptide', $tax['object_type'] ?? null, 'peptide_category attached to peptide CPT' );
|
||||||
|
pr_assert_equals( true, $tax['args']['hierarchical'] ?? null, 'peptide_category hierarchical = true' );
|
||||||
|
pr_assert_equals( true, $tax['args']['show_in_rest'] ?? null, 'peptide_category show_in_rest = true' );
|
||||||
|
pr_assert_equals( 'peptide-category', $tax['args']['rewrite']['slug'] ?? null, 'peptide_category rewrite slug = "peptide-category"' );
|
||||||
|
|
||||||
|
/* ── Hook registration ──────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
echo "\nHook registration:\n";
|
||||||
|
pr_core_test_reset();
|
||||||
|
$cpt = new PR_Core_Peptide_CPT();
|
||||||
|
$cpt->register_hooks();
|
||||||
|
|
||||||
|
$hooks = array_column( $GLOBALS['pr_core_test_state']['added_actions'], 'hook' );
|
||||||
|
pr_assert( in_array( 'init', $hooks, true ), 'register_hooks() adds action on "init"' );
|
||||||
|
|
||||||
|
/* ── Summary ────────────────────────────────────────────────────────── */
|
||||||
|
|
||||||
|
exit( pr_test_summary() );
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Peptide Repo Core — Full data teardown on uninstall.
|
* Peptide Repo Core — Selective data teardown on uninstall.
|
||||||
*
|
*
|
||||||
* Removes ALL plugin data: custom tables, CPT posts + meta, taxonomy terms,
|
* Removes plugin-owned data only: custom tables, PR Core-authored peptide
|
||||||
* options, and capabilities. No orphaned data left behind.
|
* posts, pr_core_ options, and the manage_peptide_content capability.
|
||||||
|
* Shared data (the 89 canonical peptide posts authored by PSA, and the
|
||||||
|
* peptide_category taxonomy terms) is preserved.
|
||||||
*
|
*
|
||||||
* @see ARCHITECTURE.md — Section 2.9 Uninstall specification.
|
* @see ARCHITECTURE.md — §2.9 Uninstall specification.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||||
@@ -27,33 +29,45 @@ foreach ( $tables as $table ) {
|
|||||||
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 2. Delete all pr_peptide posts (cascade deletes meta) ────────────── */
|
/* ── 2. Delete only peptide posts authored through PR Core's UI ───────── */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* As of v0.2.0, PR Core shares the `peptide` CPT with Peptide Search AI.
|
||||||
|
* PSA authored the 89 canonical peptide posts on peptiderepo.com; those
|
||||||
|
* predate PR Core and do NOT carry the `_pr_core_authored` flag. A blanket
|
||||||
|
* DELETE here would destroy site-owned content, not plugin-owned content.
|
||||||
|
*
|
||||||
|
* This loop only deletes posts that PR Core itself created (flagged with
|
||||||
|
* post-meta `_pr_core_authored = '1'`). If no post carries the flag, the
|
||||||
|
* loop no-ops and shared content is preserved.
|
||||||
|
*/
|
||||||
|
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||||
$post_ids = $wpdb->get_col(
|
$post_ids = $wpdb->get_col(
|
||||||
"SELECT ID FROM {$wpdb->posts} WHERE post_type = 'pr_peptide'"
|
$wpdb->prepare(
|
||||||
|
"SELECT p.ID FROM {$wpdb->posts} p
|
||||||
|
INNER JOIN {$wpdb->postmeta} pm
|
||||||
|
ON p.ID = pm.post_id AND pm.meta_key = %s AND pm.meta_value = %s
|
||||||
|
WHERE p.post_type = %s",
|
||||||
|
'_pr_core_authored',
|
||||||
|
'1',
|
||||||
|
'peptide'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $post_ids as $post_id ) {
|
foreach ( $post_ids as $post_id ) {
|
||||||
wp_delete_post( (int) $post_id, true );
|
wp_delete_post( (int) $post_id, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── 3. Delete taxonomy terms ─────────────────────────────────────────── */
|
/* ── 3. Preserve taxonomy terms (shared ownership post-v0.2.0) ────────── */
|
||||||
|
|
||||||
$taxonomies = [ 'pr_peptide_category', 'pr_peptide_family' ];
|
/*
|
||||||
|
* `peptide_category` is shared between PR Core and PSA. Term metadata
|
||||||
foreach ( $taxonomies as $taxonomy ) {
|
* (descriptions, parent relationships, counts) is data the site owns —
|
||||||
$terms = get_terms( [
|
* removing it on PR Core uninstall would strip categorization from the
|
||||||
'taxonomy' => $taxonomy,
|
* peptide posts that remain. So we intentionally do NOT enumerate or
|
||||||
'hide_empty' => false,
|
* delete terms here. `pr_peptide_family` is gone in v0.2.0 so no cleanup
|
||||||
'fields' => 'ids',
|
* is needed for it either.
|
||||||
] );
|
*/
|
||||||
|
|
||||||
if ( is_array( $terms ) ) {
|
|
||||||
foreach ( $terms as $term_id ) {
|
|
||||||
wp_delete_term( (int) $term_id, $taxonomy );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ── 4. Delete all pr_core_ prefixed options ──────────────────────────── */
|
/* ── 4. Delete all pr_core_ prefixed options ──────────────────────────── */
|
||||||
|
|
||||||
@@ -62,7 +76,7 @@ $wpdb->query(
|
|||||||
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'pr\_core\_%'"
|
"DELETE FROM {$wpdb->options} WHERE option_name LIKE 'pr\_core\_%'"
|
||||||
);
|
);
|
||||||
|
|
||||||
/* ── 5. Remove manage_peptide_content capability from all roles ────────── */
|
/* ── 5. Remove manage_peptide_content capability from all roles ───────── */
|
||||||
|
|
||||||
$editable_roles = wp_roles()->roles;
|
$editable_roles = wp_roles()->roles;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user