/** * Checks if the plugin has been updated and performs any necessary updates. */ function check_plugin_update() { $oldVersion = $this->plugin_version_changed(); if (false === $oldVersion) { return; } $newVersion = TP_PLUGIN_VERSION(); // On any version, update defaults that didn't previously exist $newPreferences = array_merge(TP_PREFERENCES_OPTIONS_DEFAULTS(), get_option(TP_PREFERENCES_OPTIONS_KEY, array())); $newPreferences['plugin_version'] = TP_PLUGIN_VERSION; update_option(TP_PREFERENCES_OPTIONS_KEY, $newPreferences); update_option(TP_ACCOUNT_OPTIONS_KEY, array_merge(TP_ACCOUNT_OPTIONS_DEFAULTS(), get_option(TP_ACCOUNT_OPTIONS_KEY, array()))); update_option(TP_BASIC_METADATA_OPTIONS_KEY, array_merge(TP_BASIC_METADATA_OPTIONS_DEFAULTS(), get_option(TP_BASIC_METADATA_OPTIONS_KEY, array()))); // We had a messy update with 1.2.2/1.3.0, let's clean up if ($oldVersion['major'] == '1' && $oldVersion['minor'] == '2' && $oldVersion['patch'] == '2' || $oldVersion['major'] == '1' && $oldVersion['minor'] == '3' && $oldVersion['patch'] == '0') { $basicMetadataFields = get_option(TP_BASIC_METADATA_OPTIONS_KEY, array()); $customMetadataFields = get_option(TP_CUSTOM_METADATA_OPTIONS_KEY, array()); update_option(TP_BASIC_METADATA_OPTIONS_KEY, array_diff_assoc($basicMetadataFields, $customMetadataFields)); } // Move account settings from preferences (1.2.0) if ($oldVersion['major'] == '1' && $oldVersion['minor'] < '2' && ($newVersion['major'] > '1' || $newVersion['major'] >= '1' && $newVersion['minor'] >= '2')) { $preferences = get_option(TP_PREFERENCES_OPTIONS_KEY, array()); if (array_key_exists('mpx_account_id', $preferences)) { $accountSettings = TP_ACCOUNT_OPTIONS_DEFAULTS(); foreach ($preferences as $key => $value) { if (array_key_exists($key, $accountSettings)) { $accountSettings[$key] = $preferences[$key]; } } update_option(TP_ACCOUNT_OPTIONS_KEY, $accountSettings); } } }
function register_basic_metadata_options() { if (!$this->account_is_verified || !$this->region_is_verified) { return; } $this->plugin_settings_tabs[TP_BASIC_METADATA_OPTIONS_KEY] = 'Basic Metadata'; $basic_fields = TP_BASIC_METADATA_OPTIONS_DEFAULTS(); add_settings_section('section_upload_options', 'Basic Metadata Settings', array($this, 'section_basic_metadata_desc'), TP_BASIC_METADATA_OPTIONS_KEY); foreach ($basic_fields as $field => $value) { if (!array_key_exists($field, $this->upload_options)) { $this->upload_options[$field] = 'write'; } $field_title = strstr($field, '$') !== false ? substr(strstr($field, '$'), 1) : $field; add_settings_field($field, esc_html(ucfirst($field_title)), array($this, 'field_basic_metadata_option'), TP_BASIC_METADATA_OPTIONS_KEY, 'section_upload_options', array('field' => $field)); } }