GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
Namespaces | Functions
import-functions.php File Reference

Go to the source code of this file.

Namespaces

 GravityView
 GPL2+
 

Functions

 gravityview_import_helper_fix_line_breaks ( $postmeta=array(), $post_id=0, $post=array())
 Fixes broken serialization character counts when new line characters are in the exported XML. More...
 
 gravityview_import_helper_restore_line_breaks ( $post_id, $key, $value)
 Restores the single new line for imported Views that have been modified. More...
 

Function Documentation

◆ gravityview_import_helper_fix_line_breaks()

gravityview_import_helper_fix_line_breaks (   $postmeta = array(),
  $post_id = 0,
  $post = array() 
)

Fixes broken serialization character counts when new line characters are in the exported XML.

The XML export file includes the line breaks, which are one character when interpreted by PHP ("\n"). For some reason, which I (Zack) cannot understand, the serialized data for the post meta counts both characters when generating the string length calculations.

For example, the following should be exported with a string length of two: an exclamation mark and a new line ("\n") character. But it's stored in the serialized data as length of three:

s:3:"! ";

So this function replaces new line characters ("\n") in the XML and replaces them with two line break characters in order to match the expected number of characters. I chose this route instead of using placeholders like [newline] in case the second part (updating the meta after import) doesn't work. Multiple new lines is a better outcome than modified text.

Replacing one new line with two makes the maybe_unserialize() function happy. I'm happy because we fixed the bug.

Am I thrilled with this solution? No, no I am not.

Does it work? Yes. Yes, it does.

Since
2.12.1
Parameters
array$postmetaCopy of $post['postmeta'] to be filtered.
int$post_id
array$post
Returns
array Modified array, if GravityView

Definition at line 49 of file import-functions.php.

References $post.

◆ gravityview_import_helper_restore_line_breaks()

gravityview_import_helper_restore_line_breaks (   $post_id,
  $key,
  $value 
)

Restores the single new line for imported Views that have been modified.

Since
2.12.1
See also
gravityview_import_helper_fix_line_breaks()
Parameters
int$post_id
string$key
mixed$value

Definition at line 109 of file import-functions.php.

References $value.