Skip to content

Commit 899fb2c

Browse files
dhruposwissspidy
andauthored
Update autoload in wp option update when the value is unchanged (#689)
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
1 parent a5bcc96 commit 899fb2c

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

‎features/option.feature‎

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,112 @@ Feature: Manage WordPress options
180180
| option_name | option_value | autoload |
181181
| hello | island | on |
182182
183+
@less-than-wp-6.6
184+
Scenario: Update autoload value for custom option with an unchanged value
185+
Given a WP install
186+
And I run `wp option add hello world --autoload=yes`
187+
188+
When I run `wp option update hello world --autoload=no`
189+
Then STDOUT should be:
190+
"""
191+
Success: Updated autoload value for 'hello' option.
192+
"""
193+
194+
When I run `wp option get-autoload hello`
195+
Then STDOUT should be:
196+
"""
197+
no
198+
"""
199+
200+
When I run `wp option update hello world --autoload=yes`
201+
Then STDOUT should be:
202+
"""
203+
Success: Updated autoload value for 'hello' option.
204+
"""
205+
206+
When I run `wp option get-autoload hello`
207+
Then STDOUT should be:
208+
"""
209+
yes
210+
"""
211+
212+
When I run `wp option update hello world --autoload=off`
213+
Then STDOUT should be:
214+
"""
215+
Success: Updated autoload value for 'hello' option.
216+
"""
217+
218+
When I run `wp option get-autoload hello`
219+
Then STDOUT should be:
220+
"""
221+
no
222+
"""
223+
224+
When I run `wp option update hello world --autoload=on`
225+
Then STDOUT should be:
226+
"""
227+
Success: Updated autoload value for 'hello' option.
228+
"""
229+
230+
When I run `wp option get-autoload hello`
231+
Then STDOUT should be:
232+
"""
233+
yes
234+
"""
235+
236+
@require-wp-6.6
237+
Scenario: Update autoload value for custom option with an unchanged value
238+
Given a WP install
239+
And I run `wp option add hello world --autoload=on`
240+
241+
When I run `wp option update hello world --autoload=off`
242+
Then STDOUT should be:
243+
"""
244+
Success: Updated autoload value for 'hello' option.
245+
"""
246+
247+
When I run `wp option get-autoload hello`
248+
Then STDOUT should be:
249+
"""
250+
off
251+
"""
252+
253+
When I run `wp option update hello world --autoload=on`
254+
Then STDOUT should be:
255+
"""
256+
Success: Updated autoload value for 'hello' option.
257+
"""
258+
259+
When I run `wp option get-autoload hello`
260+
Then STDOUT should be:
261+
"""
262+
on
263+
"""
264+
265+
When I run `wp option update hello world --autoload=no`
266+
Then STDOUT should be:
267+
"""
268+
Success: Updated autoload value for 'hello' option.
269+
"""
270+
271+
When I run `wp option get-autoload hello`
272+
Then STDOUT should be:
273+
"""
274+
off
275+
"""
276+
277+
When I run `wp option update hello world --autoload=yes`
278+
Then STDOUT should be:
279+
"""
280+
Success: Updated autoload value for 'hello' option.
281+
"""
282+
283+
When I run `wp option get-autoload hello`
284+
Then STDOUT should be:
285+
"""
286+
on
287+
"""
288+
183289
@require-wp-4.2
184290
@less-than-wp-6.6
185291
Scenario: Managed autoloaded options

‎src/Option_Command.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ public function update( $args, $assoc_args ) {
466466

467467
if ( $value === $old_value && null === $autoload ) {
468468
WP_CLI::success( "Value passed for '{$key}' option is unchanged." );
469+
} elseif ( $value === $old_value ) {
470+
// Store the value update_option() would: WordPress before 6.6 only autoloads 'yes'.
471+
$autoload_on = in_array( $autoload, [ 'on', 'yes' ], true );
472+
if ( Utils\wp_version_compare( '6.6', '<' ) ) {
473+
$autoload = $autoload_on ? 'yes' : 'no';
474+
} else {
475+
$autoload = $autoload_on ? 'on' : 'off';
476+
}
477+
$this->set_autoload( [ $key, $autoload ] );
469478
// @phpstan-ignore argument.type
470479
} elseif ( update_option( $key, $value, $autoload ) ) {
471480
WP_CLI::success( "Updated '{$key}' option." );

0 commit comments

Comments
 (0)