Files
peptide-search-ai/uninstall.php
peptiderepo 868d31cfb3 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.
2026-04-22 17:12:34 +07:00

44 lines
1.6 KiB
PHP
Executable File

<?php
/**
* Fired when the plugin is uninstalled.
*
* As of PSA v4.5.0 the `peptide` custom post type and `peptide_category`
* taxonomy are owned by Peptide Repo Core (PR Core) — PSA is a consumer, not
* the owner. Uninstalling PSA must therefore NOT delete peptide posts,
* peptide_category terms, or any `psa_*` post meta: that data predates PR
* Core and is consumed by other plugins via PR Core's data layer + PSA's
* REST endpoints. Removing it on uninstall would be destructive across
* plugin boundaries.
*
* This uninstaller only removes PSA's own option rows, transients, and the
* `wp_psa_api_logs` table (PSA's internal cost-tracking table — no other
* plugin reads from it).
*
* @package PeptideSearchAI
*/
// Abort if not called by WordPress.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
// 1. Delete plugin options.
delete_option( 'psa_settings' );
delete_option( 'psa_search_cache_gen' );
delete_option( 'psa_db_version' );
// 2. Delete all plugin transients (validation cache, rate limits, PubChem cache).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$wpdb->esc_like( '_transient_psa_' ) . '%',
$wpdb->esc_like( '_transient_timeout_psa_' ) . '%'
)
);
// 3. Drop PSA's API logs table. Owned entirely by PSA; no cross-plugin reads.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}psa_api_logs" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared
// 4. NOT deleted (owned by Peptide Repo Core as of PSA v4.5.0)