Skip to content

Commit a744b95

Browse files
committed
Store the autoload value update_option() would use on each WordPress version
1 parent 1caa986 commit a744b95

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎features/option.feature‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ Feature: Manage WordPress options
210210
yes
211211
"""
212212
213+
When I run `wp option update hello world --autoload=off`
214+
Then STDOUT should be:
215+
"""
216+
Success: Updated autoload value for 'hello' option.
217+
"""
218+
219+
When I run `wp option get-autoload hello`
220+
Then STDOUT should be:
221+
"""
222+
no
223+
"""
224+
225+
When I run `wp option update hello world --autoload=on`
226+
Then STDOUT should be:
227+
"""
228+
Success: Updated autoload value for 'hello' option.
229+
"""
230+
231+
When I run `wp option get-autoload hello`
232+
Then STDOUT should be:
233+
"""
234+
yes
235+
"""
236+
213237
@require-wp-6.6
214238
Scenario: Update autoload value for custom option with an unchanged value
215239
Given a WP install
@@ -239,6 +263,30 @@ Feature: Manage WordPress options
239263
on
240264
"""
241265
266+
When I run `wp option update hello world --autoload=no`
267+
Then STDOUT should be:
268+
"""
269+
Success: Updated autoload value for 'hello' option.
270+
"""
271+
272+
When I run `wp option get-autoload hello`
273+
Then STDOUT should be:
274+
"""
275+
off
276+
"""
277+
278+
When I run `wp option update hello world --autoload=yes`
279+
Then STDOUT should be:
280+
"""
281+
Success: Updated autoload value for 'hello' option.
282+
"""
283+
284+
When I run `wp option get-autoload hello`
285+
Then STDOUT should be:
286+
"""
287+
on
288+
"""
289+
242290
@require-wp-4.2
243291
@less-than-wp-6.6
244292
Scenario: Managed autoloaded options

‎src/Option_Command.php‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,13 @@ public function update( $args, $assoc_args ) {
455455
if ( $value === $old_value && null === $autoload ) {
456456
WP_CLI::success( "Value passed for '{$key}' option is unchanged." );
457457
} elseif ( $value === $old_value ) {
458+
// Store the value update_option() would: WordPress before 6.6 only autoloads 'yes'.
459+
$autoload_on = in_array( $autoload, [ 'on', 'yes' ], true );
460+
if ( Utils\wp_version_compare( '6.6', '<' ) ) {
461+
$autoload = $autoload_on ? 'yes' : 'no';
462+
} else {
463+
$autoload = $autoload_on ? 'on' : 'off';
464+
}
458465
$this->set_autoload( [ $key, $autoload ] );
459466
// @phpstan-ignore argument.type
460467
} elseif ( update_option( $key, $value, $autoload ) ) {

0 commit comments

Comments
 (0)