Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent backslashes from being stripped on post insertion #172

Closed
wants to merge 1 commit into from

Conversation

gtuser10
Copy link

@gtuser10 gtuser10 commented Jul 3, 2020

In content created with Gutenberg editor, some characters (used in block attribute) are encoded into unicode character codes that start with a backslash, e.g.

<!-- wp:plugin/custom-block {"data":"Some text and \u003ca href=\u0022https://example.com/\u0022\u003esome-link\u003c/a\u003e."} /-->

Before inserting into database, wp_insert_post() function runs the post object through wp_unslash() function which strips all backslashes. This breaks unicode character codes (and content). To mitigate that, we should run the post object through wp_slash() functions before passing it to wp_insert_post(). The original WordPress Importer does this.

In content created with Gutenberg editor, some characters (used in block attribute) are encoded into unicode character codes that start with a backslash, e.g.
```
<!-- wp:plugin/custom-block {"data":"Some text and \u003ca href=\u0022https://example.com/\u0022\u003esome-link\u003c/a\u003e."} /-->
```
Before inserting into database, `wp_insert_post()` function runs the post object through `wp_unslash()` function which strips all backslashes. This breaks unicode character codes (and content). To mitigate that, we should run the post object through `wp_slash()` functions before passing it to `wp_insert_post()`. The original WordPress Importer does this.
@JiveDig
Copy link

JiveDig commented Apr 20, 2021

I've been having failing imports on some themes lately and finally tracked it down to this same issue. I can confirm that adding the following fixed it for me.

add_filter( 'wp_import_post_data_processed', function( $postdata, $data ) {
	return wp_slash( $postdata );
});

@JiveDig
Copy link

JiveDig commented Apr 20, 2021

Actually, this seems to be a duplicate of #161

@rmccue
Copy link
Member

rmccue commented Mar 4, 2023

Thanks! Closing in favour of #174 for a best practice approach.

@rmccue rmccue closed this Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants