run_updates( $saved_version, $current_version ); // Create ctc_analytics when upgrading to 5.3.0+ or on first install. if ( version_compare( $saved_version, '5.3.0', '<' ) ) { \CTC\Analytics\Database::create_table(); } // Update stored version. update_option( self::VERSION_OPTION, $current_version ); /** * Fires after plugin update completes. * * @since 5.0.0 * * @param string $saved_version Previously saved version. * @param string $current_version Current plugin version. */ do_action( 'ctc/updater/after', $saved_version, $current_version ); } /** * Run version-specific updates. * * @param string $from_version Version updating from. * @param string $to_version Version updating to. */ private function run_updates( $from_version, $to_version ) { // Update to 5.0.0. if ( version_compare( $from_version, '5.0.0', '<' ) ) { $this->update_to_5_0_0(); } // Update to 5.4.0: single analytics table ctc_analytics. if ( version_compare( $from_version, '5.4.0', '<' ) ) { $this->update_to_5_4_0(); } // Update to 5.4.1: migrate legacy copy_the_code_allow_tracking to ctc_telemetry_opt_in. if ( version_compare( $from_version, '5.4.1', '<' ) ) { $this->update_to_5_4_1(); } } /** * Migrate legacy tracking opt-in to new telemetry opt-in (5.4.1). * * Users who had "Allow tracking" set to yes in v4.x (copy_the_code_allow_tracking) * are treated as opted in for ctc_telemetry_opt_in so we don't ask again. * * @since 5.4.1 */ private function update_to_5_4_1() { $legacy_allow = get_option( 'copy_the_code_allow_tracking', 'no' ); if ( 'yes' === $legacy_allow ) { Telemetry::set_opt_in( true ); } } /** * Migrate to single analytics table ctc_analytics. * If ctc_copy_events exists, rename to ctc_analytics; otherwise create ctc_analytics. * * @since 5.4.0 * @return void */ private function update_to_5_4_0() { \CTC\Analytics\Database::create_table(); // Ensure daily cleanup of old analytics events is scheduled after upgrading to 5.4.0+. if ( ! wp_next_scheduled( 'ctc_analytics_cleanup' ) ) { wp_schedule_event( time() + DAY_IN_SECONDS, 'daily', 'ctc_analytics_cleanup' ); } } /** * Update to version 5.0.0. * * Migrates from legacy settings to new Global Injector. */ private function update_to_5_0_0() { /** * Fires during 5.0.0 update. * * Use this hook to run custom migration logic. * * @since 5.0.0 */ do_action( 'ctc/updater/5.0.0' ); // Migration logic for 5.0.0 can be added here. // For example: migrate legacy CPT settings to new format. } }