diff --git a/features/option.feature b/features/option.feature index ec731280..6fd54c10 100644 --- a/features/option.feature +++ b/features/option.feature @@ -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: diff --git a/src/Option_Command.php b/src/Option_Command.php index 34310af0..b57b339e 100644 --- a/src/Option_Command.php +++ b/src/Option_Command.php @@ -47,6 +47,7 @@ class Option_Command extends WP_CLI_Command { * - var_export * - json * - yaml + * - raw * --- * * ## EXAMPLES @@ -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 ); }