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