-
Couldn't load subscription status.
- Fork 95
Description
I've just been tripped up by the way that WP-CLI represents serialized data stored in meta data as JSON encoded, and the fact that the behaviour when displaying meta data differs from that when displaying option values.
Scenario: Two post meta fields, one storing its data as a JSON-encoded string and one storing its data using the WordPress-native serialisation:
$value = [ 1, 2, 3 ];
add_post_meta( $id, 'json', wp_json_encode( $value ) );
add_post_meta( $id, 'raw', $value );When listing the post meta for this post, WP-CLI incorrectly represents both values as JSON-encoded:
wp post meta list <id>
+----------+------------+
| meta_key | meta_value |
+----------+------------+
| json | [1,2,3] |
| raw | [1,2,3] |
+----------+------------+
When doing the same with options instead of post meta, the serialised value is correctly represented when listed:
wp option list
+-------------+--------------------------------+
| option_name | option_value |
+-------------+--------------------------------+
| json | [1,2,3] |
| raw | a:3:{i:0;i:1;i:1;i:2;i:2;i:3;} |
+-------------+--------------------------------+
This means that when using the list command it's not possible to determine whether a meta value is actually stored serialised or JSON encoded. When doing the same for option values, it is.
IMO I think the representation of meta values should be brought inline with that of option values.