Files
prautoblogger/uninstall.php
peptiderepo 1704d7f3a6 feat(schema): v1.2.0 substrate schema + stage display map (v0.18.0)
Pipeline v2 Phase 1, commit 1/4. Five new dbDelta-idempotent tables
(prompts, run_sources, run_decisions, runs, run_stages), additive
nullable agent_role + prompt_version columns on generation_log,
PRAUTOBLOGGER_DB_VERSION 1.1.0 -> 1.2.0 (existing on_check_db_version
auto-migration re-runs the installers on mismatch), Stage_Display_Map
covering historical + image + v2 stage vocabulary with humanizing
fallback, uninstall coverage for all new tables + full cron hook list,
ARCHITECTURE edit->polish canonicalization + schema docs + decision #22.

No behavior change: nothing reads the new tables yet.

Agent-Session: pipeline-v2-phase1-engineer-20260612
2026-06-11 16:42:56 +07:00

101 lines
2.9 KiB
PHP

<?php
/**
* phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration -- strict_types must precede docblock
*
* Fired when the plugin is uninstalled (deleted) from WordPress.
*
* Removes ALL plugin data: custom tables, options, post meta, transients, and cron events.
* This is the nuclear option — only runs when the user explicitly deletes the plugin.
*
* @see class-deactivator.php — Lighter cleanup on deactivation (preserves data).
*/
declare(strict_types=1);
// Abort if not called by WordPress uninstall process.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
/*
|--------------------------------------------------------------------------
| 1. Drop Custom Tables
|--------------------------------------------------------------------------
*/
$prefix = $wpdb->prefix . 'prautoblogger_';
$tables = array(
$prefix . 'source_data',
$prefix . 'analysis_results',
$prefix . 'generation_log',
$prefix . 'content_scores',
$prefix . 'event_log',
// Pipeline v2 substrate (v0.18.0 / db 1.2.0).
$prefix . 'prompts',
$prefix . 'run_sources',
$prefix . 'run_decisions',
$prefix . 'runs',
$prefix . 'run_stages',
);
foreach ( $tables as $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are hardcoded above, not user input.
$wpdb->query( "DROP TABLE IF EXISTS {$table}" );
}
/*
|--------------------------------------------------------------------------
| 2. Delete All Plugin Options
|--------------------------------------------------------------------------
*/
$options = $wpdb->get_col(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'prautoblogger\_%'"
);
foreach ( $options as $option ) {
delete_option( $option );
}
/*
|--------------------------------------------------------------------------
| 3. Delete All Plugin Post Meta
|--------------------------------------------------------------------------
*/
$wpdb->query(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '\\_prautoblogger\\_%'"
);
/*
|--------------------------------------------------------------------------
| 4. Delete All Plugin Transients
|--------------------------------------------------------------------------
*/
$wpdb->query(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE '\\_transient\\_prautoblogger\\_%' OR option_name LIKE '\\_transient\\_timeout\\_prautoblogger\\_%'"
);
/*
|--------------------------------------------------------------------------
| 5. Clear Any Remaining Cron Events
|--------------------------------------------------------------------------
*/
$hooks = array(
'prautoblogger_daily_generation',
'prautoblogger_collect_metrics',
'prautoblogger_reap_orphan_research_rows',
'prautoblogger_sync_runware_models',
'prautoblogger_manual_generation',
'prautoblogger_generate_queued_article',
'prautoblogger_generate_from_idea',
'prautoblogger_opik_dispatch',
);
foreach ( $hooks as $hook ) {
wp_clear_scheduled_hook( $hook );
}