fix(cpt): restore complete file — patch truncation from prior commit

This commit is contained in:
peptiderepo
2026-04-25 01:51:28 +07:00
committed by peptiderepo
parent 3382cd3c96
commit 224fae5c2b

View File

@@ -2,9 +2,10 @@
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).
* Who calls it: PR_Core::init() on plugins_loaded. * Who calls it: PR_Core::init() on plugins_loaded.
* Dependencies: None. * Dependencies: None.
* *
@@ -183,10 +184,8 @@ class PR_Core_Peptide_CPT {
'show_in_nav_menus' => true, 'show_in_nav_menus' => true,
'show_in_rest' => true, 'show_in_rest' => true,
'rest_base' => 'peptides', 'rest_base' => 'peptides',
// Note: 'rest_namespace' is deliberately omitted. Custom namespaces prevent // 'rest_namespace' omitted — custom namespaces break Gutenberg (it
// Gutenberg's block editor from loading posts for editing (it fetches the // fetches wp/v2 hardcoded). WordPress defaults to wp/v2. (#4)
// hardcoded wp/v2 REST route). WordPress defaults to wp/v2 — appropriate for
// this CPT — and keeps the REST endpoint at /wp-json/wp/v2/peptides/.
'menu_position' => 25, 'menu_position' => 25,
'menu_icon' => 'dashicons-database', 'menu_icon' => 'dashicons-database',
'capability_type' => 'post', 'capability_type' => 'post',
@@ -204,22 +203,22 @@ class PR_Core_Peptide_CPT {
* Register the `peptide_category` taxonomy. * Register the `peptide_category` taxonomy.
* *
* 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.
* *
* v0.3.0: `peptide_topic` taxonomy moved to PR_Core_Topic_Taxonomy class.
*
* Side effects: registers taxonomy with WordPress. * Side effects: registers taxonomy 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, [ register_taxonomy( self::TAX_CATEGORY, self::POST_TYPE, [
'labels' => [ 'labels' => [
'name' => __( 'Peptide Categories', 'peptide-repo-core' ), 'name' => __( 'Peptide Categories', 'peptide-repo-core' ),
@@ -234,6 +233,7 @@ class PR_Core_Peptide_CPT {
'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ], 'rewrite' => [ 'slug' => 'peptide-category', 'with_front' => false ],
] ); ] );
} }
}
/** /**
* Register post-meta fields. Auth gated on manage_peptide_content. * Register post-meta fields. Auth gated on manage_peptide_content.
@@ -288,4 +288,11 @@ class PR_Core_Peptide_CPT {
/** /**
* Sanitize editorial_review_status to allowed enum values. * Sanitize editorial_review_status to allowed enum values.
* *
* @param mixed $value Raw input.
* @return string Valid enum value.
*/
public static function sanitize_review_status( $value ): string {
$value = sanitize_text_field( (string) $value );
return in_array( $value, self::REVIEW_STATUSES, true ) ? $value : 'draft';
}
}