Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Updating a post with HTML in the content/excerpt is buggy. #1469

@picklepete

Description

@picklepete

I've noticed the following oddity when creating then updating a post with HTML in the post content, using WP-API v2.0.

Step 1

Create a post.

POST /wp-json/wp/v2/posts

{
    "content": "<p>Google.</p><p><img src=\"https://www.google.co.uk/images/srpr/logo11w.png\" /></p>", 
    "status": "publish", 
    "title": "Google", 
    "excerpt": ""
}

Response (truncated for clarity):

{
    "id": 583,
    "...": "...",
    "content": {
        "raw": "<p>Google.</p><p><img src=\"https://www.google.co.uk/images/srpr/logo11w.png\" /></p>",
        "rendered": "<p>Google.</p>\n<p><img src=\"https://www.google.co.uk/images/srpr/logo11w.png\" /></p>\n"
    }
}

So far, so good.

Step 2:

Update the post.

PUT /wp-json/wp/v2/posts/583

{
    "content": "<p>Google's logo.</p><p><img src=\"https://www.google.co.uk/images/srpr/logo11w.png\" /></p>", 
    "status": "publish", 
    "title": "Google's Logo.", 
    "excerpt": ""
}

Response (truncated for clarity):

{
    "id": 583,
    "...": "...",
    "content": {
        "raw": "<p>Google\\'s logo.</p><p><img src=\\\"https://www.google.co.uk/images/srpr/logo11w.png\\\" /></p>",
        "rendered": "<p>Google\\&#8217;s logo.</p>\n<p><img src=\\\"https://www.google.co.uk/images/srpr/logo11w.png\\\" /></p>\n"
    }
}

Step 3:

Look at your post.

Please correct me if I'm wrong, but I think the cause is: wp_update_post calls wp_slash, when we've previously called wp_filter_post_kses here on post_title, post_content and post_excerpt.

I'd love some feedback on this, it's proving to be a blocker for us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions