Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#18478 closed defect (bug) (fixed)

*_site_option() should use get_site_option for caching and filtering

Reported by: duck_ Owned by: duck_
Milestone: 3.3 Priority: normal
Severity: normal Version: 3.0
Component: General Keywords: has-patch needs-testing
Focuses: Cc:


Currently add_site_option() and update_site_option() perform direct SQL queries instead of using the API. This means that we lose out on caching and the ability to filter the results.

However, I'm not sure on the caching part as it was specifically stopped in MU during the merging in of get_site_option with the $use_cache argument from WP. Does anyone know why this was? The call to get_site_option() was then switched to a direct query to stop infinite loops though this should no longer be a problem due to the use of get_row() in get_site_option(). I believe that missing out on filtering of DB results is enough to get this patch in anyway.

update_site_option() on already calls get_site_option() before the direct query. The attached patch moves this code block above the !is_multisite() check, so this means that on singlesite there is a change to the filters applied. Calling update_site_option() on a non-existant option will apply pre_add_site_option_$option instead of pre_update_option_$option. I can easily move the code back down if this is undesirable.

Patch attached also adds the standard if ( $result ) { code to add_site_option() so that filters are only run on success.

Related: #18422, #15497

Attachments (1)

18478.diff (1.8 KB) - added by duck_ 7 years ago.

Download all attachments as: .zip

Change History (4)

7 years ago

#1 @ryan
7 years ago

Looks good to me.

#2 @ryan
7 years ago

  • Milestone changed from Awaiting Review to 3.3

#3 @duck_
7 years ago

  • Owner set to duck_
  • Resolution set to fixed
  • Status changed from new to closed

In [18588]:

Use get_site_option in add/update_site_option for caching and filtering benefits. fixes #18478

Note: See TracTickets for help on using tickets.