WordPress.org

Make WordPress Core

Opened 23 months ago

Last modified 22 months ago

#34845 new defect (bug)

Serialized custom fields are ignored on import

Reported by: muffingroup Owned by:
Milestone: WordPress.org Priority: normal
Severity: normal Version:
Component: Import Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Hi guys,

we would like to report a bug related with .xml file import. Data from our builder are stored in $items table. Post meta values entry are made with below code:

$new = wp_slash( $items ); 
update_post_meta( $post_id, 'mfn-page-items', $new );

And in accordance to your documentation https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping, we use "wp_slash" function. Table with data is saving and reading properly. The problem is when we export .xml file with Tools > Export and when we try to import data with built-in Tools > Import > WordPress option, serialised table is ignored and we get empty field.

We attach test, exported .xml file so you can check it yourself.

We would be grateful if you can have a look on it.

Thanks!

Attachments (2)

betheme3.xml (6.4 KB) - added by muffingroup 23 months ago.
xml file with serialised data being ignored
betheme4.xml (4.3 KB) - added by kkarpieszuk 22 months ago.
correct import file with serialized data

Download all attachments as: .zip

Change History (4)

@muffingroup
23 months ago

xml file with serialised data being ignored

#1 @SergeyBiryukov
23 months ago

  • Component changed from General to Import
  • Description modified (diff)
  • Milestone changed from Awaiting Review to WordPress.org
  • Summary changed from Serialized custom fields are ignored to Serialized custom fields are ignored on import

#2 @kkarpieszuk
22 months ago

Hello @muffingroup . I am Konrad from WPML dev team and I think you remember me when we were working on Muffin and WPML and we found this issue. :)

I was going to provide patch for wordpress for this bug but I found that it is really problem in your file (or problem in PHP interpreter, but this would be really hard to fix ;) ).

I tried to copy and paste content of your serialized custom field into some $a variable and in command line interpreter I run this:

php > $b = unserialize($a);

This gave me this result:

PHP Notice:  unserialize(): Error at offset 674 of 992 bytes in php shell code on line 1

And $b was empty.

unserialize() is core PHP function, not WordPress.

The reason why we see this issue is because one of fields called "content" has this long string with line breaks. In serialized string it is described as field with length 92 while it is actually 92 + 2-new-line-characters long.

I suggest you to, when exporting this data, change those new lines characters into <br> with nl2br() or change them into escaped representation, like this:

$string = preg_replace('~\R~u', "\n", $string);

and then serialize it.

I tried to import your file without new line characters (I will attach it as example) and it worked without any problems. So it is not a problem with serialized data, but data corruption.

@kkarpieszuk
22 months ago

correct import file with serialized data

Note: See TracTickets for help on using tickets.