3445 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

Are there know issues with the XML importer regarding this? I am finding it really really buggy.

Before import (taken from the import.xml file):

[{"width":2,"height":1,"type":"text","i":0,"title":"","bgcolor":"#fff85f","bgimage":"","bgrepeat":"fill","color":"#000000","customtransform":"center","kmbcontent":"<div class="\"big-text\"">\n<h2>Mail</h2>\n</div>\n<div class="\"btn-link\""><a href="\"mailto:hello@lobo.com\"">hello@lobo.com</a></div>"},

After import (taken from the outputted meta value):

[{"width":2,"height":1,"type":"text","i":0,"title":"","bgcolor":"#fff85f","bgimage":"","bgrepeat":"fill","color":"#000000","customtransform":"center","kmbcontent":"<div class="big-text">n<h2>Mail</h2>n</div>n<div class="btn-link"><a href="mailto:hello@lobo.com">hello@lobo.com</a></div>"},

What in the world happens with the escapes when the WordPress importer does its job? It breaks the entire thing.

3445 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

bump? :|

186 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says

hey Ruben, are you serializing the values ? It happens when you serialize it manually. You can try this, when you save the values encode it into base64.

3445 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

Any other way? I would like to not use base64..

3445 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

I am serializing arrays with JSON. And in the import file there’s a perfect JSON array, but when WordPress imports it, it breaks.

186 posts
  • Bought between 100 and 499 items
  • Contributed a Tutorial to a Tuts+ Site
  • Elite Author
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 50 000 and 100 000 dollars
Artillegence says
other option would be to add action for import_end hook , you can check the meta field that if it is not proper json , add the slashes . Something like this
if( ! is_obj( json_decode($array_str) ) )
 $array_str = addslashes($array_str);
or before generating json change double quotes to single in array. Hope this helps :)
1081 posts
  • Forum Superstar
  • Most Wanted Bounty Winner
  • Envato Studio (Microlancer) Beta Tester
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Referred between 50 and 99 users
  • Europe
  • Has been a member for 3-4 years
  • Exclusive Author
+1 more
Smartik says

Export: htmlspecialchars( addslashes($str) );
Import: stripslashes( htmlspecialchars_decode($str) );

3445 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 more
KrownThemes says

Thanks for the help guys. I finally found the root of the error. It’s in the add_post_meta function which is used by the WP importer:

Post meta values are passed through the stripslashes() function upon being stored, so you will need to be careful when passing in values (such as JSON) that might include \ escaped characters.

Every day is a good day for learning :)

I went with the “import_end” filter.

by
by
by
by
by
by