[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:12:01 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 modernnerd):

 Thanks for the fast reply and for your advice, @jeremyfelt.

 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}
 }}}

 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?

 My goal is to be able to copy code from the block editor and insert it via
 wp_insert_post() during the theme activation process in order to reduce
 theme setup steps.

 The way HTML in block attributes is currently stored as unicode escape
 sequences by WordPress appears to prevent that workflow. (I understand
 that escape sequences are part of the JSON spec and exist to prevent some
 browsers interpreting code as HTML, so it probably needs to be stored the
 way it currently is, but the issue seems to be with decoding that stored
 content for import, rather than encoding it.)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47420#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list