[wp-trac] [WordPress Trac] #23905: Add_post_meta strips slashes
WordPress Trac
noreply at wordpress.org
Sat Mar 30 00:20:30 UTC 2013
#23905: Add_post_meta strips slashes
-----------------------------+--------------------------
Reporter: Looimaster | Type: defect (bug)
Status: new | Priority: normal
Milestone: Awaiting Review | Component: General
Version: 3.5.1 | Severity: normal
Keywords: |
-----------------------------+--------------------------
Let's assume that JS generated an object that I want to store in custom
field. Everything goes smooth when I convert it back and forth from JS to
PHP and from PHP to JS (using json_encode() and json_decode()) and it even
works when I do update_post_meta() manually in my file but this stops
working as soon as WordPress Importer tries to load it from XML file (in
XML it's still valid object) using add_post_meta().
This is the code from importer from the bottom of process_posts()
function:
{{{
if ( $key ) {
// export gets meta straight from the DB so could have a
serialized string
if ( ! $value )
$value = maybe_unserialize( $meta['value'] );
$value =
'{"0":{"type":"text","text":""},"1":{"type":"html","html":"<div
class=\"cssclass\" style=\"margin-top: 3em;\"><p>here goes
html</p></div>","css_class":""}}'; // I added this for test purposes
add_post_meta( $post_id, $key, $value );
do_action( 'import_post_meta', $post_id, $key, $value );
}}}
This is an object:
{{{
{"0":{"type":"text","text":""},"1":{"type":"html","html":"<div
class=\"cssclass\" style=\"margin-top: 3em;\"><p>here goes
html</p></div>","css_class":""}}
}}}
It strips slashes from HTML tags (before each double quote sign) from
objects that are stored as strings. I bet it shouldn't happen. Why would
add_post_meta strip slashes or anything if XML explicitly says:
{{{
<wp:meta_value><![CDATA[{"0":{"type":"text","text":""},"1":{"type":"html","html":"<div
class=\"cssclass\" style=\"margin-top: 3em;\"><p>here goes
html</p></div>","css_class":""}}]]></wp:meta_value>
}}}
which in XML language is considered "use as is. Do not modify". I think
that it might be a bug.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23905>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list