array( 'post', 'page' ), 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Required to find all translation posts for cleanup. 'meta_query' => array( array( 'key' => '_translatetoenglish_language', 'value' => 'en', ), ), 'no_found_rows' => true, ) ); foreach ( $translatetoenglish_translation_posts as $post_id ) { wp_delete_post( $post_id, true ); } // ------------------------------------------------------------------------- // 2. Clean up bidirectional meta on source (German) posts. // ------------------------------------------------------------------------- global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( "DELETE FROM {$wpdb->postmeta} WHERE meta_key = '_translatetoenglish_translation_id_en'" ); // ------------------------------------------------------------------------- // 3. Delete the translatetoenglish_language taxonomy and its terms. // ------------------------------------------------------------------------- $translatetoenglish_terms = get_terms( array( 'taxonomy' => 'translatetoenglish_language', 'hide_empty' => false, 'fields' => 'ids', ) ); if ( ! is_wp_error( $translatetoenglish_terms ) && is_array( $translatetoenglish_terms ) ) { foreach ( $translatetoenglish_terms as $translatetoenglish_term_id ) { wp_delete_term( $translatetoenglish_term_id, 'translatetoenglish_language' ); } } // ------------------------------------------------------------------------- // 4. Delete all plugin options. // ------------------------------------------------------------------------- $translatetoenglish_options = array( 'translatetoenglish_active_provider', 'translatetoenglish_api_key_deepl', 'translatetoenglish_deepl_api_type', 'translatetoenglish_api_key_openai', 'translatetoenglish_openai_model', 'translatetoenglish_api_key_google', 'translatetoenglish_google_project_id', 'translatetoenglish_enable_redirect', 'translatetoenglish_cookie_lifetime', 'translatetoenglish_redirect_admins', 'translatetoenglish_translate_posts', 'translatetoenglish_translate_pages', 'translatetoenglish_enable_hreflang', 'translatetoenglish_default_language', 'translatetoenglish_db_version', 'translatetoenglish_migration_v2_complete', 'translatetoenglish_migration_v2_offset', 'translatetoenglish_activation_date', 'translatetoenglish_review_dismissed', 'translatetoenglish_installed_at', 'translatetoenglish_fix_post_status_v204', 'translatetoenglish_needs_migration', ); foreach ( $translatetoenglish_options as $translatetoenglish_option ) { delete_option( $translatetoenglish_option ); } // ------------------------------------------------------------------------- // 5. Drop legacy custom tables (from v1, if still present). // ------------------------------------------------------------------------- TranslateToEnglish_Migrator::drop_tables(); // ------------------------------------------------------------------------- // 6. Flush rewrite rules and object cache. // ------------------------------------------------------------------------- flush_rewrite_rules(); wp_cache_flush();