WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#25670 closed enhancement (invalid)

update_option() values persist in the database even when no longer exist in the code

Reported by: carlesjove Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.6.1
Component: Database Keywords: 2nd-opinion needs-patch close
Focuses: Cc:
PR Number:

Description

The default WordPress' behaviour is to store the update_option() values to the database. Thus, if an option was once updated it will keep the same value forever, even after the theme author or mantainer removes update_option() from the code. This can lead to difficulties when debugging issues related to options, because even if in the actual code no option's value is being updated, the once set value will still run.

Expected behaviour
Only when an update_option() is passed in the actual code should its value apply. Otherwise, the default value should apply.

Proposed solution(s)
1 - Instead of permanently storing options in the database, only do it as longs as update_option() it's in the code. Otherwise, set the value back to the default.
2 - Set option values only at runtime, without any database storing.

PS: Hope my english is good enough ;-)

Change History (5)

#1 @carlesjove
6 years ago

  • Summary changed from update_option() values persist even when no longer exist in the code to update_option() values persist in the database even when no longer exist in the code

#2 @knutsp
6 years ago

  • Keywords close added

From Codex: "The Options API is a simple and standardized way of storing data in the database."

For temporary storage there is the Transients API.

#3 @mark-k
6 years ago

+1 to close.

There are several problems with the idea

  1. If the option is not in a DB how would you know what is its value when the code that uses it runs
  2. When the option is in the DB you can't know which plugin or theme created it which will make it even harder to guess from the code if it is still being used.
  3. users expect that options continue to exist in the DB if they accidentally deleted the plugin (maybe migrating to new host and haven't set the plugins yet), if options will be deleted automatically this will not work any longer.
  4. It is the responsibility of the plugin and theme authors to provide the functionality to delete the options before the plugin/theme is deleted, or when there is an upgrade and they stop using an option.

#4 @carlesjove
6 years ago

You both have good points. It's ok to close this ticket for me.

#5 @nacin
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.