{"id":15351550,"date":"2022-02-10T15:40:41","date_gmt":"2022-02-10T15:40:41","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/re-enabling-plugin-reverts-options-to-defaults\/"},"modified":"2022-02-10T15:40:41","modified_gmt":"2022-02-10T15:40:41","slug":"re-enabling-plugin-reverts-options-to-defaults","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/re-enabling-plugin-reverts-options-to-defaults\/","title":{"rendered":"Re-enabling plugin reverts options to defaults"},"content":{"rendered":"<p>If you deactivate then re-activate the plugin, the options reset to defaults.<\/p>\n<p>In the <code>set_default_values()<\/code> method in the activation hook I see:<br \/>\n<code>update_option(&#039;ip2location_redirection_api_key&#039;, &#039;&#039;);<\/code> which will always update the value if it has already been added.<\/p>\n<p>Is there a reason to not set default values with <code>add_option()<\/code> instead?  This way existing options\/settings will not be updated. Like:<\/p>\n<pre><code>if (!get_option(&#039;ip2location_redirection_api_key&#039;)) {\n  add_option(&#039;ip2location_redirection_api_key&#039;, &#039;&#039;);\n}<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-15351550","topic","type-topic","status-publish","hentry","topic-tag-initialization"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15351550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/15351550\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=15351550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}