WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#32848 new defect (bug)

Null values for Update Options does not reset in $all_options

Reported by: MikeNGarrett Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.2.2
Component: Cache API Keywords: has-patch needs-unit-tests
Focuses: performance Cc:

Description

This is a fun, extremely niche case.

We were using the Settings API to save out options for a plugin when we came across a really frustrating scenario. Half the time our setting was returning values that were not accurate to the setting that was stored in the database and in cache.

Come to find, the value being returned from wp_load_alloptions was incorrect while every other instance was correct. In our case, these values were in the database, memcache, and the single value in wp-object-cache.

On line 319 of option.php, we're using isset to check the value in the array. This returns false if the value is NULL. This leads to all kinds of sadness.

I would propose we instead use array_key_exists here to ensure we're getting true if the key is present in the array at all.

Attachments (2)

32848.diff (510 bytes) - added by MikeNGarrett 2 years ago.
Patch #1
32848.2.diff (5.1 KB) - added by MikeNGarrett 2 years ago.
Patch 2 - replace all isset in option.php

Download all attachments as: .zip

Change History (5)

@MikeNGarrett
2 years ago

Patch #1

This ticket was mentioned in Slack in #core by mikengarrett. View the logs.


2 years ago

#2 @MikeNGarrett
2 years ago

Co-contributor: @tndavide, @jipmoors

Last edited 2 years ago by MikeNGarrett (previous) (diff)

#3 @MikeNGarrett
2 years ago

  • Keywords has-patch needs-unit-tests added

I ran back through and realized there were quite a few places here that are using isset for assessing array keys existence. Here's a patch to switch all isset to array_key_exists. Next step, let's create some unit tests.

@MikeNGarrett
2 years ago

Patch 2 - replace all isset in option.php

Note: See TracTickets for help on using tickets.