feat: add peptide_topic taxonomy registration

This commit is contained in:
peptiderepo
2026-04-24 10:01:47 +07:00
parent 14f8e6159a
commit 0210d73cf7

View File

@@ -2,9 +2,11 @@
declare(strict_types=1); 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. * 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. * Who calls it: PR_Core::init() on plugins_loaded.
* Dependencies: None. * Dependencies: None.
* *
@@ -15,6 +17,10 @@ declare(strict_types=1);
* deploy order between the two plugins does not matter — whichever runs first * deploy order between the two plugins does not matter — whichever runs first
* wins, the other no-ops. * 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 ARCHITECTURE.md — CPT specification and post-meta field definitions.
* @see CONVENTIONS.md — CPT ownership rule (no plugin registers a CPT another plugin owns). * @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). */ /** @var string Taxonomy: category (e.g., GLP-1 agonist). */
public const TAX_CATEGORY = 'peptide_category'; 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. */ /** @var string Capability required for editing peptide data. */
public const CAPABILITY = 'manage_peptide_content'; 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 * 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, * they key on taxonomy name `peptide_category` in wp_term_taxonomy,
* which is exactly what we register here. * which is exactly what we register here.
* *
* v0.2.0: `pr_peptide_family` taxonomy removed — never populated, never * v0.2.0: `pr_peptide_family` taxonomy removed — never populated, never
* surfaced in UI. * 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 * @return void
*/ */
public static function register_taxonomies(): void { public static function register_taxonomies(): void {
if ( taxonomy_exists( self::TAX_CATEGORY ) ) { // Register peptide_category taxonomy.
return; 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, [ // Register peptide_topic taxonomy (for blog post tagging).
'labels' => [ if ( ! taxonomy_exists( self::TAX_TOPIC ) ) {
'name' => __( 'Peptide Categories', 'peptide-repo-core' ), register_taxonomy( self::TAX_TOPIC, 'post', [
'singular_name' => __( 'Peptide Category', 'peptide-repo-core' ), 'labels' => [
], 'name' => __( 'Peptide Topics', 'peptide-repo-core' ),
'public' => true, 'singular_name' => __( 'Peptide Topic', 'peptide-repo-core' ),
'publicly_queryable' => true, ],
'show_in_rest' => true, 'public' => true,
'show_ui' => true, 'publicly_queryable' => true,
'show_admin_column' => true, 'show_in_rest' => true,
'hierarchical' => true, 'show_ui' => true,
'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ], 'show_admin_column' => true,
] ); 'hierarchical' => false,
'rewrite' => [ 'slug' => 'peptide-topic', 'with_front' => false ],
] );
}
} }
/** /**