new name (only copied when the new one is not set yet). $map = [ 'tt_pixel_id' => 'pxsync_pixel_id', 'tt_enable_am' => 'pxsync_enable_am', 'tt_capi_token' => 'pxsync_capi_token', 'tt_test_event_code' => 'pxsync_test_event_code', 'tt_debug_mode' => 'pxsync_debug_mode', 'tt_evt_pageview' => 'pxsync_evt_pageview', 'tt_evt_viewcontent' => 'pxsync_evt_viewcontent', 'tt_evt_addtocart' => 'pxsync_evt_addtocart', 'tt_evt_viewcart' => 'pxsync_evt_viewcart', 'tt_evt_initiatecheckout' => 'pxsync_evt_initiatecheckout', 'tt_evt_addpayment' => 'pxsync_evt_addpayment', 'tt_evt_purchase' => 'pxsync_evt_purchase', 'tt_evt_search' => 'pxsync_evt_search', 'tt_evt_registration' => 'pxsync_evt_registration', 'tiktok_default_country' => 'pxsync_default_country', 'ttb_feed_secret' => 'pxsync_feed_secret', 'ttb_feed_last_updated' => 'pxsync_feed_last_updated', ]; foreach ( $map as $old => $new ) { $value = get_option( $old, null ); if ( null !== $value ) { // An empty new value (for example one created by saving the empty settings form) counts as "not set". $current = get_option( $new, false ); if ( false === $current || '' === $current ) { update_option( $new, $value ); } delete_option( $old ); } } delete_option( 'ttb_db_version' ); // 2. Order meta (_ttb_* -> _pxsync_*), classic posts storage and HPOS. // Keeps "already sent" flags, so old orders are never re-sent to TikTok. $meta_tables = [ $wpdb->postmeta, $wpdb->prefix . 'wc_orders_meta' ]; foreach ( $meta_tables as $table ) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) !== $table ) continue; $wpdb->query( $wpdb->prepare( "UPDATE %i SET meta_key = CONCAT('_pxsync_', SUBSTRING(meta_key, 6)) WHERE meta_key LIKE %s", $table, $wpdb->esc_like( '_ttb_' ) . '%' ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } // 3. Live-log table: make sure the new one exists, copy old rows across, drop the old one. $old_table = $wpdb->prefix . 'ttb_logs'; $new_table = $wpdb->prefix . 'pxsync_logs'; // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $new_table ) ) !== $new_table ) { PXSYNC_Installer::activate(); } if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $old_table ) ) === $old_table ) { // One-time copy of the plugin's own old log table; %i quotes the table names safely. // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange $wpdb->query( $wpdb->prepare( 'INSERT INTO %i (event_id, event_name, source, source_platform, status, details, created_at) SELECT event_id, event_name, source, source_platform, status, details, created_at FROM %i', $new_table, $old_table ) ); $wpdb->query( $wpdb->prepare( 'DROP TABLE %i', $old_table ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange } // 4. Old scheduled hooks. // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching wp_clear_scheduled_hook( 'ttb_generate_feed_cron' ); update_option( 'pxsync_migrated_v1', 1 ); } }