Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,9 @@ wp option list [--search=<pattern>] [--exclude=<pattern>] [--autoload=<value>] [
[--transients]
List only transients. Use `--no-transients` to ignore all transients.

[--unserialize]
Unserialize option values in output.

[--field=<field>]
Prints the value of a single field.

Expand Down
13 changes: 13 additions & 0 deletions features/option-list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
11 changes: 11 additions & 0 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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=<field>]
* : Prints the value of a single field.
*
Expand Down Expand Up @@ -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 {
Expand Down