Skip to content
Closed
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
9 changes: 9 additions & 0 deletions features/option.feature
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ Feature: Manage WordPress options
[1,2]
"""

# Raw values
When I run `wp option set raw_option '[ 1, 2 ]' --format=json`
Then STDOUT should not be empty

When I run `wp option get raw_option --format=raw`
Then STDOUT should be:
"""
a:2:{i:0;i:1;i:1;i:2;}
"""

# Reading from files
Given a value.json file:
Expand Down
11 changes: 11 additions & 0 deletions src/Option_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Option_Command extends WP_CLI_Command {
* - var_export
* - json
* - yaml
* - raw
* ---
*
* ## EXAMPLES
Expand Down Expand Up @@ -80,6 +81,16 @@ public function get( $args, $assoc_args ) {
WP_CLI::error( "Could not get '{$key}' option. Does it exist?" );
}

if ( 'raw' === Utils\get_flag_value( $assoc_args, 'format' ) ) {
global $wpdb;
$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT option_value FROM $wpdb->options WHERE option_name = %s",
$key
)
);
}

WP_CLI::print_value( $value, $assoc_args );
}

Expand Down