From 1c7002ce43f82e0d3cbe24c98a0302271a7b6f81 Mon Sep 17 00:00:00 2001 From: softglazee Date: Sat, 24 Oct 2026 07:30:38 +0500 Subject: [PATCH] Include auto autoload values in option list --autoload filter Since WordPress 6.6, options added without an explicit autoload value are stored as 'auto', 'auto-on' or 'auto-off'. WordPress autoloads 'auto' and 'auto-on' options, but the --autoload filter of wp option list only matched 'on'/'yes' and 'off'/'no', so these options were missing from both lists. Use wp_autoload_values_to_autoload() to decide which values count as autoloaded, like wp_load_alloptions() does. --- features/option-list.feature | 27 +++++++++++++++++++++++++++ src/Option_Command.php | 18 +++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/features/option-list.feature b/features/option-list.feature index 38bd86925..b39da19d5 100644 --- a/features/option-list.feature +++ b/features/option-list.feature @@ -225,3 +225,30 @@ Feature: List WordPress options """ sample_value_four """ + + @require-wp-6.6 + Scenario: Using the `--autoload` flag with the values WordPress picks automatically + Given a WP install + And I run `wp option update sample_auto_option 'sample_value_auto'` + And I run `wp eval 'add_filter( "wp_default_autoload_value", "__return_true" ); add_option( "sample_auto_on_option", "sample_value_auto_on" );'` + And I run `wp eval 'add_filter( "wp_default_autoload_value", "__return_false" ); add_option( "sample_auto_off_option", "sample_value_auto_off" );'` + + When I run `wp option list --search="sample_auto*" --fields=option_name,autoload --orderby=option_name` + Then STDOUT should be a table containing rows: + | option_name | autoload | + | sample_auto_off_option | auto-off | + | sample_auto_on_option | auto-on | + | sample_auto_option | auto | + + When I run `wp option list --autoload=on --search="sample_auto*" --field=option_name --orderby=option_name` + Then STDOUT should be: + """ + sample_auto_on_option + sample_auto_option + """ + + When I run `wp option list --autoload=off --search="sample_auto*" --field=option_name` + Then STDOUT should be: + """ + sample_auto_off_option + """ diff --git a/src/Option_Command.php b/src/Option_Command.php index e4cd076f2..dbdb61ea2 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -168,7 +168,7 @@ public function add( $args, $assoc_args ) { * : Pattern to exclude. Use wildcards ( * and ? ) to match option name. * * [--autoload=] - * : Match only autoload options when value is on, and only not-autoload option when off. + * : Match only autoload options when value is on, and only not-autoload option when off. On WordPress 6.6 and later, options with the `auto` and `auto-on` values count as autoload options. * * [--transients] * : List only transients. Use `--no-transients` to ignore all transients. @@ -293,10 +293,22 @@ public function list_( $args, $assoc_args ) { if ( isset( $assoc_args['autoload'] ) ) { $autoload = $assoc_args['autoload']; + + // Since WordPress 6.6, options set to 'auto' or 'auto-on' are autoloaded too. + $autoload_values = function_exists( 'wp_autoload_values_to_autoload' ) + ? wp_autoload_values_to_autoload() + : [ 'on', 'yes' ]; + if ( 'on' === $autoload || 'yes' === $autoload ) { - $autoload_query = " AND (autoload='on' OR autoload='yes')"; + $autoload_query = $wpdb->prepare( + ' AND autoload IN (' . implode( ', ', array_fill( 0, count( $autoload_values ), '%s' ) ) . ')', + $autoload_values + ); } elseif ( 'off' === $autoload || 'no' === $autoload ) { - $autoload_query = " AND (autoload='off' OR autoload='no')"; + $autoload_query = $wpdb->prepare( + ' AND autoload NOT IN (' . implode( ', ', array_fill( 0, count( $autoload_values ), '%s' ) ) . ')', + $autoload_values + ); } else { WP_CLI::error( "Value of '--autoload' should be 'on', 'off', 'yes', or 'no'." ); }