'colormag_default_layout', 'new_key' => 'colormag_default_sidebar_layout', ), array( 'old_key' => 'colormag_default_page_layout', 'new_key' => 'colormag_page_sidebar_layout', ), array( 'old_key' => 'colormag_default_single_posts_layout', 'new_key' => 'colormag_post_sidebar_layout', ), ); foreach ( $sidebar_layout_option as $option ) { $old_value = get_theme_mod( $option['old_key'] ); if ( $old_value ) { if ( 'right_sidebar' === $old_value ) { $new_value = 'right_sidebar'; } elseif ( 'left_sidebar' === $old_value ) { $new_value = 'left_sidebar'; } elseif ( 'no_sidebar_full_width' === $old_value ) { $new_value = 'no_sidebar_full_width'; } elseif ( 'no_sidebar_content_centered' === $old_value ) { $new_value = 'no_sidebar_content_centered'; } else { $new_value = 'right_sidebar'; } set_theme_mod( $option['new_key'], $new_value ); remove_theme_mod( $option['old_key'] ); } } // Set flag to not repeat the migration process, ie, run it only once. update_option( 'colormag_free_major_update_customizer_migration_v1', true ); } /** * Return the value for customize migration on demo import. * * @return bool */ function colormag_demo_import_migration() { if ( isset( $_GET['demo-import-migration'] ) && isset( $_GET['_demo_import_migration_nonce'] ) ) { if ( ! wp_verify_nonce( $_GET['_demo_import_migration_nonce'], 'demo_import_migration' ) ) { wp_die( __( 'Action failed. Please refresh the page and retry.', 'colormag' ) ); } return true; } return false; } /** * @return bool */ public static function maybe_run_migration() { /** * Check migration is already run or not. * If migration is already run then return false. * */ $migrated = get_option( 'colormag_free_major_update_customizer_migration_v1' ); if ( $migrated ) { return false; } /** * If user don't import the demo and upgrade the theme. * Then we need to run the migration. * */ $result = false; $theme_mods = get_theme_mods(); foreach ( $theme_mods as $key => $_ ) { if ( strpos( $key, 'colormag_' ) !== false ) { $result = true; break; } } return $result; } } new ColorMag_Migration(); }