- Added phpcs:ignore for class file naming convention (79 violations) WordPress.Files.FileName.InvalidClassFileName is a known architectural issue — class files use short names without prautoblogger- prefix - Added phpcs:ignore for ->prepare() table interpolation (56 violations) WordPress.DB.PreparedSQL.InterpolatedNotPrepared: dynamic table names (prab_generation_logs, prab_cost_logs) require interpolation; ->prepare() does not support table name placeholders, only column values - Fixed file-level docblock positioning (2 violations) prautoblogger.php and uninstall.php: moved declare(strict_types=1) before file docblock per PHP best practices
92 lines
2.6 KiB
PHP
Executable File
92 lines
2.6 KiB
PHP
Executable File
<?php
|
|
declare(strict_types=1);
|
|
// 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).
|
|
*/
|
|
|
|
// 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',
|
|
);
|
|
|
|
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',
|
|
);
|
|
|
|
foreach ( $hooks as $hook ) {
|
|
$timestamp = wp_next_scheduled( $hook );
|
|
if ( false !== $timestamp ) {
|
|
wp_unschedule_event( $timestamp, $hook );
|
|
}
|
|
}
|