[wp-trac] [WordPress Trac] #47420: Block markup containing HTML in block attributes is corrupted when using wp_insert_post
WordPress Trac
noreply at wordpress.org
Tue May 28 18:19:50 UTC 2019
#47420: Block markup containing HTML in block attributes is corrupted when using
wp_insert_post
--------------------------+------------------------------
Reporter: modernnerd | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses:
--------------------------+------------------------------
Comment (by jeremyfelt):
Replying to [comment:2 modernnerd]:
> It seems that HTML in block attributes is already encoded by WordPress.
At least, I see content like this stored in the database already as part
of the post content:
>
> {{{
> {"title":"\u003cstrong\u003ePackage
#1\u003c/strong\u003e","fontSize":"larger","paddingTop":30}
> }}}
Exactly. Client side JavaScript in Gutenberg does
[https://github.com/WordPress/gutenberg/blob/774713c0467779a9651983ec96609a6637811132/packages/blocks/src/api/serializer.js#L172-L195
some additional work] beyond `JSON.stringify()` to encode the data before
it is sent to the server for storage.
> Are you suggesting that these attributes need to be handled differently
by the block developer, or that anyone wanting to import such content via
wp_insert_post() needs to somehow first decode block attributes that could
contain HTML?
Anything processed in PHP should effectively mimic what is done in
JavaScript. So - if the block developer is encoding on the client side,
they can use Gutenberg's `serializeAttributes()` (or something like it).
But if they're encoding on the server side, they'll likely need to pass
additional flags to `wp_json_encode()` so that those additional characters
are encoded properly.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47420#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list