run_v2_migration(); } } /** * Execute the v2.0.0 data rescue and migration. */ private function run_v2_migration() { global $wpdb; // 1. RESCUE OLD CUSTOM POST TYPES // If users have documents saved under '24tt_document' or 'tt_document', move them to 'ttdvr_document' $wpdb->query( " UPDATE {$wpdb->posts} SET post_type = 'ttdvr_document' WHERE post_type IN ('24tt_document', 'tt_document') " ); // 2. RESCUE OLD TAXONOMIES // Move old categories to the new 'ttdvr_doc_category' $wpdb->query( " UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'ttdvr_doc_category' WHERE taxonomy IN ('24tt_doc_category', 'tt_doc_category') " ); // 3. RESCUE OLD META KEYS (Data Fields) // Safely replace old prefixes (_24tt_ or _tt_) with the new secure _ttdvr_ prefix $wpdb->query( " UPDATE {$wpdb->postmeta} SET meta_key = REPLACE(meta_key, '_24tt_', '_ttdvr_') WHERE meta_key LIKE '_24tt_%' " ); $wpdb->query( " UPDATE {$wpdb->postmeta} SET meta_key = REPLACE(meta_key, '_tt_', '_ttdvr_') WHERE meta_key LIKE '_tt_%' " ); // 4. PREVENT BROKEN FRONTENDS (Configure the Kill Switch) // Automatically grab all existing categories and set them as "Publicly Verifiable" // so the user's live verification forms do not suddenly stop working. $all_categories = get_terms( array( 'taxonomy' => 'ttdvr_doc_category', 'hide_empty' => false ) ); if ( ! empty( $all_categories ) && ! is_wp_error( $all_categories ) ) { $cat_ids = wp_list_pluck( $all_categories, 'term_id' ); update_option( 'ttdvr_public_categories', $cat_ids ); } // Ensure the default PDF display is turned on if ( false === get_option( 'ttdvr_show_pdf_link' ) ) { update_option( 'ttdvr_show_pdf_link', 'yes' ); } // 5. FINALIZE MIGRATION // Flush rewrite rules so URLs for the rescued documents work perfectly flush_rewrite_rules(); // Update the database version so this script doesn't run again update_option( 'ttdvr_db_version', TTDVR_VERSION ); // Set a transient to show a success message to the admin set_transient( 'ttdvr_upgrade_complete', true, 60 ); } /** * Show a friendly notice after a successful upgrade. */ public function display_upgrade_notice() { if ( get_transient( 'ttdvr_upgrade_complete' ) ) { // Added the 'ttdvr-notice' class to bypass our workspace enforcer! echo '
🎉 ' . esc_html__( '24TT Document Verifier successfully upgraded to v2.0.0!', '24tt-document-verifier' ) . '
' . esc_html__( 'Your database and existing documents have been safely migrated to the new enterprise architecture. Please visit "Global Settings" to review your new security features.', '24tt-document-verifier' ) . '