3804 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • 8 Years of Membership
+14 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.

3804 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • 8 Years of Membership
+14 more
KrownThemes
says

bump? :|

191 posts
  • Elite Author
  • Author Level 8
  • Top Monthly Author
  • Weekly Top Seller
+9 more
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.

3804 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • 8 Years of Membership
+14 more
KrownThemes
says

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

3804 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • 8 Years of Membership
+14 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.

191 posts
  • Elite Author
  • Author Level 8
  • Top Monthly Author
  • Weekly Top Seller
+9 more
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 :)
1368 posts
  • Copyright Ninja
  • Trendsetter
  • Weekly Top Seller
  • 6 Years of Membership
+7 more
Smartik
says

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

3804 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • 8 Years of Membership
+14 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