query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk removal of the plugin's own transients. $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s OR option_name LIKE %s', $wpdb->options, $wpdb->esc_like( '_transient_' . RateLimiter::TRANSIENT_PREFIX ) . '%', $wpdb->esc_like( '_transient_timeout_' . RateLimiter::TRANSIENT_PREFIX ) . '%' ) ); } /** * Deletes every request in any status, with its comments, meta, revisions and term links. */ private static function delete_requests(): void { global $wpdb; do { $ids = $wpdb->get_col( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Covers every post status, including trash and auto-draft. $wpdb->prepare( 'SELECT ID FROM %i WHERE post_type = %s LIMIT 100', $wpdb->posts, RequestPostType::NAME ) ); $deleted = 0; foreach ( $ids as $id ) { if ( wp_delete_post( (int) $id, true ) ) { ++$deleted; } } } while ( $deleted > 0 ); } /** * Deletes every board, status and category, with their term meta. */ private static function delete_terms(): void { foreach ( ContentTypes::taxonomies() as $taxonomy ) { $term_ids = get_terms( [ 'taxonomy' => $taxonomy, 'hide_empty' => false, 'fields' => 'ids', ] ); if ( ! is_array( $term_ids ) ) { continue; } foreach ( $term_ids as $term_id ) { wp_delete_term( (int) $term_id, $taxonomy ); } // WordPress keeps a map of parents and children for a taxonomy in an option named after it, and writes it again after each deletion. delete_option( $taxonomy . '_children' ); } } }