From 0210d73cf7d7abb8e18f378bffd69fc03decdfcf Mon Sep 17 00:00:00 2001 From: peptiderepo Date: Fri, 24 Apr 2026 10:01:47 +0700 Subject: [PATCH] feat: add peptide_topic taxonomy registration --- includes/cpt/class-pr-core-peptide-cpt.php | 67 ++++++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/includes/cpt/class-pr-core-peptide-cpt.php b/includes/cpt/class-pr-core-peptide-cpt.php index d8a19b8..147bb32 100644 --- a/includes/cpt/class-pr-core-peptide-cpt.php +++ b/includes/cpt/class-pr-core-peptide-cpt.php @@ -2,9 +2,11 @@ declare(strict_types=1); /** - * Registers the peptide custom post type and associated taxonomy. + * Registers the peptide custom post type and associated taxonomies. * * What: Defines the peptide CPT with REST support, archive, and monograph meta fields. + * Also registers the peptide_category taxonomy (for peptide categorization) and + * peptide_topic taxonomy (for linking blog posts to peptides). * Who calls it: PR_Core::init() on plugins_loaded. * Dependencies: None. * @@ -15,6 +17,10 @@ declare(strict_types=1); * deploy order between the two plugins does not matter — whichever runs first * wins, the other no-ops. * + * As of v0.3.0, `peptide_topic` taxonomy is registered for linking blog posts + * to peptides via a shared topic slug (e.g., 'bpc-157'). This enables the + * Related Articles feature. + * * @see ARCHITECTURE.md — CPT specification and post-meta field definitions. * @see CONVENTIONS.md — CPT ownership rule (no plugin registers a CPT another plugin owns). */ @@ -26,6 +32,9 @@ class PR_Core_Peptide_CPT { /** @var string Taxonomy: category (e.g., GLP-1 agonist). */ public const TAX_CATEGORY = 'peptide_category'; + /** @var string Taxonomy: topic (links blog posts to peptides by slug). */ + public const TAX_TOPIC = 'peptide_topic'; + /** @var string Capability required for editing peptide data. */ public const CAPABILITY = 'manage_peptide_content'; @@ -198,38 +207,58 @@ class PR_Core_Peptide_CPT { } /** - * Register the `peptide_category` taxonomy. + * Register the `peptide_category` and `peptide_topic` taxonomies. * * Guarded with `taxonomy_exists()` for the same reason CPT registration - * is guarded. The 8 existing terms + term_relationships stay intact — + * 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. * - * Side effects: registers taxonomy with WordPress. + * v0.3.0: `peptide_topic` taxonomy added. Non-hierarchical, linked to posts, + * uses peptide slugs as terms (e.g., 'bpc-157', 'tb-500'). Enables the Related + * Articles feature for blog posts tagged with a peptide topic. + * + * Side effects: registers taxonomies with WordPress. * * @return void */ public static function register_taxonomies(): void { - if ( taxonomy_exists( self::TAX_CATEGORY ) ) { - return; + // Register peptide_category taxonomy. + if ( ! taxonomy_exists( self::TAX_CATEGORY ) ) { + register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [ + 'labels' => [ + 'name' => __( 'Peptide Categories', 'peptide-repo-core' ), + 'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ), + ], + 'public' => true, + 'publicly_queryable' => true, + 'show_in_rest' => true, + 'show_ui' => true, + 'show_admin_column' => true, + 'hierarchical' => true, + 'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ], + ] ); } - register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [ - 'labels' => [ - 'name' => __( 'Peptide Categories', 'peptide-repo-core' ), - 'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ), - ], - 'public' => true, - 'publicly_queryable' => true, - 'show_in_rest' => true, - 'show_ui' => true, - 'show_admin_column' => true, - 'hierarchical' => true, - 'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ], - ] ); + // Register peptide_topic taxonomy (for blog post tagging). + if ( ! taxonomy_exists( self::TAX_TOPIC ) ) { + 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 ], + ] ); + } } /**