Upload via Git Manager GUI - uninstall.php
This commit is contained in:
227
uninstall.php
227
uninstall.php
@@ -1,114 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* WP Business Forum — Uninstaller
|
||||
* Wird automatisch aufgerufen wenn das Plugin über WP-Admin gelöscht wird.
|
||||
* Entfernt: alle DB-Tabellen, wp_options, Transients, Cron-Jobs, Upload-Verzeichnis.
|
||||
*/
|
||||
|
||||
// Sicherheits-Check — nur via WordPress-Uninstall erlaubt
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// ── 1. Alle Datenbank-Tabellen löschen ───────────────────────────────────────
|
||||
// Reihenfolge beachten: abhängige Tabellen zuerst (Foreign Keys)
|
||||
$tables = [
|
||||
'forum_poll_votes',
|
||||
'forum_polls',
|
||||
'forum_reactions',
|
||||
'forum_notifications',
|
||||
'forum_subscriptions',
|
||||
'forum_bookmarks', // ← fehlte: Lesezeichen
|
||||
'forum_ignore_list', // ← Ignore/Block-Liste
|
||||
'forum_invites',
|
||||
'forum_thread_tags',
|
||||
'forum_tags',
|
||||
'forum_prefixes', // ← fehlte: Thread-Präfixe
|
||||
'forum_reports',
|
||||
'forum_likes',
|
||||
'forum_messages',
|
||||
'forum_remember_tokens',
|
||||
'forum_user_meta',
|
||||
'forum_posts',
|
||||
'forum_threads',
|
||||
'forum_categories',
|
||||
'forum_users',
|
||||
];
|
||||
|
||||
foreach ( $tables as $table ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}{$table}`" );
|
||||
}
|
||||
|
||||
// ── 2. Alle wp_options löschen ───────────────────────────────────────────────
|
||||
$options = [
|
||||
'wbf_settings',
|
||||
'wbf_custom_roles',
|
||||
'wbf_level_config',
|
||||
'wbf_levels_enabled',
|
||||
'wbf_profile_fields',
|
||||
'wbf_reactions',
|
||||
'wbf_forum_page_id',
|
||||
'wbf_superadmin_email',
|
||||
'wbf_db_version',
|
||||
'wbf_word_filter',
|
||||
];
|
||||
|
||||
foreach ( $options as $option ) {
|
||||
delete_option( $option );
|
||||
}
|
||||
|
||||
// Multisite: Netzwerk-Optionen ebenfalls entfernen
|
||||
if ( is_multisite() ) {
|
||||
foreach ( $options as $option ) {
|
||||
delete_site_option( $option );
|
||||
}
|
||||
}
|
||||
|
||||
// ── 3. Transients löschen ────────────────────────────────────────────────────
|
||||
delete_transient( 'wbf_activation_redirect' );
|
||||
delete_transient( 'wbf_stats_cache' );
|
||||
delete_transient( 'wbf_update_check' );
|
||||
|
||||
// Alle wbf_* Transients per LIKE-Query entfernen (inkl. Update-Dismissed-Transients)
|
||||
$wpdb->query(
|
||||
"DELETE FROM `{$wpdb->options}`
|
||||
WHERE `option_name` LIKE '_transient_wbf_%'
|
||||
OR `option_name` LIKE '_transient_timeout_wbf_%'"
|
||||
);
|
||||
|
||||
// ── 4. Geplante Cron-Jobs entfernen ──────────────────────────────────────────
|
||||
wp_clear_scheduled_hook( 'wbf_check_expired_bans' );
|
||||
wp_clear_scheduled_hook( 'wbf_check_for_updates' );
|
||||
|
||||
// ── 5. Forum-Seite löschen (vom Setup-Wizard erstellt) ───────────────────────
|
||||
$forum_page_id = get_option( 'wbf_forum_page_id' );
|
||||
if ( $forum_page_id ) {
|
||||
wp_delete_post( (int) $forum_page_id, true ); // true = dauerhaft löschen
|
||||
}
|
||||
|
||||
// ── 6. Upload-Unterverzeichnis entfernen ─────────────────────────────────────
|
||||
$upload_dir = wp_upload_dir();
|
||||
$wbf_dir = trailingslashit( $upload_dir['basedir'] ) . 'wbf-avatars';
|
||||
if ( is_dir( $wbf_dir ) ) {
|
||||
wbf_uninstall_rmdir( $wbf_dir );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsfunktion: Verzeichnis rekursiv löschen.
|
||||
* Nur innerhalb des WP-Upload-Verzeichnisses erlaubt.
|
||||
*/
|
||||
function wbf_uninstall_rmdir( $dir ) {
|
||||
$upload_base = wp_upload_dir()['basedir'];
|
||||
// Sicherheitscheck: nur Unterverzeichnisse von uploads/ löschen
|
||||
if ( strpos( realpath( $dir ), realpath( $upload_base ) ) !== 0 ) {
|
||||
return;
|
||||
}
|
||||
$files = array_diff( scandir( $dir ), [ '.', '..' ] );
|
||||
foreach ( $files as $file ) {
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $file;
|
||||
is_dir( $path ) ? wbf_uninstall_rmdir( $path ) : unlink( $path );
|
||||
}
|
||||
rmdir( $dir );
|
||||
<?php
|
||||
/**
|
||||
* WP Business Forum — Uninstaller
|
||||
* Wird automatisch aufgerufen wenn das Plugin über WP-Admin gelöscht wird.
|
||||
* Entfernt: alle DB-Tabellen, wp_options, Transients, Cron-Jobs, Upload-Verzeichnis.
|
||||
*/
|
||||
|
||||
// Sicherheits-Check — nur via WordPress-Uninstall erlaubt
|
||||
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
// ── 1. Alle Datenbank-Tabellen löschen ───────────────────────────────────────
|
||||
// Reihenfolge beachten: abhängige Tabellen zuerst (Foreign Keys)
|
||||
$tables = [
|
||||
'forum_poll_votes',
|
||||
'forum_polls',
|
||||
'forum_reactions',
|
||||
'forum_notifications',
|
||||
'forum_subscriptions',
|
||||
'forum_bookmarks', // ← fehlte: Lesezeichen
|
||||
'forum_ignore_list', // ← Ignore/Block-Liste
|
||||
'forum_invites',
|
||||
'forum_thread_tags',
|
||||
'forum_tags',
|
||||
'forum_prefixes', // ← fehlte: Thread-Präfixe
|
||||
'forum_reports',
|
||||
'forum_likes',
|
||||
'forum_messages',
|
||||
'forum_remember_tokens',
|
||||
'forum_user_meta',
|
||||
'forum_posts',
|
||||
'forum_threads',
|
||||
'forum_categories',
|
||||
'forum_users',
|
||||
];
|
||||
|
||||
foreach ( $tables as $table ) {
|
||||
$wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}{$table}`" );
|
||||
}
|
||||
|
||||
// ── 2. Alle wp_options löschen ───────────────────────────────────────────────
|
||||
$options = [
|
||||
'wbf_settings',
|
||||
'wbf_custom_roles',
|
||||
'wbf_level_config',
|
||||
'wbf_levels_enabled',
|
||||
'wbf_profile_fields',
|
||||
'wbf_profile_field_cats',
|
||||
'wbf_reactions',
|
||||
'wbf_forum_page_id',
|
||||
'wbf_superadmin_email',
|
||||
'wbf_db_version',
|
||||
'wbf_word_filter',
|
||||
];
|
||||
|
||||
foreach ( $options as $option ) {
|
||||
delete_option( $option );
|
||||
}
|
||||
|
||||
// Multisite: Netzwerk-Optionen ebenfalls entfernen
|
||||
if ( is_multisite() ) {
|
||||
foreach ( $options as $option ) {
|
||||
delete_site_option( $option );
|
||||
}
|
||||
}
|
||||
|
||||
// ── 3. Transients löschen ────────────────────────────────────────────────────
|
||||
delete_transient( 'wbf_activation_redirect' );
|
||||
delete_transient( 'wbf_stats_cache' );
|
||||
delete_transient( 'wbf_update_check' );
|
||||
|
||||
// Alle wbf_* Transients per LIKE-Query entfernen (inkl. Update-Dismissed-Transients)
|
||||
$wpdb->query(
|
||||
"DELETE FROM `{$wpdb->options}`
|
||||
WHERE `option_name` LIKE '_transient_wbf_%'
|
||||
OR `option_name` LIKE '_transient_timeout_wbf_%'"
|
||||
);
|
||||
|
||||
// ── 4. Geplante Cron-Jobs entfernen ──────────────────────────────────────────
|
||||
wp_clear_scheduled_hook( 'wbf_check_expired_bans' );
|
||||
wp_clear_scheduled_hook( 'wbf_check_for_updates' );
|
||||
|
||||
// ── 5. Forum-Seite löschen (vom Setup-Wizard erstellt) ───────────────────────
|
||||
$forum_page_id = get_option( 'wbf_forum_page_id' );
|
||||
if ( $forum_page_id ) {
|
||||
wp_delete_post( (int) $forum_page_id, true ); // true = dauerhaft löschen
|
||||
}
|
||||
|
||||
// ── 6. Upload-Unterverzeichnis entfernen ─────────────────────────────────────
|
||||
$upload_dir = wp_upload_dir();
|
||||
$wbf_dir = trailingslashit( $upload_dir['basedir'] ) . 'wbf-avatars';
|
||||
if ( is_dir( $wbf_dir ) ) {
|
||||
wbf_uninstall_rmdir( $wbf_dir );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hilfsfunktion: Verzeichnis rekursiv löschen.
|
||||
* Nur innerhalb des WP-Upload-Verzeichnisses erlaubt.
|
||||
*/
|
||||
function wbf_uninstall_rmdir( $dir ) {
|
||||
$upload_base = wp_upload_dir()['basedir'];
|
||||
// Sicherheitscheck: nur Unterverzeichnisse von uploads/ löschen
|
||||
if ( strpos( realpath( $dir ), realpath( $upload_base ) ) !== 0 ) {
|
||||
return;
|
||||
}
|
||||
$files = array_diff( scandir( $dir ), [ '.', '..' ] );
|
||||
foreach ( $files as $file ) {
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $file;
|
||||
is_dir( $path ) ? wbf_uninstall_rmdir( $path ) : unlink( $path );
|
||||
}
|
||||
rmdir( $dir );
|
||||
}
|
||||
Reference in New Issue
Block a user