v4.5.0: drop peptide CPT registration; add PR Core dependency check (#15)

Drops PSA registration of peptide CPT + peptide_category taxonomy (PR Core >= 0.2.0 now owns them per 2026-04-22 consolidation). Adds hard dependency check on PR Core 0.2.0+ — PSA self-deactivates with an admin notice if PR Core is missing or below min version.

CI note: PHPUnit failures (PSA_AI_Content, PSA_Directory_API not found) and WPCS failure are pre-existing on main at HEAD 65f973f (verified: same 5 errors in run 24530495421). PHP Lint green on 7.4/8.1/8.3. No regressions introduced by this PR.

QA: qa-reviews/2026-04-22-2609c66.md PASS.
This commit is contained in:
peptiderepo
2026-04-22 17:12:34 +07:00
committed by GitHub
parent 65f973fea4
commit 868d31cfb3
8 changed files with 480 additions and 292 deletions

View File

@@ -0,0 +1,81 @@
<?php
/**
* Dependency check for Peptide Repo Core (PR Core).
*
* What: Verifies PR Core >= REQUIRED_PR_CORE_VERSION is active so PSA can rely
* on the `peptide` CPT + `peptide_category` taxonomy being registered. Renders
* an admin notice when the dependency is unmet. Serves as a boot-path gate:
* PSA surfaces that operate on the `peptide` CPT (meta boxes, admin columns,
* directory widget, KB renderer, search widget, template) call
* is_satisfied() and degrade gracefully — they do not fatal — when PR Core is
* missing or out of date.
*
* Who calls it: Main plugin bootstrap (`psa_init` + `psa_admin_init`) and each
* CPT-dependent class's `init()` method before hooking into WordPress.
* Dependencies: PR Core defines the PR_CORE_VERSION constant in its main
* plugin file; absence of the constant is treated as "not installed."
*
* @package PeptideSearchAI
* @since 4.5.0
* @see includes/class-psa-post-type.php — Gated via init_admin().
* @see includes/class-psa-directory.php — Gated via init().
* @see includes/class-psa-template.php — Gated via init().
* @see includes/class-psa-search.php — Gated via init().
*/
declare( strict_types=1 );
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class PSA_Dependency_Check {
/**
* Minimum PR Core version that registers the `peptide` CPT + `peptide_category`
* taxonomy in the shape PSA depends on. Coordinated release: see
* `convo/peptidesearch/threads/2026-04-peptide-cpt-consolidation/`.
*/
const REQUIRED_PR_CORE_VERSION = '0.2.0';
/** Register the admin notice hook. Safe to call multiple times. */
public static function init(): void {
add_action( 'admin_notices', array( __CLASS__, 'maybe_render_notice' ) );
}
/**
* Whether PR Core is installed, active, and at a version PSA accepts.
*
* Pure function — no side effects. Safe to call from any boot-path gate.
*
* @return bool True when PR_CORE_VERSION is defined and >= REQUIRED_PR_CORE_VERSION.
*/
public static function is_satisfied(): bool {
if ( ! defined( 'PR_CORE_VERSION' ) ) {
return false;
}
return version_compare( (string) constant( 'PR_CORE_VERSION' ), self::REQUIRED_PR_CORE_VERSION, '>=' );
}
/**
* Render the admin notice when the dependency is unmet.
*
* Hooked to `admin_notices`. Skips rendering when the dependency is
* satisfied and when the current user lacks the `activate_plugins`
* capability (the only role that can act on the notice).
*/
public static function maybe_render_notice(): void {
if ( self::is_satisfied() ) {
return;
}
if ( ! function_exists( 'current_user_can' ) || ! current_user_can( 'activate_plugins' ) ) {
return;
}
$msg = esc_html__(
'Peptide Search AI requires Peptide Repo Core 0.2.0 or newer for peptide data (custom post type and taxonomy). Please install or update Peptide Repo Core — until then, peptide meta boxes, the directory widget, and the search widget are disabled.',
'peptide-search-ai'
);
printf( '<div class="notice notice-error"><p>%s</p></div>', $msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $msg already escaped via esc_html__.
}
}

View File

@@ -1,16 +1,26 @@
<?php
/**
* Registers the Peptide custom post type, taxonomy, and admin columns.
* PSA's consumer-side integration with the `peptide` custom post type.
*
* What: CPT registration, taxonomy registration, default category seeding, admin columns.
* Who calls it: Main plugin file via psa_init() and psa_admin_init() hooks.
* Dependencies: WordPress CPT API, taxonomy API.
* As of v4.5.0 the `peptide` CPT and `peptide_category` taxonomy are owned by
* Peptide Repo Core (PR Core) >= 0.2.0 — PSA no longer registers them. This
* class now wires PSA-owned admin surfaces (meta boxes, admin columns) onto
* the CPT that PR Core registers, and exposes the `psa_*` meta key namespace
* via constants for the rest of PSA to consume.
*
* What: Admin columns, meta key definitions, get_all_meta_keys() helper, and
* backward-compatible proxies to PSA_Post_Type_Meta.
* Who calls it: `psa_admin_init()` in the main plugin file, gated by
* PSA_Dependency_Check::is_satisfied() so admin surfaces don't bind against
* a missing CPT when PR Core is absent.
* Dependencies: PR Core >= 0.2.0 for the CPT itself (runtime); WordPress
* meta-box + admin-column APIs; PSA_Post_Type_Meta for meta box rendering.
*
* @package PeptideSearchAI
* @since 1.0.0
* @see includes/class-psa-post-type-meta.php — Meta box rendering and save handlers.
* @see includes/class-psa-ai-content.php — Uses DEFAULT_CATEGORIES for category assignment.
* @see includes/class-psa-directory.php — Reads taxonomy for directory filtering.
* @since 1.0.0 (CPT registration removed in 4.5.0)
* @see includes/class-psa-post-type-meta.php — Meta box rendering and save handlers.
* @see includes/class-psa-dependency-check.php — PR Core gate used by init_admin().
* @see includes/class-psa-directory.php — Reads `peptide_category` terms for directory filtering.
*/
declare( strict_types=1 );
@@ -20,7 +30,16 @@ if ( ! defined( 'ABSPATH' ) ) {
class PSA_Post_Type {
/** Default peptide category terms pre-populated on activation. slug => display name. */
/**
* Canonical slug → display-name map for the peptide categories PSA's
* AI and admin tools know how to assign terms to. This is a consumer
* reference list (used by PSA_AI_Content::assign_category_term() and
* the "Migrate Existing Peptides to Categories" admin button) — not a
* seed list. As of PSA v4.5.0 PR Core >= 0.2.0 owns the
* `peptide_category` taxonomy; the 8 terms below were seeded by PSA
* in pre-v4.5.0 releases and remain intact in `wp_term_taxonomy`. PSA
* no longer seeds them on activation.
*/
const DEFAULT_CATEGORIES = array(
'tissue-repair' => 'Tissue Repair',
'lipid-metabolism' => 'Lipid Metabolism',
@@ -60,7 +79,14 @@ class PSA_Post_Type {
'psa_amino_acid_count' => 'Amino Acid Count',
);
/** Register admin-only hooks (meta boxes, save, admin columns). */
/**
* Register admin-only hooks (meta boxes, save, admin columns).
*
* Caller (`psa_admin_init`) gates this behind
* PSA_Dependency_Check::is_satisfied() so meta boxes + admin columns
* don't attempt to bind against a `peptide` CPT that PR Core has not
* yet registered.
*/
public static function init_admin(): void {
add_action( 'add_meta_boxes', array( 'PSA_Post_Type_Meta', 'add_meta_boxes' ) );
add_action( 'save_post_peptide', array( 'PSA_Post_Type_Meta', 'save_meta' ) );
@@ -68,72 +94,6 @@ class PSA_Post_Type {
add_action( 'manage_peptide_posts_custom_column', array( __CLASS__, 'render_admin_column' ), 10, 2 );
}
/** Register the peptide CPT. */
public static function register_peptide_post_type(): void {
if ( post_type_exists( 'peptide' ) ) {
return;
}
register_post_type( 'peptide', array(
'labels' => array(
'name' => 'Peptides',
'singular_name' => 'Peptide',
'menu_name' => 'Peptides',
'add_new' => 'Add Peptide',
'add_new_item' => 'Add New Peptide',
'edit_item' => 'Edit Peptide',
'new_item' => 'New Peptide',
'view_item' => 'View Peptide',
'search_items' => 'Search Peptides',
'not_found' => 'No peptides found',
'not_found_in_trash' => 'No peptides found in Trash',
),
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => 'peptides' ),
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' ),
'menu_icon' => 'dashicons-database',
'show_in_rest' => true,
'capability_type' => 'post',
'hierarchical' => false,
) );
}
/** Register the peptide_category taxonomy on the peptide CPT. */
public static function register_taxonomy(): void {
if ( taxonomy_exists( 'peptide_category' ) ) {
return;
}
register_taxonomy( 'peptide_category', 'peptide', array(
'labels' => array(
'name' => __( 'Peptide Categories', 'peptide-search-ai' ),
'singular_name' => __( 'Peptide Category', 'peptide-search-ai' ),
'search_items' => __( 'Search Categories', 'peptide-search-ai' ),
'all_items' => __( 'All Categories', 'peptide-search-ai' ),
'edit_item' => __( 'Edit Category', 'peptide-search-ai' ),
'update_item' => __( 'Update Category', 'peptide-search-ai' ),
'add_new_item' => __( 'Add New Category', 'peptide-search-ai' ),
'new_item_name' => __( 'New Category Name', 'peptide-search-ai' ),
'menu_name' => __( 'Categories', 'peptide-search-ai' ),
),
'hierarchical' => true,
'public' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'rewrite' => array( 'slug' => 'peptide-category' ),
) );
}
/** Pre-populate default category terms on activation. Idempotent. */
public static function populate_default_categories(): void {
foreach ( self::DEFAULT_CATEGORIES as $slug => $name ) {
if ( ! term_exists( $slug, 'peptide_category' ) ) {
wp_insert_term( $name, 'peptide_category', array( 'slug' => $slug ) );
}
}
}
/**
* Add custom columns to the peptide admin list.
*