[wp-trac] [WordPress Trac] #34845: Serialized custom fields are ignored on import

WordPress Trac noreply at wordpress.org
Fri Jan 15 15:15:44 UTC 2016


#34845: Serialized custom fields are ignored on import
--------------------------+----------------------------
 Reporter:  muffingroup   |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  WordPress.org
Component:  Import        |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+----------------------------

Comment (by kkarpieszuk):

 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.

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


More information about the wp-trac mailing list