Skip to content

Commit 8bdd517

Browse files
committed
Support new autoload options
Fixes #491 See: https://core.trac.wordpress.org/changeset/57920
1 parent e72ba04 commit 8bdd517

File tree

4 files changed

+91
-10
lines changed

4 files changed

+91
-10
lines changed

features/option-get-autoload.feature

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feature: Get 'autoload' value for an option
88
"""
99
Error: Could not get 'foo' option. Does it exist?
1010
"""
11-
11+
@less-than-wp-6.6
1212
Scenario: Displays 'autoload' value
1313
Given a WP install
1414

@@ -23,3 +23,18 @@ Feature: Get 'autoload' value for an option
2323
"""
2424
yes
2525
"""
26+
@require-wp-6.6
27+
Scenario: Displays 'autoload' value
28+
Given a WP install
29+
30+
When I run `wp option add foo bar`
31+
Then STDOUT should contain:
32+
"""
33+
Success:
34+
"""
35+
36+
When I run `wp option get-autoload foo`
37+
Then STDOUT should be:
38+
"""
39+
on
40+
"""

features/option-set-autoload.feature

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Feature: Set 'autoload' value for an option
2424
Error: Invalid value specified for positional arg.
2525
"""
2626

27+
@less-than-wp-6.6
2728
Scenario: Successfully updates autoload value
2829
Given a WP install
2930

@@ -56,3 +57,37 @@ Feature: Set 'autoload' value for an option
5657
"""
5758
no
5859
"""
60+
61+
@require-wp-6.6
62+
Scenario: Successfully updates autoload value
63+
Given a WP install
64+
65+
When I run `wp option add foo bar`
66+
Then STDOUT should contain:
67+
"""
68+
Success:
69+
"""
70+
71+
When I run `wp option get-autoload foo`
72+
Then STDOUT should be:
73+
"""
74+
on
75+
"""
76+
77+
When I run `wp option set-autoload foo off`
78+
Then STDOUT should be:
79+
"""
80+
Success: Updated autoload value for 'foo' option.
81+
"""
82+
83+
When I run the previous command again
84+
Then STDOUT should be:
85+
"""
86+
Success: Autoload value passed for 'foo' option is unchanged.
87+
"""
88+
89+
When I run `wp option get-autoload foo`
90+
Then STDOUT should be:
91+
"""
92+
off
93+
"""

features/option.feature

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ Feature: Manage WordPress options
140140
"""
141141
142142
@require-wp-4.2
143+
@less-than-wp-6.6
143144
Scenario: Update autoload value for custom option
144145
Given a WP install
145146
And I run `wp option add hello world --autoload=no`
@@ -160,7 +161,30 @@ Feature: Manage WordPress options
160161
| option_name | option_value | autoload |
161162
| hello | island | yes |
162163
164+
@require-wp-6.6
165+
Scenario: Update autoload value for custom option
166+
Given a WP install
167+
And I run `wp option add hello world --autoload=off`
168+
169+
When I run `wp option update hello universe`
170+
Then STDOUT should not be empty
171+
172+
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
173+
Then STDOUT should be a table containing rows:
174+
| option_name | option_value | autoload |
175+
| hello | universe | off |
176+
177+
When I run `wp option update hello island --autoload=on`
178+
Then STDOUT should not be empty
179+
180+
When I run `wp option list --search='hello' --fields=option_name,option_value,autoload`
181+
Then STDOUT should be a table containing rows:
182+
| option_name | option_value | autoload |
183+
| hello | island | on |
184+
185+
163186
@require-wp-4.2
187+
@less-than-wp-6.6
164188
Scenario: Managed autoloaded options
165189
Given a WP install
166190
@@ -248,11 +272,11 @@ Feature: Manage WordPress options
248272
"""
249273
And the return code should be 0
250274
251-
When I try `wp option list --search='auto_opt' --autoload=no`
275+
When I try `wp option list --search='auto_opt' --autoload=nope`
252276
Then STDOUT should be empty
253-
And STDERR should be:
277+
And STDERR should contain:
254278
"""
255-
Error: Value of '--autoload' should be on or off.
279+
Error: Value of '--autoload' should be
256280
"""
257281
And the return code should be 1
258282
@@ -264,7 +288,7 @@ Feature: Manage WordPress options
264288
"""
265289
And the return code should be 0
266290
267-
When I try `wp option add str_opt_foo 'bar' --autoload=off`
291+
When I try `wp option add str_opt_foo 'bar' --autoload=bad`
268292
Then STDOUT should be empty
269293
And STDERR should contain:
270294
"""

src/Option_Command.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public function get( $args, $assoc_args ) {
109109
* : Should this option be automatically loaded.
110110
* ---
111111
* options:
112+
* - 'on'
113+
* - 'off'
112114
* - 'yes'
113115
* - 'no'
114116
* ---
@@ -125,7 +127,7 @@ public function add( $args, $assoc_args ) {
125127
$value = WP_CLI::get_value_from_arg_or_stdin( $args, 1 );
126128
$value = WP_CLI::read_value( $value, $assoc_args );
127129

128-
if ( Utils\get_flag_value( $assoc_args, 'autoload' ) === 'no' ) {
130+
if ( in_array( Utils\get_flag_value( $assoc_args, 'autoload' ), [ 'no', 'off' ], true ) ) {
129131
$autoload = 'no';
130132
} else {
131133
$autoload = 'yes';
@@ -271,12 +273,13 @@ public function list_( $args, $assoc_args ) {
271273
}
272274

273275
if ( isset( $assoc_args['autoload'] ) ) {
274-
if ( 'on' === $assoc_args['autoload'] ) {
276+
$autoload = $assoc_args['autoload'];
277+
if ( 'on' === $autoload || 'yes' === $autoload ) {
275278
$autoload_query = " AND autoload='yes'";
276-
} elseif ( 'off' === $assoc_args['autoload'] ) {
279+
} elseif ( 'off' === $autoload || 'no' === $autoload ) {
277280
$autoload_query = " AND autoload='no'";
278281
} else {
279-
WP_CLI::error( "Value of '--autoload' should be on or off." );
282+
WP_CLI::error( "Value of '--autoload' should be 'on', 'off', 'yes', or 'no'." );
280283
}
281284
}
282285

@@ -360,6 +363,8 @@ function ( $a, $b ) use ( $orderby, $order ) {
360363
* : Requires WP 4.2. Should this option be automatically loaded.
361364
* ---
362365
* options:
366+
* - 'on'
367+
* - 'off'
363368
* - 'yes'
364369
* - 'no'
365370
* ---
@@ -413,7 +418,7 @@ public function update( $args, $assoc_args ) {
413418
$value = WP_CLI::read_value( $value, $assoc_args );
414419

415420
$autoload = Utils\get_flag_value( $assoc_args, 'autoload' );
416-
if ( ! in_array( $autoload, [ 'yes', 'no' ], true ) ) {
421+
if ( ! in_array( $autoload, [ 'on', 'off', 'yes', 'no' ], true ) ) {
417422
$autoload = null;
418423
}
419424

@@ -479,6 +484,8 @@ public function get_autoload( $args ) {
479484
* : Should this option be automatically loaded.
480485
* ---
481486
* options:
487+
* - 'on'
488+
* - 'off'
482489
* - 'yes'
483490
* - 'no'
484491
* ---

0 commit comments

Comments
 (0)