Skip to content

Commit 346446f

Browse files
authored
Fix option list filtering with autoload and transients (#620)
1 parent 91fe708 commit 346446f

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

features/option-list.feature

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ Feature: List WordPress options
3333
siteurl
3434
"""
3535

36+
@skip-object-cache
37+
Scenario: Using the `--autoload=on` flag excludes transients by default
38+
Given a WP install
39+
And I run `wp option add sample_autoload_option 'sample_autoload_option' --autoload=yes`
40+
And I run `wp transient set sample_autoload_transient 'sample_autoload_transient'`
41+
42+
When I run `wp option list --autoload=on`
43+
Then STDOUT should contain:
44+
"""
45+
sample_autoload_option
46+
"""
47+
And STDOUT should not contain:
48+
"""
49+
sample_autoload_transient
50+
"""
51+
52+
When I run `wp option list --transients --autoload=on`
53+
Then STDOUT should contain:
54+
"""
55+
sample_autoload_transient
56+
"""
57+
And STDOUT should not contain:
58+
"""
59+
sample_autoload_option
60+
"""
61+
3662
Scenario: List option with exclude pattern
3763
Given a WP install
3864

@@ -198,4 +224,4 @@ Feature: List WordPress options
198224
And STDOUT should contain:
199225
"""
200226
sample_value_four
201-
"""
227+
"""

src/Option_Command.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ public function list_( $args, $assoc_args ) {
294294
if ( isset( $assoc_args['autoload'] ) ) {
295295
$autoload = $assoc_args['autoload'];
296296
if ( 'on' === $autoload || 'yes' === $autoload ) {
297-
$autoload_query = " AND (autoload='on') OR (autoload='yes')";
297+
$autoload_query = " AND (autoload='on' OR autoload='yes')";
298298
} elseif ( 'off' === $autoload || 'no' === $autoload ) {
299-
$autoload_query = " AND (autoload='off') OR (autoload='no')";
299+
$autoload_query = " AND (autoload='off' OR autoload='no')";
300300
} else {
301301
WP_CLI::error( "Value of '--autoload' should be 'on', 'off', 'yes', or 'no'." );
302302
}
@@ -306,11 +306,11 @@ public function list_( $args, $assoc_args ) {
306306
$show_transients = Utils\get_flag_value( $assoc_args, 'transients', false );
307307

308308
if ( $show_transients ) {
309-
$transients_query = " AND option_name LIKE '\_transient\_%'
310-
OR option_name LIKE '\_site\_transient\_%'";
309+
$transients_query = " AND (option_name LIKE '\_transient\_%'
310+
OR option_name LIKE '\_site\_transient\_%')";
311311
} else {
312-
$transients_query = " AND option_name NOT LIKE '\_transient\_%'
313-
AND option_name NOT LIKE '\_site\_transient\_%'";
312+
$transients_query = " AND (option_name NOT LIKE '\_transient\_%'
313+
AND option_name NOT LIKE '\_site\_transient\_%')";
314314
}
315315

316316
$where = '';

0 commit comments

Comments
 (0)