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\\’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.
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.
{ "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.
{ "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\\’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_kseshere onpost_title,post_contentandpost_excerpt.I'd love some feedback on this, it's proving to be a blocker for us.