/** * @static * @return EasyRecipeSettings */ static function getInstance() { $freeSettings = null; $updateOptions = false; /** * If we haven't already instantiated settings, try to do it from the options */ if (!self::$instance) { self::$instance = get_option('EasyRecipe', false); if (!self::$instance) { self::$instance = new EasyRecipeSettings(); /** * If we're updating from a very early version, copy the old settings which are still relevant * Any not set in the defaults are deprecated and we can drop them */ $v31Settings = get_option('ERSettings'); if (!empty($v31Settings)) { foreach ($v31Settings as $setting => $value) { if (isset(self::$defaultSettings[$setting])) { self::$instance->{$setting} = $value; } } $updateOptions = true; } } /** * Fixup possible legacy problems where the options weren't stored as the correct class */ if (!self::$instance instanceof EasyRecipeSettings) { self::$instance = new EasyRecipeSettings(self::$instance); $updateOptions = true; } /** * If this is the first run of the plugin after an update, see if we need to do any processing specific to this update. * Also do the update check if the taxonomies haven't been created yet * * TODO - determine if this is a new install - won't need to check if so? */ $updateCheck = version_compare(self::$instance->settingsVersion, EasyRecipe::$pluginVersion) == -1 || !self::$instance->taxonomiesCreated; if ($updateCheck) { EasyRecipeUpdate::check(self::$instance); /** * Save the new settings version (will be the same as the installed pluginVersion) */ self::$instance->settingsVersion = EasyRecipe::$pluginVersion; $updateOptions = true; } /** * Set any defaults which haven't been set in the current version (i.e. new settings just introduced) * TODO - remove any options no longer needed? */ foreach (self::$defaultSettings as $setting => $default) { if (!isset(self::$instance->{$setting})) { self::$instance->{$setting} = $default; $updateOptions = true; } } /** * Update the settings if we changed them during construction */ if ($updateOptions) { update_option('EasyRecipe', self::$instance); } } return self::$instance; }