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
30 changes: 30 additions & 0 deletions features/post-meta.feature
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,33 @@ Feature: Manage post custom fields
Then STDOUT should be a table containing rows:
| post_id | meta_key | meta_value |
| 1 | foo | |

Scenario: Make sure WordPress receives the slashed data it expects in meta fields
Given a WP install

When I run `wp post-meta add 1 foo 'My\Meta'`
Then STDOUT should not be empty

When I run `wp post-meta get 1 foo`
Then STDOUT should be:
"""
My\Meta
"""

When I run `wp post-meta update 1 foo 'My\New\Meta'`
Then STDOUT should be:
"""
Success: Updated custom field 'foo'.
"""

When I run the previous command again
Then STDOUT should be:
"""
Success: Value passed for custom field 'foo' is unchanged.
"""

When I run `wp post-meta get 1 foo`
Then STDOUT should be:
"""
My\New\Meta
"""
2 changes: 2 additions & 0 deletions php/WP_CLI/CommandWithMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function add( $args, $assoc_args ) {

$object_id = $this->check_object_id( $object_id );

$meta_value = wp_slash( $meta_value );
$success = add_metadata( $this->meta_type, $object_id, $meta_key, $meta_value );

if ( $success ) {
Expand Down Expand Up @@ -221,6 +222,7 @@ public function update( $args, $assoc_args ) {
if ( $meta_value === $old_value ) {
WP_CLI::success( "Value passed for custom field '$meta_key' is unchanged." );
} else {
$meta_value = wp_slash( $meta_value );
$success = update_metadata( $this->meta_type, $object_id, $meta_key, $meta_value );

if ( $success ) {
Expand Down