From a093791ecc1e0f25282d0c1d28b2055e8ebfeefd Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 22 Sep 2018 07:54:39 -0400 Subject: [PATCH] Properly get the previous version on plugin activate --- inc/migrations.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/inc/migrations.php b/inc/migrations.php index ecea4ee..18c8a71 100644 --- a/inc/migrations.php +++ b/inc/migrations.php @@ -4,16 +4,19 @@ Poor man's migration system */ namespace migrations; -$previous_version = get_option( 'pterotype_previously_migrated_version' ); -if ( !$previous_version ) { - $previous_version = '0.0.0'; +function get_previous_version() { + $previous_version = get_option( 'pterotype_previously_migrated_version' ); + if ( !$previous_version ) { + $previous_version = '0.0.0'; + } + return $previous_version; } /* It's okay to add new queries to this function, but don't ever delete queries. */ function run_migrations() { - global $previous_version; + $previous_version = get_previous_version(); if ( version_compare( $previous_version, PTEROTYPE_VERSION, '>=' ) ) { return; } @@ -23,7 +26,7 @@ function run_migrations() { } function apply_migration( $version, $migration_func ) { - global $previous_version; + $previous_version = get_previous_version(); if ( version_compare( $previous_version, $version, '<' ) ) { call_user_func( __NAMESPACE__ . '\\' . $migration_func ); }