Unserialize PHP Arrays before building the JSON response
-
Hey, thanks for the great plugin you built. I was having some problems with a custom field that was getting saved with a PHP serialize array, I couldn’t read easily the content without the help of other libraries in JavaScript so I thought it will be better to fix the issue in your plugin.
So I added these lines in the models/post.php starting at line 271
$parsed_custom_fields = array(); foreach($wp_custom_fields[$key] as $custom_field){ if(is_serialized($custom_field)){ $parsed_custom_fields[] = unserialize($custom_field); } else { $parsed_custom_fields[] = $custom_field; } } $this->custom_fields->$key = $parsed_custom_fields;
Basically I’m using the WordPress built-in function is_serialized to check if the value of the custom field is a php serialize array.
My problem started when I was using Advanced Custom Fields (ACF) and the Google Maps Custom field, but with this solution I was able to make it work. I hope you can merge this change in a new version.
Have a good day.
- The topic ‘Unserialize PHP Arrays before building the JSON response’ is closed to new replies.