Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -1233,14 +1233,14 @@ function delete_option( $option ) {
if ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) {
$alloptions = wp_load_alloptions( true );

if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) {
if ( is_array( $alloptions ) && array_key_exists( $option, $alloptions ) ) {
unset( $alloptions[ $option ] );
wp_cache_set( 'alloptions', $alloptions, 'options' );
}
} else {
wp_cache_delete( $option, 'options' );
}

wp_cache_delete( $option, 'options' );

$notoptions = wp_cache_get( 'notoptions', 'options' );

if ( ! is_array( $notoptions ) ) {
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/tests/option/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,4 +613,28 @@ public function helper_object_cache_stats_cmd_get() {

return $stats['cmd_get'];
}

/**
* Test that delete_option() properly removes options with null values from cache.
*
* @ticket 28701
*
* @covers ::delete_option
*/
public function test_delete_option_with_null_value_in_cache() {
$option_name = 'test_null_cache_' . wp_rand();

add_option( $option_name, 'value', '', true );

$alloptions = wp_load_alloptions();
$alloptions[ $option_name ] = null;
wp_cache_set( 'alloptions', $alloptions, 'options' );

delete_option( $option_name );

$alloptions_after = wp_load_alloptions();
$this->assertArrayNotHasKey( $option_name, $alloptions_after );

$this->assertSame( 'default', get_option( $option_name, 'default' ) );
}
}
Loading