fix: rename CPT slugs to opentr_* with v4 migration#21
Conversation
wp.org reviewer required a 4+ char prefix. Renamed the 5 CPTs from ot_* to opentr_*. Added v3 to v4 migration to rewrite wp_posts.post_type for existing rows. Legacy slugs preserved in OpenTrust_CPT::LEGACY_* and used by the import/export back-compat remap and uninstall cleanup.
…he staleness (#20) Pass 2 goalkeeper review surfaced three sharp edges in the v3 to v4 rename: - opentrust.php: the activation hook unconditionally stamped opentrust_db_version on every activation, which would skip the rename on the deactivate-upload-reactivate upgrade path and orphan every existing ot_* row. Stamp on first install only; maybe_upgrade() handles the upgrade path on next init. - includes/class-opentrust.php: rename_cpt_slugs_v4() now collects affected post IDs before the UPDATE and calls clean_post_cache() per row so the WP_Post object cache does not return stale post_type values after the migration. - includes/class-opentrust.php: explicitly invalidate the chat corpus transient at the end of maybe_upgrade(); the corpus is locale-keyed and not bound to opentrust_cache_version, so the cache-version bump alone would not bust it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR renames five custom post type slugs from the non-compliant 2-character ChangesCPT Slug Migration (ot_ → opentr_*)*
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@includes/class-opentrust-io.php`:
- Around line 427-429: The loop that maps incoming manifest records into $out
uses OpenTrust_CPT::LEGACY_MAP to normalize keys but assigns $recs directly, so
when a legacy and a new key map to the same CPT the latter overwrites the
former; update the foreach over $manifest['records'] to merge arrays into $out
instead of replacing—e.g., for each $cpt/$recs, compute $key =
OpenTrust_CPT::LEGACY_MAP[$cpt] ?? $cpt and then append/array_merge $recs into
existing $out[$key] (initializing it if absent) so records from both keys are
preserved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 05e3089c-7950-4971-845d-0d7171941bc1
📒 Files selected for processing (20)
assets/js/admin.jsincludes/class-opentrust-admin-review.phpincludes/class-opentrust-admin-tools.phpincludes/class-opentrust-admin.phpincludes/class-opentrust-catalog.phpincludes/class-opentrust-chat-summarizer.phpincludes/class-opentrust-cpt.phpincludes/class-opentrust-io.phpincludes/class-opentrust-render.phpincludes/class-opentrust-repository.phpincludes/class-opentrust-version.phpincludes/class-opentrust.phpincludes/data/certification-catalog.phpincludes/data/data-practice-catalog.phpincludes/data/faq-catalog.phpincludes/data/subprocessor-catalog.phplanguages/opentrust.potopentrust.phpuninstall.phpwpml-config.xml
v1.1.0 upgrade plan — release notesSummary. This PR renames five CPT slugs from Scenario walkthrough1. Fresh install on a clean WordPress. Activation hook fires. 2. wp.org background auto-update. No activation hook. Files swap in place; 3. WP-CLI 4. Manual "Upload Plugin" (replace flow). WP typically deactivates the plugin during replacement, lands the new files, and lands the user on a screen asking them to click Activate. Mid-upgrade state: the DB still holds 5. SFTP file replacement → user clicks Activate. Behaviourally identical to scenario 4. 6. Upgrade from a hypothetical pre-v3 install (v1 → v4 jump). 7. Re-run after a fatal interruption. Because Operator FAQ
Rollback planIf a site reports CPTs missing post-update: confirm What to watch in production
|
…20) Adds @deprecated PHPDoc tags so IDEs and static analyzers flag the four pieces of v1.0.x → v1.1.0 upgrade scaffolding when 2.0.0 cleanup happens: - OpenTrust_CPT::LEGACY_* constants + LEGACY_MAP - OpenTrust::rename_cpt_slugs_v4() - OpenTrust_IO::remap_legacy_cpt_keys() - uninstall.php legacy ot_* slug fallback list No runtime behavior change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Line-reference shifts only; no msgid changes, so existing PO/MO files remain valid. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…dundant v4 DB-version comment superseded by #21 migration
Summary
ot_policy,ot_certification,ot_subprocessor,ot_data_practice,ot_faq) toopentr_*to satisfy the wp.org ≥4-char prefix rule.opentr_is the reviewer's own example and the only candidate that survives WP's hard 20-charregister_post_typecap on every slug.OpenTrust::maybe_upgrade()that rewriteswp_posts.post_typefor existing rows, with per-rowclean_post_cache()and an explicit chat-corpus invalidate.opentrust_db_versionstamp so it only runs on a true first install — fixes the deactivate → upload zip → reactivate upgrade path that would otherwise skip the rename and orphan existing rows.OpenTrust_CPT::LEGACY_MAP,OpenTrust_IO::remap_legacy_cpt_keys()for legacy export archives, and a belt-and-suspenders legacy-slug list inuninstall.php.wpml-config.xml<custom-type>entries.Test plan
opentr_*;opentrust_db_versionstamps at 4; no migration runs.wp_posts.post_typerewrites on next page load and admin lists still show every row.wp plugin update(no activation hook fires): verifymaybe_upgrade()runs the rename on next request.ot_*manifest keys are remapped and posts land under the new slugs.Closes #20
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Chores
Bug Fixes