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
18 changes: 18 additions & 0 deletions features/option-set-autoload.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,21 @@ Feature: Set 'autoload' value for an option
"""
off
"""

@require-wp-6.6
Scenario: Updates the cached alloptions in the same request
Given a WP install
And I run `wp option add foo bar --autoload=on`
And I run `wp option add baz qux --autoload=off`

When I run `wp eval 'wp_load_alloptions(); WP_CLI::runcommand( "option set-autoload foo off", array( "launch" => false ) ); var_dump( array_key_exists( "foo", wp_load_alloptions() ) );'`
Then STDOUT should contain:
"""
bool(false)
"""

When I run `wp eval 'wp_load_alloptions(); get_option( "baz" ); WP_CLI::runcommand( "option set-autoload baz on", array( "launch" => false ) ); var_dump( array_key_exists( "baz", wp_load_alloptions() ) );'`
Then STDOUT should contain:
"""
bool(true)
"""
14 changes: 9 additions & 5 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,17 @@ public function set_autoload( $args ) {
wp_cache_set( 'notoptions', $notoptions, 'options' );
}

// Refresh the 'alloptions' cache like wp_set_option_autoload_values().
if ( ! defined( 'WP_INSTALLING' ) ) {
$alloptions = wp_load_alloptions( true );
if ( isset( $alloptions[ $option ] ) ) {
$alloptions[ $option ] = $previous->option_value;
wp_cache_set( 'alloptions', $alloptions, 'options' );
if ( in_array( $autoload, array( 'on', 'yes' ), true ) ) {
wp_cache_delete( $option, 'options' );
wp_cache_delete( 'alloptions', 'options' );
} else {
wp_cache_set( $option, $previous->option_value, 'options' );
$alloptions = wp_load_alloptions( true );
if ( isset( $alloptions[ $option ] ) ) {
unset( $alloptions[ $option ] );
wp_cache_set( 'alloptions', $alloptions, 'options' );
}
}
}

Expand Down
Loading