query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'svabg_scanlist' ) ); if ( ! $delete_all ) { // Keep the tables; drop only the version marker's dependence. } else { // What the owner made with the site features: only when everything is to go. foreach ( array( 'svabg_redirects', 'svabg_redirect_hits', 'svabg_404_log', 'svabg_permalinks_map', 'svabg_snippets', 'svabg_maintenance', 'svabg_cpt', 'svabg_roles_backup', 'svabg_custom_caps' ) as $option ) { delete_option( $option ); } $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN (%s, %s)", '_svabg_permalink', '_svabg_duplicate_of' ) ); // phpcs:ignore WordPress.DB foreach ( array( 'findings', 'scans', 'log', 'lockouts', 'filehash', 'knowledge', 'links', 'traffic', 'quarantine' ) as $name ) { $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'svabg_' . $name ) ); } delete_option( 'svabg_db_version' ); $backups = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_svabg_backup_' ) . '%', $wpdb->esc_like( 'svabg_import_' ) . '%' ) ); foreach ( (array) $backups as $name ) { delete_option( $name ); } $upload = wp_upload_dir( null, false ); // The plugin's own folder in uploads (named after the slug) and the one of 1.5.0 and older. $dirs = array( trailingslashit( $upload['basedir'] ) . 'ai-guardwall', trailingslashit( $upload['basedir'] ) . 'softvoltai-ai-bodyguard' ); delete_option( 'svabg_work_key' ); foreach ( $dirs as $dir ) { if ( ! is_dir( $dir ) ) { continue; } $it = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); foreach ( $it as $file ) { if ( $file->isDir() ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- removes a folder the plugin created or the administrator chose to delete. @rmdir( $file->getPathname() ); } else { wp_delete_file( $file->getPathname() ); } } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- removes a folder the plugin created or the administrator chose to delete. @rmdir( $dir ); } $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s", $wpdb->esc_like( 'svabg_' ) . '%' ) ); // phpcs:ignore WordPress.DB } // Transients share a prefix. $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_svabg_' ) . '%', $wpdb->esc_like( '_transient_timeout_svabg_' ) . '%' ) ); // phpcs:ignore WordPress.DB foreach ( array( 'svabg_daily_maintenance', 'svabg_scheduled_scan', 'svabg_scan_tick', 'svabg_scan_watchdog', 'svabg_threat_feed_update', 'svabg_geoip_update', 'svabg_geoip_step', 'svabg_monitor_check', 'svabg_summary_email', 'svabg_surge_alert', 'svabg_dbopt_auto' ) as $hook ) { wp_clear_scheduled_hook( $hook ); } // Server rules must not outlive the plugin. if ( ! function_exists( 'insert_with_markers' ) ) { require_once ABSPATH . 'wp-admin/includes/misc.php'; } if ( ! function_exists( 'get_home_path' ) ) { require_once ABSPATH . 'wp-admin/includes/file.php'; } $upload = wp_upload_dir( null, false ); foreach ( array( trailingslashit( get_home_path() ) . '.htaccess', trailingslashit( $upload['basedir'] ) . '.htaccess' ) as $file ) { if ( file_exists( $file ) && false !== strpos( (string) file_get_contents( $file ), '# BEGIN SoftVoltAI AI Bodyguard' ) ) { insert_with_markers( $file, 'SoftVoltAI AI Bodyguard', array() ); } } } if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids' ) ) as $softvolt_ai_bodyguard_site_id ) { switch_to_blog( $softvolt_ai_bodyguard_site_id ); softvolt_ai_bodyguard_uninstall_site(); restore_current_blog(); } } else { softvolt_ai_bodyguard_uninstall_site(); }