query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- uninstall clean-up of our own options and transients. $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s', $wpdb->options, $wpdb->esc_like( 'aigeschikt_' ) . '%', $wpdb->esc_like( '_transient_aigeschikt_' ) . '%', $wpdb->esc_like( '_transient_timeout_aigeschikt_' ) . '%' ) ); // Post meta written by the plugin (edits, schema, provenance markers). $wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- uninstall clean-up of our own meta keys. $wpdb->prepare( 'DELETE FROM %i WHERE meta_key LIKE %s', $wpdb->postmeta, $wpdb->esc_like( '_aigeschikt_' ) . '%' ) ); // Bot-event buffer table. $aigeschikt_table = $wpdb->prefix . 'aigeschikt_bot_events'; $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $aigeschikt_table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- uninstall: drop our own table. // Scheduled events. wp_clear_scheduled_hook( 'aigeschikt_sync_ip_ranges' ); wp_clear_scheduled_hook( 'aigeschikt_sync_bot_events' ); // Spool folder in uploads. $uploads = wp_upload_dir( null, false ); if ( is_array( $uploads ) && ! empty( $uploads['basedir'] ) ) { $dir = trailingslashit( $uploads['basedir'] ) . 'aigeschikt-bot-spool'; if ( is_dir( $dir ) ) { $files = scandir( $dir ); foreach ( (array) $files as $file ) { if ( '.' === $file || '..' === $file ) { continue; } wp_delete_file( $dir . '/' . $file ); } @rmdir( $dir ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir,WordPress.PHP.NoSilencedErrors.Discouraged -- our own, now empty, folder. } } } // Fallback: if our advanced-cache.php drop-in is somehow still there, remove it // (and put a cache plugin's original back) so nothing of ours keeps loading. $aigeschikt_ac = WP_CONTENT_DIR . '/advanced-cache.php'; $aigeschikt_ac_bak = WP_CONTENT_DIR . '/advanced-cache-aigeschikt-origineel.php'; if ( is_file( $aigeschikt_ac ) && false !== strpos( (string) file_get_contents( $aigeschikt_ac ), '// AIGeschikt vroege botdetectie (cache)' ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- local file. wp_delete_file( $aigeschikt_ac ); if ( is_file( $aigeschikt_ac_bak ) ) { @rename( $aigeschikt_ac_bak, $aigeschikt_ac ); // phpcs:ignore WordPress.WP.AlternativeFunctions.rename_rename,WordPress.PHP.NoSilencedErrors.Discouraged,PluginCheck.CodeAnalysis.WriteFile.PluginDirectoryWrite -- restores the cache plugin's original drop-in in wp-content (not the plugin folder). } } if ( is_multisite() ) { foreach ( get_sites( array( 'fields' => 'ids', 'number' => 0 ) ) as $aigeschikt_blog_id ) { switch_to_blog( (int) $aigeschikt_blog_id ); aigeschikt_uninstall_site(); restore_current_blog(); } } else { aigeschikt_uninstall_site(); }