diff --git a/README.md b/README.md index 58d6846bc..da8b6db19 100644 --- a/README.md +++ b/README.md @@ -1719,6 +1719,9 @@ wp option list [--search=] [--exclude=] [--autoload=] [ [--transients] List only transients. Use `--no-transients` to ignore all transients. + [--unserialize] + Unserialize option values in output. + [--field=] Prints the value of a single field. diff --git a/features/option-list.feature b/features/option-list.feature index fd0d11129..539352f7a 100644 --- a/features/option-list.feature +++ b/features/option-list.feature @@ -135,3 +135,16 @@ Feature: List WordPress options siteurl """ + Scenario: Using the `--unserialize` flag + Given a WP install + + When I run `wp option add --format=json sample_test_field_one '{"value": 1}'` + And I run `wp option list --search="sample_test_field_*" --format=yaml --unserialize` + Then STDOUT should be: + """ + --- + - + option_name: sample_test_field_one + option_value: + value: 1 + """ diff --git a/src/Option_Command.php b/src/Option_Command.php index 42aca0ffb..c013b8c13 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -154,6 +154,9 @@ public function add( $args, $assoc_args ) { * [--transients] * : List only transients. Use `--no-transients` to ignore all transients. * + * [--unserialize] + * : Unserialize option values in output. + * * [--field=] * : Prints the value of a single field. * @@ -317,6 +320,14 @@ public function list_( $args, $assoc_args ) { krsort( $results ); } + if ( true === Utils\get_flag_value( $assoc_args, 'unserialize', null ) ) { + foreach ( $results as $k => &$v ) { + if ( ! empty( $v->option_value ) ) { + $v->option_value = maybe_unserialize( $v->option_value ); + } + } + } + if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'format' ) === 'total_bytes' ) { WP_CLI::line( $results[0]->size_bytes ); } else {